Final Poetry
An entry in the C++wtf segment
The C++ standards committee is very strongly against producing any kind of
breaking changes when considering new language features – especially keywords.
Over the course of standardization, this has lead to terms like auto
being
repurposed, or awkward keywords like co_await
and co_yield
being introduced
in C++20 to avoid breaking a handful of projects in the world that might
possibly be using await
or yield
in their vocabulary.
A notable byproduct that comes from this is that some things we take for granted
in every day modern C++ may not actually be keywords in the sense that you
would expect. For example, both final
and override
are not actually keywords
at all!
These are context-sensitive specifiers, rather than official keywords. This means that their functionality only applies when found in a very specific place, but otherwise allows for their names to be used in any other context – such as variable names, function names, and even type names!
This allows for the following program to be completely syntactically valid, against all logical reason:
struct final final {
final();
final(final&&) : final{}{}
} final;
This creates a final
type named final
and also creates an object of said
type which is also named final
. This is C++’s equivalent of the
buffalo buffalo sentence
or the shi shi shi poem
,
and I think that’s beautiful. Of course, save this in the back of your mind as
an esoteric fact about C++ – and don’t spring this in any professional code, or
you might have some very upset maintainers!