I have a small program with such simple code:
namespace override
{
using final = void();
}
namespace final
{
using override = void(int);
struct final
{
virtual override override;
virtual ::override::final override;
};
}
int main()
{
struct final final : ::final::final
{
::final::override override override final;
::override::final override final override;
};
// doesn't compile
struct override : final
{
};
}
Unfortunately it doesn't compile. I tried to compile it with following pieces of code:
// 1
struct override final
{
};
// 2
override : final
{
};
And both of these variants compile fine. Is it an error in my compiler (clang 3.4)? I can't also understand why my original code doesn't compile.
See live example.
Update: It was an April Fool's day joke, of course. Thanks to all who participated in the discussion. I also thank @ecatmur for his exact but too serious answer.
I wanted to get the code that would have looked strange and at the same time would have compiled with one compiler at least (because it would have given respectability to my question). So my goal was not to create a standard-compliant code. But as @Johannes Schaub - litb noted in comments this code has at least one problem which make it ill-formed. The line virtual override override;
is a violation the following rule (see paragraph [basic.scope.class] 3.3.7/1 of the standard):
A name
N
used in a classS
shall refer to the same declaration in its context and when re-evaluated in the completed scope ofS
. No diagnostic is required for a violation of this rule.
As I can see it can be rewritten as virtual ::final::override override;
to become a standard-compliant.
Why would you expect it to compile? final
is final, so you can't inherit from it.
In your other code:
struct override final
{
};
This is defining a final class with no base classes, so that's fine.
override : final
{
};
This is declaring a label override
, and at that label creating a prvalue temporary of type final
initialized with the brace-initializer {}
, which is immediately destroyed:
override:
final{};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With