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!

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

# include <iostream>
int main () 
{ 
	if ( f    ) std::cout << "Global functions can be converted to boolean.\n" ; 
	if ( a.f  ) std::cout << "Member functions can be converted to boolean.\n" ; 
	if ( a.vf ) std::cout << "Virtual member functions can be converted to boolean.\n" ;
	if ( a.sf ) std::cout << "Static member functions can be converted to boolean.\n" ; 
}

/*
$ clang++ -c function-boolean-conversion.cpp
function-boolean-conversion.cpp:11:7: warning: address of function 'f' will always evaluate to 'true' [-Wbool-conversion]
        if ( f     ) std::cout << "Global functions can be converted to boolean.\n" ; 
        ~~   ^
function-boolean-conversion.cpp:11:7: note: prefix with the address-of operator to silence this warning
        if ( f     ) std::cout << "Global functions can be converted to boolean.\n" ; 
             ^
             &
function-boolean-conversion.cpp:12:9: error: reference to non-static member function must be called; did you mean to call it with no arguments?
        if ( a.f   ) std::cout << "Member functions can be converted to boolean.\n" ; 
             ~~^
                ()
function-boolean-conversion.cpp:12:7: error: value of type 'void' is not contextually convertible to 'bool'
        if ( a.f   ) std::cout << "Member functions can be converted to boolean.\n" ; 
             ^~~
function-boolean-conversion.cpp:13:9: error: reference to non-static member function must be called; did you mean to call it with no arguments?
        if ( a.vf  ) std::cout << "Virtual member functions can be converted to boolean.\n" ;
             ~~^~
                 ()
function-boolean-conversion.cpp:13:7: error: value of type 'void' is not contextually convertible to 'bool'
        if ( a.vf  ) std::cout << "Virtual member functions can be converted to boolean.\n" ;
             ^~~~
function-boolean-conversion.cpp:14:9: warning: address of function 'A::sf' will always evaluate to 'true' [-Wbool-conversion]
        if ( a.sf  ) std::cout << "Static member functions can be converted to boolean.\n" ; 
        ~~   ~~^~
function-boolean-conversion.cpp:14:9: note: prefix with the address-of operator to silence this warning
        if ( a.sf  ) std::cout << "Static member functions can be converted to boolean.\n" ; 
               ^
               &
2 warnings and 4 errors generated.
*/

/*
$ g++ -c function-boolean-conversion.cpp
function-boolean-conversion.cpp: In function ‘int main()’:
function-boolean-conversion.cpp:12:13: error: cannot convert ‘A::f’ from type ‘void (A::)()’ to type ‘bool’
function-boolean-conversion.cpp:13:13: error: cannot convert ‘A::vf’ from type ‘void (A::)()’ to type ‘bool’
*/
_______________________________________________
cfe-users mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-users

Reply via email to