This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/13452] No error on invalid (I think) C++ code


------- 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]