https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107460
Bug ID: 107460 Summary: ICE with "using enum" member passed to template function (g++ 11.x-13) Product: gcc Version: 12.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: chris-gcc-bugzilla at cybermato dot com Target Milestone: --- Created attachment 53793 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53793&action=edit file generated by -freport-bug The following code (also attached) causes an ICE in tsubst_copy on every version of g++ that can handle "using enum", with either -std=c++20 or -std=gnu++20, regardless of -O0, -O1, -O2, etc.: trunk (13.0.0 20221028) (Godbolt) 12.2.0 (Godbolt) 12.1.0 (Ubuntu 22.04) 11.3.0 (Godbolt) 11.2.0 (Ubuntu 22.04) 11.1 (Ubuntu 20.04) (10.4 and earlier don't seem to support "using enum") clang 13, 14, and 15 compile it with no complaint, as does MSVC (19.33 per Godbolt, plus VS 2019 and VS 2022). If I pass 'EventCat::kEventCat_Min' to boundsCheck() instead of just 'kEventCat_Min', it compiles without error. --------------------------------------------------------------------------------- void fatal [[noreturn]] (const char * msg); template <typename ToType, typename FromType, typename MinType> ToType boundsCheck(const FromType & value, const MinType & min) { if (int(value) >= int(min)) { return static_cast<ToType>(value); } fatal ("nope"); } enum class EventCat { kEventCat_NeverUseThis = 0, kUninitialized, kTesting, kEventCat_Min = kEventCat_NeverUseThis + 1, }; struct Event { using enum EventCat; Event(EventCat a_category, auto) : category(a_category) { boundsCheck<EventCat>(a_category, kEventCat_Min); // using "EventCat::kEventCat_Min" instead of just "kEventCat_Min" makes this not fail } EventCat category = EventCat::kUninitialized; }; void foo() { Event(EventCat::kTesting, 0); } --------------------------------------------------------------------------------- On Ubuntu 22.04 using g++-12 (Ubuntu 12.1.0-2ubuntu1~22.04) 12.1.0: $ g++-12 -c -std=c++20 g++-ice-in-tsubst_copy.cpp g++-ice-in-tsubst_copy.cpp: In instantiation of ‘Event::Event(EventCat, auto:1) [with auto:1 = int]’: g++-ice-in-tsubst_copy.cpp:38:32: required from here g++-ice-in-tsubst_copy.cpp:30:30: internal compiler error: in tsubst_copy, at cp/pt.cc:16919 30 | boundsCheck<EventCat>(a_category, kEventCat_Min); // using "EventCat::kEventCat_Min" instead of just "kEventCat_Min" makes this not fail | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ 0x661b9b tsubst_copy ../../src/gcc/cp/pt.cc:16919 0x80f2ce tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../src/gcc/cp/pt.cc:21399 0x81e961 tsubst_copy_and_build_call_args ../../src/gcc/cp/pt.cc:19937 0x80f8c0 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../src/gcc/cp/pt.cc:20687 0x8200e8 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../src/gcc/cp/pt.cc:19491 0x821097 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../src/gcc/cp/pt.cc:18462 0x821097 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../src/gcc/cp/pt.cc:18504 0x820c28 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../src/gcc/cp/pt.cc:18462 0x820c28 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../src/gcc/cp/pt.cc:18833 0x821632 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../src/gcc/cp/pt.cc:18462 0x821632 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../src/gcc/cp/pt.cc:18476 0x820c28 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../src/gcc/cp/pt.cc:18462 0x820c28 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../src/gcc/cp/pt.cc:18833 0x81f63c tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../src/gcc/cp/pt.cc:26412 0x81f63c instantiate_body ../../src/gcc/cp/pt.cc:26412 0x81ff09 instantiate_decl(tree_node*, bool, bool) ../../src/gcc/cp/pt.cc:26704 0x834bdb instantiate_pending_templates(int) ../../src/gcc/cp/pt.cc:26783 0x739197 c_parse_final_cleanups() ../../src/gcc/cp/decl2.cc:5128 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.