https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119378
Bug ID: 119378 Summary: Nested template class friend of template class produces "internal compiler error: unexpected expression ‘T’ of kind template_parm_index" Product: gcc Version: 12.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: sebastian at radakovits dot se Target Milestone: --- Created attachment 60825 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=60825&action=edit The program generating the error GCC version: (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0 Target: x86_64-linux-gnu GCC Configured with: ../src/configure -v --with-pkgversion='Ubuntu 12.3.0-1ubuntu1~22.04' --with- bugurl=file:///usr/share/doc/gcc-12/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-12 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-12-ALHxjy/gcc-12-12.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-12-ALHxjy/gcc-12-12.3.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Command line: gcc-12 main.cpp Output: main.cpp: In instantiation of ‘class C<int>’: main.cpp:16:12: required from here main.cpp:8:9: internal compiler error: unexpected expression ‘T’ of kind template_parm_index 8 | class C { | ^ 0x7f0291921d8f __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 0x7f0291921e3f __libc_start_main_impl ../csu/libc-start.c:392 Please submit a full bug report, with preprocessed source (by using -freport-bug). Please include the complete backtrace with any bug report. See <file:///usr/share/doc/gcc-12/README.Bugs> for instructions. ---------- When testing in Compiler Explorer (https://godbolt.org/z/aWE1aqnee) it seems that the bug is only present in versions of gcc >= 4.8.1 and main.cpp compiles fine with gcc version 4.7.4 and earlier. Compiling the program with clang only produces a warning: main.cpp:11:24: warning: dependent nested name specifier 'A<T>::' for friend template declaration is not supported; ignoring this friend declaration [-Wunsupported-friend] friend class A<T>::B; ~~~~~~^ ---------- template <int T> struct A { template <typename Q> class B {}; }; template <class R> class C { template <int T> template <class Q> friend class A<T>::B; }; int main() { C<void> ctg; }