This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/30811] __FUNCTION__ allowed in function declaration


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

Eric Gallager <egallager at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|2016-02-02 00:00:00         |2017-08-28
                 CC|                            |egallager at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #8 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Martin Sebor from comment #7)
> 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"

Confirmed, I get the same output.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]