[cfe-users] Converting a function name to boolean

David Blaikie dblaikie at gmail.com
Fri May 3 16:22:40 PDT 2013


On Fri, May 3, 2013 at 7:29 AM, Shriramana Sharma <samjnaa at gmail.com> wrote:
> On Thu, May 2, 2013 at 11:37 PM, Dmitri Gribenko <gribozavr at gmail.com> 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’"

Yep, this is already filed here: http://llvm.org/bugs/show_bug.cgi?id=13235




More information about the cfe-users mailing list