knatten / cppquiz

Source for the http://cppquiz.org website (not the questions)
GNU General Public License v3.0
98 stars 14 forks source link

Question #231 has compilation errors #354

Closed WebDancer69 closed 2 weeks ago

WebDancer69 commented 2 weeks ago

Question #231 has compilation errors, but does not accept that as the answer.

:10:25: error: two or more data types in declaration of 'type name' 10 | virtual auto f() -> override override{ | ^~~~ : In function 'int main()': :17:13: error: invalid cast to abstract class type 'Derived' 17 | Derived().f(); | ^ :9:8: note: because the following virtual functions are pure within 'Derived': 9 | struct Derived : Base { | ^~~ :6:22: note: 'virtual override Base::f()' 6 | virtual override f() = 0; | ^ ASM generation compiler returned: 1 :10:25: error: two or more data types in declaration of 'type name' 10 | virtual auto f() -> override override{ | ^~~~ : In function 'int main()': :17:13: error: invalid cast to abstract class type 'Derived' 17 | Derived().f(); | ^ :9:8: note: because the following virtual functions are pure within 'Derived': 9 | struct Derived : Base { | ^~~ :6:22: note: 'virtual override Base::f()' 6 | virtual override f() = 0; | ^ Execution build compiler returned: 1

WebDancer69 commented 2 weeks ago

I used x86-64 gcc (trunk) (currently 15.0.0 20240828 experimental) with Compiler Explorer.

tocic commented 2 weeks ago

Please see #148 and #311.

knatten commented 2 weeks ago

Thanks for reporting! By "has compilation errors", do you mean it fails to compile on a particular compiler (gcc) or that the standard says it should not compile?

If you click the compiler explorer link in the question, you can see that this compiles fine with clang and msvc. The explanation to the question also explains why this is, in fact, legal C++. I believe this is a bug in gcc, unless you take issue with anything in particular in the explanation to the question. Please re-open if you disagree.

WebDancer69 commented 2 weeks ago

I agree, it seems it (still) is a gcc bug.

This seems to work in gcc:

virtual override f() override {
    std::cout << "1";
    return override();
}