This code is compiled without error in the current mainline: class C { public: template<typename i> int (*f())() const; }; However, it now seems to me that there should be an error on the trailing const. Otherwise, I have no idea what the trailing const means. It appears that generating a const method (i.e., a method for which `this' is a pointer to const) requires class C { public: template<typename i> int (*f() const)(); }; This may be a misunderstanding on my part, but at least some people share my misunderstanding; see PR c++/13447.
Confirmed but not a regression.
(In reply to comment #0) > However, it now seems to me that there should be an error on the trailing const. No. > Otherwise, I have no idea what the trailing const means. It appears that > generating a const method (i.e., a method for which `this' is a pointer to > const) requires > class C { public: template<typename i> int (*f() const)(); }; > This may be a misunderstanding on my part, but at least some people share my > misunderstanding; see PR c++/13447. You declared a non const member function f() which returns a pointer to a const member function. If the const is inside the parenteses, you declare a const member function f() which returns a pointer to a non const member function. Now, consider to place const at both... Cheers, Rainer
Subject: Re: No error on invalid (I think) C++ code "Rainer dot Bensch at rsd dot rohde-schwarz dot com" <gcc-bugzilla@gcc.gnu.org> writes: > You declared a non const member function f() which returns a pointer to a const > member function. If the const is inside the parenteses, you declare a const > member function f() which returns a pointer to a non const member function. > Now, consider to place const at both... I don't agree. The function f() does not return a pointer to any sort of member function. It returns a simple pointer to function. Consider this test case: extern int bar(); class C { public: int (*f())() const; }; int (*C::f())() const { return bar; } Right now this compiles without error. But the `const' in the declaration of C::f() is meaningless. C::f() returns an ordinary function. I certainly can't declare `extern int bar() const'. Conversely, this test case: class C { public: int (*f())() const; int bar(); }; int (*C::f())() const { return C::bar; } fails, with: foo3.cc:2: error: argument of type `int (C::)()' does not match `int (*)() Similarly, this one: class C { public: int (*f())() const; int bar() const; }; int (*C::f())() const { return C::bar; } fails with: foo3.cc:2: error: argument of type `int (C::)() const' does not match `int (*)()' (both these error messages are mildly bogus, since the case here is not an argument mismatch, but a return mismatch, but that is a separate issue). So I still think that the trailing const is meaningless, and should cause an error. Ian
Just a note that this still fails to issue an error on mainline.
*** Bug 37885 has been marked as a duplicate of this bug. ***
*** Bug 26143 has been marked as a duplicate of this bug. ***
The invalid test case from comment #0 is still accepted by the top of trunk (GCC 7.0). Both Clang and Oracle Solaris Studio reject the program with a similar error: "t.C", line 1: Error: Non-member function pointer cannot point to a const function.
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1417
*** Bug 86652 has been marked as a duplicate of this bug. ***
Still no error. I've updated https://gcc.gnu.org/projects/cxx-dr-status.html