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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
N.B. for clang 3.9 the program prints "top level" not the constructor name.

__PRETTY_FUNCTION__ is a non-standard extension so the standard says nothing
about how it works. The similar function-local predefined variable __func__ is
standard, and is usable in ctor-init-lists, e.g. this should get the name of
the constructor:

struct getter {
  getter() : s(__func__) { }
  const char* s;
};

However, the predefined variable is only in scope in the function body, and a
default member initializer is not part of the constructor's function body, so I
think G++ is right to find the variable from the enclosing scope (as in
Andrew's example).

And so I think Clang is wrong to warn. Likewise, EDG is wrong to give an error:

"dmi2.cc", line 4: error: the reserved identifier "__PRETTY_FUNCTION__" may
          only be used inside a function
                  const char * fn = __PRETTY_FUNCTION__;
                                    ^

I don't see anything in the standard saying the predefined variable __func__ is
not usable in nested classes defined in the block scope where the variable is
defined.

Reply via email to