https://gcc.gnu.org/bugzilla/show_bug.cgi?id=30811

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2016-2-2

--- Comment #7 from Martin Sebor <msebor at gcc dot gnu.org> ---
I believe besides an enhancement request there's a bug here: The 
__builtin_FUNCTION() intrinsic is documented as "the equivalent to the
preprocessor __FUNCTION__ macro and returns the function name the invocation of 
the built-in is in."  However, as the following test case shows, the intrinsic
evaluates to a pointer to a different string than __FUNCTION__, and so it's not
equivalent.  Perhaps it's just a matter of correcting the documentation.

This is with the latest trunk of 6.0:

$ cat t.c && /build/gcc-trunk/gcc/xgcc -B /build/gcc-trunk/gcc -O2 -Wall
-Wextra -xc++ t.c && ./a.out
#define F(f, ff) \
    void f (const char *s = ff) { \
        __builtin_printf (#ff " = \"%s\"\n", s); \
    }

F (f0, __func__);
F (f1, __FUNCTION__);
F (f2, __PRETTY_FUNCTION__);
F (f3, __builtin_FUNCTION());

int main () {
    f0 ();
    f1 ();
    f2 ();
    f3 ();
}
t.c:6:8: warning: ‘__func__’ is not defined outside of function scope
 F (f0, __func__);
        ^

t.c:2:29: note: in definition of macro ‘F’
     void f (const char *s = ff) { \
                             ^~

__func__ = ""
__FUNCTION__ = ""
__PRETTY_FUNCTION__ = "top level"
__builtin_FUNCTION() = "main"

Reply via email to