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

            Bug ID: 91230
           Summary: Template function containing lambda expression that
                    has auto parameter and uses __PRETTY_FUNCTION__ does
                    not compile
           Product: gcc
           Version: 9.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: btzy1996 at gmail dot com
  Target Milestone: ---

Created attachment 46619
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46619&action=edit
Preprocessed file

The following valid C++14 code does not compile in GCC 9.1 and later:

struct StringWrapper {
    const char* Value;
};

template <typename T>
void f() {
    [](auto) {
        StringWrapper{__PRETTY_FUNCTION__};
    };
}

int main() {
    f<int>();
}

The error produced by GCC 9.1.0 is:

test.cpp: In instantiation of ‘void f() [with T = int]’:
test.cpp:13:12:   required from here
test.cpp:8:9: error: invalid use of non-lvalue array
    8 |         StringWrapper{__PRETTY_FUNCTION__};
      |         ^~~~~~~~~~~~~

It is broken since GCC 9.1, and it is still broken in GCC 10.0 (experimental). 
GCC 8.3 and lower compiles it without errors.

Notably, if __PRETTY_FUNCTION__ is changed to __FUNCTION__ or __func__, it
compiles successfully.

GCC docs (https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Function-Names.html)
state that __PRETTY_FUNCTION__ (in function scope) should act as if it is
declared as `static const char[]` as the first line of the function definition,
and that __PRETTY_FUNCTION__, __FUNCTION__, and __func__ have the same type.

C++ standards mode (`-std=c++14` or `-std=c++17`) does not matter.

GCC version:

Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/usr --disable-multilib --with-isl
--enable-rpath --enable-__cxa_atexit --enable-nls --disable-checking
--disable-libunwind-exceptions --enable-bootstrap --enable-shared
--enable-static --enable-threads=posix --with-gcc --with-gnu-as
--with-system-zlib --enable-languages=c,c++,fortran,go,objc,obj-c++
--enable-lto
Thread model: posix
gcc version 9.1.0 (GCC)

Link:
https://godbolt.org/z/cuAr4o

Reply via email to