https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118128
Bug ID: 118128 Summary: Internal Compiler Error with using enum and Templated Class Product: gcc Version: 11.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: kilian.tr...@rohde-schwarz.com Target Milestone: --- Host: Ubuntu 22.04.5 Created attachment 59918 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59918&action=edit preprocessed source code When compiling the following C++ code that utilizes using enum within a templated class, GCC produces an internal compiler error. The issue appears to be related to the combination of using enum and the templated class. Code Example: class b { public: enum class a { c }; using enum a; b(a) {} }; template<typename> class d { b a = b::c; }; int main() { d<int> d; } Steps to reproduce: 1. Save the above code in a file named error.cpp. 2. Compile the code using the command: g++ error.cpp -std=c++20 Additional Information: * The code compiles successfully when directly accessing the enum value (e.g., b::a::c) or when the template of class d is removed. * This issue has been tested on GCC versions 11.4.0 and 11.5.0, and it appears to be present in all versions prior to 12.3. Output of g++ -v -save-temps error.cpp -std=c++20 (.ii file is attached): Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/11.5.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ./configure --disable-multilib Thread model: posix Supported LTO compression algorithms: zlib gcc version 11.5.0 (GCC) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++20' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-dumpdir' 'a-' /usr/local/libexec/gcc/x86_64-pc-linux-gnu/11.5.0/cc1plus -E -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE error.cpp -mtune=generic -march=x86-64 -std=c++20 -fpch-preprocess -o a-error.ii ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" ignoring nonexistent directory "/usr/local/lib/gcc/x86_64-pc-linux-gnu/11.5.0/../../../../x86_64-pc-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /usr/local/lib/gcc/x86_64-pc-linux-gnu/11.5.0/../../../../include/c++/11.5.0 /usr/local/lib/gcc/x86_64-pc-linux-gnu/11.5.0/../../../../include/c++/11.5.0/x86_64-pc-linux-gnu /usr/local/lib/gcc/x86_64-pc-linux-gnu/11.5.0/../../../../include/c++/11.5.0/backward /usr/local/lib/gcc/x86_64-pc-linux-gnu/11.5.0/include /usr/local/include /usr/local/lib/gcc/x86_64-pc-linux-gnu/11.5.0/include-fixed /usr/include/x86_64-linux-gnu /usr/include End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++20' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-dumpdir' 'a-' /usr/local/libexec/gcc/x86_64-pc-linux-gnu/11.5.0/cc1plus -fpreprocessed a-error.ii -quiet -dumpdir a- -dumpbase error.cpp -dumpbase-ext .cpp -mtune=generic -march=x86-64 -std=c++20 -version -o a-error.s GNU C++20 (GCC) version 11.5.0 (x86_64-pc-linux-gnu) compiled by GNU C version 11.5.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version none GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C++20 (GCC) version 11.5.0 (x86_64-pc-linux-gnu) compiled by GNU C version 11.5.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version none GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 9142fb5436a559c637d51027d8c27ce4 error.cpp: In instantiation of ‘constexpr d<int>::d()’: error.cpp:14:10: required from here error.cpp:10:14: internal compiler error: in tsubst_copy, at cp/pt.c:16892 10 | b a = b::c; | ~~~^ 0x6269ff tsubst_copy ../.././gcc/cp/pt.c:16892 0x7c112a tsubst_qualified_id ../.././gcc/cp/pt.c:16618 0x7c2e26 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../.././gcc/cp/pt.c:20133 0x70ca41 get_nsdmi(tree_node*, bool, int) ../.././gcc/cp/init.c:614 0x726d18 walk_field_subobs ../.././gcc/cp/method.c:2279 0x72746b synthesized_method_walk ../.././gcc/cp/method.c:2637 0x7279dd get_defaulted_eh_spec(tree_node*, int) ../.././gcc/cp/method.c:2679 0x7c4fd0 maybe_instantiate_noexcept(tree_node*, int) ../.././gcc/cp/pt.c:25869 0x7c4ef9 maybe_instantiate_noexcept(tree_node*, int) ../.././gcc/cp/pt.c:25859 0x6f3da2 mark_used(tree_node*, int) ../.././gcc/cp/decl2.c:5621 0x67adde build_over_call ../.././gcc/cp/call.c:9531 0x679587 build_new_method_call_1 ../.././gcc/cp/call.c:10821 0x67cbf7 build_new_method_call(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>**, tree_node*, int, tree_node**, int) ../.././gcc/cp/call.c:10897 0x67cbf7 build_special_member_call(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>**, tree_node*, int, int) ../.././gcc/cp/call.c:10297 0x707793 expand_default_init ../.././gcc/cp/init.c:1995 0x707793 expand_aggr_init_1 ../.././gcc/cp/init.c:2110 0x7096b5 build_aggr_init(tree_node*, tree_node*, int, int) ../.././gcc/cp/init.c:1844 0x6d52bd build_aggr_init_full_exprs ../.././gcc/cp/decl.c:6990 0x6d52bd check_initializer ../.././gcc/cp/decl.c:7155 0x6e9478 cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int) ../.././gcc/cp/decl.c:8164 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <https://gcc.gnu.org/bugs/> for instructions.