This code triggers an internal compiler error. ------------------------------------------------ enum class Pig { OINK }; struct Hog { using enum Pig; Hog(Pig) { } }; template <unsigned> void pen() { (void)Hog(Hog::OINK); } void pen() { pen<0>(); } ------------------------------------------------ .../gcc/11.1.0/bin/g++ -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -pedantic-errors -Wall -Wno-unknown-pragmas -W -fsigned-char -malign-data=abi -fno-semantic-interposition -gz=zlib-gnu -c -march=westmere -mmmx -mno-3dnow -msse -msse2 -msse3 -mssse3 -mno-sse4a -mcx16 -msahf -mno-movbe -mno-aes -mno-sha -mno-pclmul -mpopcnt -mno-abm -mno-lwp -mno-fma -mno-fma4 -mno-xop -mno-bmi -mno-sgx -mno-bmi2 -mno-tbm -mno-avx -mno-avx2 -msse4.2 -msse4.1 -mno-lzcnt -mno-rtm -mno-hle -mno-rdrnd -mno-f16c -mno-fsgsbase -mno-rdseed -mno-prfchw -mno-adx -mfxsr -mno-xsave -mno-xsaveopt -mno-avx512f -mno-avx512er -mno-avx512cd -mno-avx512pf -mno-prefetchwt1 -mno-clflushopt -mno-xsavec -mno-xsaves -mno-avx512dq -mno-avx512bw -mno-avx512vl -mno-avx512ifma -mno-avx512vbmi -mno-avx5124fmaps -mno-avx5124vnniw -mno-clwb -mno-mwaitx -mno-clzero -mno-pku -mno-rdpid --param "l1-cache-size=32" --param "l1-cache-line-size=64" --param "l2-cache-size=12288" -mtune=westmere -std=gnu++20 -Wrestrict -Wdangling-else -Wno-placement-new -Wno-deprecated-declarations -fno-strict-overflow -Wzero-as-null-pointer-constant -Wwrite-strings -Wno-ignored-qualifiers -Wno-array-bounds -Wno-mismatched-new-delete -Wdeprecated-copy -Wdeprecated-copy-dtor -Wredundant-move -m32 -mfpmath=sse -Woverloaded-virtual -fPIC -g -o /home/welinder/using-enum_L111a3.o /home/welinder/using-enum.C /home/welinder/using-enum.C: In instantiation of ‘void pen() [with unsigned int <anonymous> = 0]’: /home/welinder/using-enum.C:14:9: required from here /home/welinder/using-enum.C:10:18: internal compiler error: in tsubst_copy, at cp/pt.c:16715 10 | (void)Hog(Hog::OINK); | ~~~~~^~~~ 0x669a60 tsubst_copy ../../../gcc-11.1.0/gcc/cp/pt.c:16715 0x802d0c tsubst_qualified_id ../../../gcc-11.1.0/gcc/cp/pt.c:16449 0x8041b6 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../../gcc-11.1.0/gcc/cp/pt.c:19948 0x814e01 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../../gcc-11.1.0/gcc/cp/pt.c:19587 0x814e01 tsubst_tree_list(tree_node*, tree_node*, int, tree_node*) ../../../gcc-11.1.0/gcc/cp/pt.c:15417 0x8037fa tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../../gcc-11.1.0/gcc/cp/pt.c:20586 0x804f67 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../../gcc-11.1.0/gcc/cp/pt.c:19587 0x804f67 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../../gcc-11.1.0/gcc/cp/pt.c:19797 0x814e01 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../../gcc-11.1.0/gcc/cp/pt.c:19587 0x814e01 tsubst_tree_list(tree_node*, tree_node*, int, tree_node*) ../../../gcc-11.1.0/gcc/cp/pt.c:15417 0x8037fa tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../../gcc-11.1.0/gcc/cp/pt.c:20586 0x804f67 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../../gcc-11.1.0/gcc/cp/pt.c:19587 0x804f67 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../../gcc-11.1.0/gcc/cp/pt.c:19797 0x815114 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../../gcc-11.1.0/gcc/cp/pt.c:19587 0x815114 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../../gcc-11.1.0/gcc/cp/pt.c:19198 0x816181 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../../gcc-11.1.0/gcc/cp/pt.c:18223 0x816181 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../../gcc-11.1.0/gcc/cp/pt.c:18268 0x815c4f tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../../gcc-11.1.0/gcc/cp/pt.c:18223 0x815c4f tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../../gcc-11.1.0/gcc/cp/pt.c:18589 0x809719 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../../gcc-11.1.0/gcc/cp/pt.c:25909 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. Return code for compiling using-enum.C: 1 This is an x86_64 system running OpenSuSE 15.2.
Confirmed.
Started with r11-5003.
Confirmed on the GCC 11 branch head and trunk. clang complains: > clang++-11 -S t.C -std=c++20 t.C:4:9: error: expected unqualified-id using enum Pig; ^ t.C:10:18: error: no member named 'OINK' in 'Hog' (void)Hog(Hog::OINK); ~~~~~^ 2 errors generated.
That version of clang does not do "using enum" at all. clang 13 accepts this code, but it has other issues with "using enum".
*** Bug 105787 has been marked as a duplicate of this bug. ***
*** Bug 104398 has been marked as a duplicate of this bug. ***
Created attachment 53800 [details] testcase originally for bug 107460 Now that bug 107460 (ICE with "using enum" member passed to template function, g++ 11.x-13) is marked a dup of this (indirectly, via bug 105787), attaching the testcase here; hopefully that's helpful.
*** Bug 107460 has been marked as a duplicate of this bug. ***
With the testcase I just attached, using 13.0.0 20221030 via Godbolt: https://godbolt.org/z/8Y4cr6MxY <source>: In instantiation of 'Event::Event(EventCat, auto:1) [with auto:1 = int]': <source>:38:32: required from here <source>:30:30: internal compiler error: tree check: expected enumeral_type, have record_type in tsubst_copy, at cp/pt.cc:17024 30 | boundsCheck<EventCat>(a_category, kEventCat_Min); // using "EventCat::kEventCat_Min" instead of just "kEventCat_Min" makes this not fail | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>: https://gcc.gnu.org/g:b3912122c9dfaba6c8229e8f095885f69782ceda commit r13-4477-gb3912122c9dfaba6c8229e8f095885f69782ceda Author: Patrick Palka <ppalka@redhat.com> Date: Sat Dec 3 10:28:25 2022 -0500 c++: substituting CONST_DECL_USING_P enumerators [PR103081] We implement class-scope using enum by injecting clones of the enum's CONST_DECLs as fields of the class, for which CONST_DECL_USING_P is true, so that qualified lookup naturally finds the enumerators. Substitution into such a CONST_DECL currently ICEs however, because we assume the DECL_CONTEXT is always the ENUMERAL_TYPE (which has TYPE_VALUES) but in this case it's the RECORD_TYPE for the class scope (which has TYPE_FIELDS). Since these CONST_DECLs appear to always be non-dependent, this patch fixes this by shortcutting substitution for CONST_DECLs that have non-dependent DECL_CONTEXT. This subsumes the existing (and seemingly dead) DECL_NAMESPACE_SCOPE_P early exit test and also benefits substitution into ordinary non-dependent CONST_DECLs. PR c++/103081 gcc/cp/ChangeLog: * pt.cc (tsubst_copy) <case CONST_DECL>: Generalize early exit test for namespace-scope decls to check dependence of the enclosing scope instead. Remove dead early exit test. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/using-enum-10.C: New test. * g++.dg/cpp2a/using-enum-10a.C: New test.
Fixed on trunk so far.
The releases/gcc-12 branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>: https://gcc.gnu.org/g:648db321893acabd06c24da149c09fceab4daeff commit r12-8995-g648db321893acabd06c24da149c09fceab4daeff Author: Patrick Palka <ppalka@redhat.com> Date: Sat Dec 3 10:28:25 2022 -0500 c++: substituting CONST_DECL_USING_P enumerators [PR103081] We implement class-scope using enum by injecting clones of the enum's CONST_DECLs as fields of the class, for which CONST_DECL_USING_P is true, so that qualified lookup naturally finds the enumerators. Substitution into such a CONST_DECL currently ICEs however, because we assume the DECL_CONTEXT is always the ENUMERAL_TYPE (which has TYPE_VALUES) but in this case it's the RECORD_TYPE for the class scope (which has TYPE_FIELDS). Since these CONST_DECLs appear to always be non-dependent, this patch fixes this by shortcutting substitution for CONST_DECLs that have non-dependent DECL_CONTEXT. This subsumes the existing (and seemingly dead) DECL_NAMESPACE_SCOPE_P early exit test and also benefits substitution into ordinary non-dependent CONST_DECLs. PR c++/103081 gcc/cp/ChangeLog: * pt.cc (tsubst_copy) <case CONST_DECL>: Generalize early exit test for namespace-scope decls to check dependence of the enclosing scope instead. Remove dead early exit test. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/using-enum-10.C: New test. * g++.dg/cpp2a/using-enum-10a.C: New test. (cherry picked from commit b3912122c9dfaba6c8229e8f095885f69782ceda)
Fixed for GCC 12.3/13, thanks for the bug report.