[Bug c++/77557] New: gcc doesn't warn about code (clang does), __PRETTY_FUNCTION__ used in struct in function

marmoo1024 at gmail dot com gcc-bugzilla@gcc.gnu.org
Sun Sep 11 07:29:00 GMT 2016


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

            Bug ID: 77557
           Summary: gcc doesn't warn about code (clang does),
                    __PRETTY_FUNCTION__ used in struct in function
           Product: gcc
           Version: 6.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marmoo1024 at gmail dot com
  Target Milestone: ---

I don't know about the standard, I'm afraid to embark on a grand quest to read
the whole thing. But the code below is accepted by g++ (4.8.5, 5.3.0 and 6.1.1)
without a warning, even with -Wall, but clang++ emits a sensible seeming
warning. Also, the value differs between clang and gcc. In gcc it's the name of
the function, in clang it's the class constructor.

Is gcc doing the right thing?

gcc compiled prog outputs "void fn()", clang compiled code outputs
"fn()::getter::getter()".

clang emits this warning,
test_1.cpp:6:21: warning: predefined identifier is only valid inside function
[-Wpredefined-identifier-outside-function]
                const char * fn = __PRETTY_FUNCTION__;
                                  ^
1 warning generated.


== code ==
#include <stdio.h>
void fn () {
        struct getter {
                const char * fn = __PRETTY_FUNCTION__;
        };      
        printf ("%s\n",getter().fn);
};      
int main () {
        fn();
}


More information about the Gcc-bugs mailing list