This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/13452] No error on invalid (I think) C++ code
- From: "ian at airs dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 12 Jan 2004 16:27:34 -0000
- Subject: [Bug c++/13452] No error on invalid (I think) C++ code
- References: <20031219185750.13452.ian@airs.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From ian at airs dot com 2004-01-12 16:27 -------
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
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13452