https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112715
Bug ID: 112715 Summary: Incorrect handling of template type aliases instantiated from decltype of lambdas Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: gcc at nospam dot scs.stanford.edu Target Milestone: --- Created attachment 56689 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56689&action=edit File that should compile but doesn't I'm using g++ version 13.2.1 on arch linux, configured as follows: ~~~~ $ g++ -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /build/gcc/src/gcc/configure --enable-languages=ada,c,c++,d,fortran,go,lto,objc,obj-c++ --enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --with-build-config=bootstrap-lto --with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit --enable-cet=auto --enable-checking=release --enable-clocale=gnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-libstdcxx-backtrace --enable-link-serialization=1 --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch --disable-werror Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 13.2.1 20230801 (GCC) ~~~~ When defining template type aliases, I get bizarrely incorrect types in some contexts but not others. For example, the static assertion fails in this code but should not: ~~~~ #include <type_traits> template<unsigned int Nbits> using uintsz = decltype([](auto i){ if constexpr (i <= 32) return 0; else return 0L; }(std::integral_constant<unsigned int, Nbits>{})); template<unsigned int Nbytes> constexpr uintsz<8*Nbytes> f() { return 0; } static_assert(std::is_same_v<decltype(f<7>()), uintsz<56>>); ~~~~ Specifically I get the following error: ~~~~ $ g++ -std=c++20 -ggdb -O -Wall -c -o uintsz.o uintsz.cc uintsz.cc:18:20: error: static assertion failed 18 | static_assert(std::is_same_v<decltype(f<7>()), uintsz<56>>); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~ This feels like some sort of state corruption in the compiler, because there are more complicated examples in which gcc rejects other things inside functions (like rejecting a using type alias and accepting the corresponding typedef). I think this example suffices to show the problem, but I could try to reduce another test case if necessary. In all cases, clang++ -std=c++20 accepts the code.