[cfe-users] Converting a function name to boolean
Shriramana Sharma
samjnaa at gmail.com
Fri May 3 07:29:09 PDT 2013
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’"
--
Shriramana Sharma ஶ்ரீரமணஶர்மா श्रीरमणशर्मा
-------------- next part --------------
A non-text attachment was scrubbed...
Name: function-boolean-conversion-explicit.cpp
Type: text/x-c++src
Size: 1055 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20130503/4988bc8a/attachment.cpp>
More information about the cfe-users
mailing list