On Thu, May 2, 2013 at 11:37 PM, Dmitri Gribenko <[email protected]> wrote:
> Looks like our attempt to recover from an error leads to a bad
> diagnostic.  You can file a bug for a bad diagnostic at
> http://llvm.org/bugs/

Hmmm, examining it further I'm not sure functionality-wise it is a bug --

I think the situation is that it is not possible to extract a bool
value via the address of the function, so instead of suspecting that
the user might have wanted to convert the function pointer into a
bool, Clang is suspecting that the user wanted to call the function
and convert its return value to a bool, which is OK IMO.

However, in investigating the reason it is not possible to get a bool
value via the function pointer, I found that it is because one can't
take a pointer to a bound member function apparently, and I ran into
an actually unclear diagnostic by Clang:

struct A {
                void  f () {}
        virtual void vf () {}
         static void sf () {}
} a ;

int main ()
{
        if ( & a.f   ) {}
        if ( & A::f  ) {}
        if ( & a.vf  ) {}
        if ( & A::vf ) {}
        if ( & a.sf  ) {}
        if ( & A::sf ) {}
}

Clang reports: for the lines &a.f and &a.vf: "cannot create a
non-constant pointer to member function", which is not all that clear
IMO -- would it then be possible to create a *constant* pointer? How?

In this one case GCC is clearer: "ISO C++ forbids taking the address
of a bound member function to form a pointer to member function.  Say
‘&A::f’"

-- 
Shriramana Sharma ஶ்ரீரமணஶர்மா श्रीरमणशर्मा
struct A { 
	        void  f () {}
	virtual void vf () {} 
	 static void sf () {}
} a ;

int main () 
{ 
	if ( & a.f   ) {} 
	if ( & A::f  ) {} 
	if ( & a.vf  ) {}
	if ( & A::vf ) {} 
	if ( & a.sf  ) {}
	if ( & A::sf ) {} 
}

/*
$ g++ -c function-boolean-conversion.cpp
function-boolean-conversion.cpp: In function ‘int main()’:
function-boolean-conversion.cpp:9:11: error: ISO C++ forbids taking the address of a bound member function to form a pointer to member function.  Say ‘&A::f’ [-fpermissive]
function-boolean-conversion.cpp:11:11: error: ISO C++ forbids taking the address of a bound member function to form a pointer to member function.  Say ‘&A::vf’ [-fpermissive]
*/

/*
$ clang -c function-boolean-conversion.cpp
function-boolean-conversion.cpp:9:7: error: cannot create a non-constant pointer to member function
        if ( & a.f   ) {} 
             ^ ~~~
function-boolean-conversion.cpp:11:7: error: cannot create a non-constant pointer to member function
        if ( & a.vf  ) {}
             ^ ~~~~
2 errors generated.
*/
_______________________________________________
cfe-users mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-users

Reply via email to