This is the mail archive of the gcc@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]

Re: Bug or feature? C++ code that no longer compiles under GCC 4.2


On ons, 2007-08-29 at 16:42 -0400, Daniel Drake wrote:
> Hi,
> 
> Take the following code sample:
> 
> ------------------------------------------------
> #define BREAK_GCC4_2
> 
> template<typename Op>
> void foo(Op& op) { op(); }
> 
> class My {
> public:
>   static void myOp() { }
> 
>   void test() {
> #ifdef BREAK_GCC4_2
>     foo(myOp);
> #else
>     foo(My::myOp);
> #endif
>   }
> };
> ------------------------------------------------
> 
> It compiled fine under GCC 4.1 but fails under 4.2.0:
> $ g++ -c test.cpp
> test.cpp: In member function 'void My::test()':
> test.cpp:12: error: invalid initialization of non-const reference of
> type 'void (&)()' from a temporary of type 'void ()()'
> test.cpp:4: error: in passing argument 1 of 'void foo(Op&) [with Op =
> void ()()]'
> 
> We found an alternative way to make the code compile (comment out the
> first line) which works with both versions, but I'm wondering whether
> this should be reported as a bug or if it was intentional.

I think this is a feature, and your old code were buggy.

ISO 14882:1998 states (§5.3.1p3)

> A pointer to member is only formed when an explicit & is used and its
> operand is a qualified-id not enclosed in parentheses.

and then goes on to say (in a note, so this isn't normative)

> Nor is &unqualified-id a pointer to member, even within the scope of 
> the unqualified-id's class.

/MF



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