Converting a function name to boolean

Hello. This is my first post here. First let me express my very many
thanks and congratulations to all those who have developed Clang so
excellently. I've only recently started using it over GCC, and I have
to say I am most pleased. I am also happy to note that Debian's
Clang-compilability is being actively tested
(http://clang.debian.net/) since I'm using Kubuntu.

OK now to my query:

I'm using Clang 3.2 (3.2-1~exp9ubuntu1) on Kubuntu Raring on a 64 bit system.

Please examine the attached C++ test program which includes the Clang
vs GCC (4.7.3-1ubuntu1) outputs too. Since Clang is far stricter with
the standard than GCC I've been using it to compile my projects and it
recently gave this error "reference to non-static member function must
be called", based on which I made up this testcase.

Normally Clang's error messages are much more useful than GCC, but in
this case, GCC clearly says that it can't convert a function of the
given type into a bool upon seeing that the expression is used in an
if() tests, whereas Clang talks about a reference to non-static member
needing to be called. I don't get what is the meaning or relevance of
the error message. Can anyone please explain? (I also note that if the
function takes no arguments, there is a suggestion appended to the
error message: whether I meant to call it with no arguments.)

Thanks a lot!

function-boolean-conversion.cpp (2.73 KB)

Hi,

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/

Dmitri

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

function-boolean-conversion-explicit.cpp (1.03 KB)

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