https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108550
Bug ID: 108550 Summary: the type 'const auto' of 'constexpr' variable is not literal Product: gcc Version: 11.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: coyorkdow at outlook dot com Target Milestone: --- Created attachment 54344 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54344&action=edit generated by `-save-temps` This bug can be triggered in gcc-11 and gcc-12. (I don't have gcc-13 so I didn't try.) Here are the codes (the preprocessed file is attached) ``` #include <type_traits> #include <memory> template <class Tp> constexpr auto is_pointer_v = std::is_pointer<Tp>::value; template <class Tp, decltype(&Tp::operator*)* = nullptr> auto Wrap1(int) -> std::integral_constant<bool, is_pointer_v<decltype(std::declval<Tp>().operator->())>>; template <class Tp> auto Wrap1(...) -> std::is_pointer<Tp>; int main() { static_assert(!is_pointer_v<std::unique_ptr<int>>); // this line can compile static_assert(decltype(Wrap1<std::unique_ptr<int>>(0))::value); // error return 0; } ``` The err msgs ``` % g++-11 a.cc -save-temps a.cc: In instantiation of 'constexpr const auto is_pointer_v<int*>': a.cc:8:49: required by substitution of 'template<class Tp, decltype (& Tp::operator*)* <anonymous> > std::integral_constant<bool, is_pointer_v<decltype (declval<Tp>().operator->())> > Wrap1(int) [with Tp = std::unique_ptr<int>; decltype (& Tp::operator*)* <anonymous> = <missing>]' a.cc:15:53: required from here a.cc:5:16: error: the type 'const auto' of 'constexpr' variable 'is_pointer_v<int*>' is not literal 5 | constexpr auto is_pointer_v = std::is_pointer<Tp>::value; | ^~~~~~~~~~~~ a.cc:5:16: error: 'const auto is_pointer_v<int*>' has incomplete type a.cc: In function 'int main()': a.cc:15:59: error: static assertion failed 15 | static_assert(decltype(Wrap1<std::unique_ptr<int>>(0))::value); // this line incurs error | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~ ``` GCC version: ``` % gcc-11 -v Using built-in specs. COLLECT_GCC=gcc-11 COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/11.3.0_2/bin/../libexec/gcc/x86_64-apple-darwin21/11/lto-wrapper Target: x86_64-apple-darwin21 Configured with: ../configure --prefix=/usr/local/opt/gcc --libdir=/usr/local/opt/gcc/lib/gcc/11 --disable-nls --enable-checking=release --with-gcc-major-version-only --enable-languages=c,c++,objc,obj-c++,fortran,d --program-suffix=-11 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-zstd=/usr/local/opt/zstd --with-pkgversion='Homebrew GCC 11.3.0_2' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --enable-libphobos --build=x86_64-apple-darwin21 --with-system-zlib --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.3.0 (Homebrew GCC 11.3.0_2) ``` If remove the parameter `decltype(&Tp::operator*)* = nullptr` then codes can be compiled. Other parameter like `class = std::enable_if_t<!std::is_pointer<Tp>::value>` can also trigger. The error also happens in gcc-12. There is another similar but unrelated bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87512