David
2012-10-07 13:38:58 UTC
For example, suppose we have the following base class:
struct Base {
virtual auto f () const -> int = 0;
};
The two possibilities for a derived class are:
struct Derived : public Base {
virtual auto f () const override -> int { return 0; } // Compiles on g++ 4.7.1
};
or
struct Derived : public Base {
virtual auto f () const -> int override { return 0; } // Compiles on clang++ 4.0
};
g++ 4.7.1 compiles the first version but fails on the second with
• test.cpp:6:30: error: expected ';' at end of member declaration
• test.cpp:6:34: error: 'override' does not name a type
whereas clang++ 4.0 compiles the second one but fails on the first with
• test.cpp:6:11: error: 'auto' return without trailing return type
virtual auto f () const override -> int { return 0; }
^
• test.cpp:6:3: error: only virtual member functions can be marked 'override'
virtual auto f () const override -> int { return 0; }
^ ~~~~~~~~
• test.cpp:6:35: error: expected ';' at end of declaration list
virtual auto f () const override -> int { return 0; }
^
Which of these compilers is actually doing the right thing according to the standard?