The following code produces the subsequent compilation error on all versions of GCC that I've tried, in C++98, C++11 and C++14 modes:
struct T
{
T(void* x) : (x) {}
};
// main.cpp: In constructor 'T::T(void*)':
// main.cpp:3:18: error: anachronistic old-style base class initializer [-fpermissive]
// T(void* x) : (x) {}
// ^
// main.cpp:3:16: error: unnamed initializer for 'T', which has no base classes
// T(void* x) : (x) {}
Sure, it's clearly broken code because I'm not actually initialising anything.
But why is it a base-class initialiser and why is it "anachronistic", rather than simply wrong? Was it once valid? When? And what did it mean?
The only related references I've found to this on the web have been people coming across the error when a member name was accidentally macro'd out, effectively resulting in the same code as above:
#define bar
// ^ some library could have done this
struct T
{
T(int x)
: bar(x) // effectively just `: (x)`
{}
int bar; // will cause its own error
};
Those people never did find out what the error meant, although they later at least discovered why their program was broken.
See Question&Answers more detail:os