# P2266’s interaction with decltype(auto)

C++Now 2021 is happening this week. Normally it’s in Aspen, Colorado, but this year it’s completely online. I presented two talks: “When Should You Give Two Things the Same Name?” and “The Complete Guide to return x.”

In my return x talk, slide 77 showed a table illustrating how P2266’s value-category changes affected five subtly different functions. One of the entries was incorrect; and, as I fixed it, I realized that for completeness the table should have included eight subtly different functions!

Here is a revised and I hope fully correct version of that table. …

# Optimizing string::append is harder than it looks

Back in early March, Lukas Böger asked on StackOverflow: “Where do standard library or compilers leverage noexcept move semantics (other than vector growth)?” So I got nerdsniped into looking at all the places libc++ tests the noexceptness of any user-defined operation. This circuitously led to my finding an absolutely massive number of corner-case bugs in libc++’s string::append member function.

# Lineup for next week’s Celebration of Mind

Next week, April 18 through 24, the Gathering 4 Gardner is hosting a week-long Celebration of Mind, featuring three brief presentations per day, every day. The speaker lineup has just been announced; but since the official website requires multiple clicks to get to the schedule, and is a little verbose too, here’s a very short summary lineup.

# Antisocial Homeworlds, and a solitaire challenge

A couple of weeks ago, I came up with a new variant of Binary Homeworlds. Readers of this blog will already know Homeworlds as the “space chess” game played with colorful pyramids, invented by John Cooper, and popularized mainly by Andy Looney. In fact, this variant was directly inspired by a variant invented by Andy Looney in February 2021, which he called “Peaceful Homeworlds,” and which you can read about here.

# static constexpr unsigned long is C++’s “lovely little old French whittling knife”

There’s a meme going around (extracted from Mark Forsyth’s 2013 book The Elements of Eloquence) that postulates an unwritten rule of English:

# Observations on Castlequest’s code

Holtzman and Kershenblatt’s Castlequest was inspired by Crowther and Woods’ Adventure, and has a lot in common with it:

# Playing Castlequest (1980), Part 2

Previously on this blog: “Playing Castlequest (1980), Part 1” (2021-03-19). So far we’ve found eight treasures — silver cross, Cuban cigar, gold statue, champagne, jade figure, sapphire, crystal swan, large ruby — and our main (only?) unsolved puzzle was where to use this rope tied to a grappling hook.

# Playing Castlequest (1980), Part 1

Earlier this week I posted that the source code for Castlequest (Holtzman and Kershenblatt, 1980) had been found — Castlequest exhumed!” (2021-03-09). By now it’s totally playable (at least if you have the ability to install GNU Fortran).

I had been seeking Castlequest because I had fond memories of the game on GEnie. I vaguely remembered the wandering werewolf, and the vampire in the attic that you have to kill with a tomato stake before the sun sets… But it turns out that the game is actually much much longer than I ever knew as a kid! I’m going to try the “All the Adventures” thing here, and describe my experience replaying the game this week.

This post contains major spoilers for all plot points and puzzles!

# Does throw x implicit-move? Let’s ask SFINAE

Language lawyers may want to read the UPDATE at the bottom of this post before the rest. I think everything discussed here is, technically speaking, ill-formed.

# C’s removal of gets could have been done better

The other day, someone filed a bug against uthash (a C library I maintain) claiming that the provided example code segfaults in C11. (Keep in mind that this example code hasn’t been significantly updated since the 1990s.) Fortunately, the segfault ended up not having anything to do with uthash proper. Instead, it boiled down to this:

# Making Castlequest compilable

Earlier this week I posted that the source code for Castlequest (Holtzman and Kershenblatt, 1980) had been found — Castlequest exhumed!” (2021-03-09). But I named several obstacles that still needed to be overcome to make it playable. Well, those obstacles have now been overcome!

# Castlequest exhumed!

“Lost game” Castlequest (1980) has been found!

# Escape analysis hates copy elision

Yesterday Lauri Vasama showed me this awesome Godbolt:

struct S {
static std::unique_ptr<S> make() noexcept;
~S();

static std::unique_ptr<S> factory() {
std::unique_ptr<S> s = S::make();
return M(s);
}
};

void take_ownership(S*) noexcept;

void test() {
std::unique_ptr<S> p = S::factory();
take_ownership(p.release());
}


When M(s) is defined as std::move(s), Clang gives pretty much optimal codegen for test: …

# Don’t blindly prefer emplace_back to push_back

In one of my recent training courses, a student informed me that both clang-tidy and PVS-Studio were complaining about some code of the form

# Adventure 448 (SWEN0448): All the easter eggs

This week Jason Dyer played Adventure 448, in a couple of blog posts:

# A hole in Clang’s -Wsuggest-override

Consider this code:

struct B {
virtual int f() = 0;
virtual int g() = 0;
};

struct C : B {
int f() override;

virtual int g() final;  // overrides
virtual int h() final;  // doesn't
}; ...

Someone recently asked me about devirtualization optimizations: when do they happen? when can we rely on devirtualization? do different compilers do devirtualization differently? As usual, this led me down an experimental rabbit-hole. The answer seems to be: Modern compilers devirtualize calls to final methods pretty reliably. But there are many interesting corner cases — including some I haven’t thought of, I’m sure! — and different compilers do catch different subsets of those corner cases.