https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101715
--- Comment #15 from Sergei Trofimovich <slyfox at gcc dot gnu.org> --- clang's compiler-rt fails to build for quite a while due to this ICE. Trying to poke at the failure. I shrunk the example slightly further: template <class A> struct S { S<A> & bar() noexcept(A::value); S<A> & foo() noexcept(A::value); }; template <class A> S<A> & S<A>::foo() noexcept(A::value) {} c++17 seems to be the trigger (perhaps due to noexcept argument type change?). Also, if we comment out seemingly unrelated `S::foo()` declaration ICE disappears. Could it be that there is an unexpected type sharing in an uninstantiated type? The backtrace: $ g++-12.0.0 -c a.c.cpp -std=c++14 $ g++-12.0.0 -c a.c.cpp -std=c++17 a.c.cpp:6:56: internal compiler error: canonical types differ for identical types 'S<A>& (S<A>::)() noexcept (A::value)' and 'S<A>& (S<A>::)() noexcept (A::value)' 6 | template <class A> S<A> & S<A>::foo() noexcept(A::value) {} | ^ 0xc3f6ee comptypes(tree_node*, tree_node*, int) ../../gcc-12-20211226/gcc/cp/typeck.c:1558 0xa784ce duplicate_decls(tree_node*, tree_node*, bool, bool) ../../gcc-12-20211226/gcc/cp/decl.c:2409 0xa7f2bb grokfndecl ../../gcc-12-20211226/gcc/cp/decl.c:10351 0xa83cf6 grokdeclarator(cp_declarator const*, cp_decl_specifier_seq*, decl_context, int, tree_node**) ../../gcc-12-20211226/gcc/cp/decl.c:14154 0xa88196 start_function(cp_decl_specifier_seq*, cp_declarator const*, tree_node*) ../../gcc-12-20211226/gcc/cp/decl.c:17171 0xb82c0f cp_parser_function_definition_from_specifiers_and_declarator ../../gcc-12-20211226/gcc/cp/parser.c:31047 0xb82c0f cp_parser_init_declarator ../../gcc-12-20211226/gcc/cp/parser.c:22520 0xb8a93e cp_parser_single_declaration ../../gcc-12-20211226/gcc/cp/parser.c:31683 0xb8aab6 cp_parser_template_declaration_after_parameters ../../gcc-12-20211226/gcc/cp/parser.c:31243 0xb8b340 cp_parser_explicit_template_declaration ../../gcc-12-20211226/gcc/cp/parser.c:31509 0xb8dcf1 cp_parser_declaration ../../gcc-12-20211226/gcc/cp/parser.c:14849 0xb8e7a2 cp_parser_toplevel_declaration ../../gcc-12-20211226/gcc/cp/parser.c:14939 0xb8e7a2 cp_parser_translation_unit ../../gcc-12-20211226/gcc/cp/parser.c:4987 0xb8e7a2 c_parse_file() ../../gcc-12-20211226/gcc/cp/parser.c:47944 0xcbefcd c_common_parse_file() ../../gcc-12-20211226/gcc/c-family/c-opts.c:1238 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. Poking at the internals: (gdb) fr 1 #1 0x0000000000c3f6ef in comptypes (t1=0x7fffea3791f8, t2=0x7fffea3627e0, strict=<optimized out>) at ../../gcc-12-20211226/gcc/cp/typeck.c:1557 1557 ../../gcc-12-20211226/gcc/cp/typeck.c: No such file or directory. (gdb) call debug_generic_expr(t1) struct S & S::<T385> (struct S *) (gdb) call debug_generic_expr(t2) struct S & S::<T37d> (struct S *) (gdb) call debug_tree(t1) <method_type 0x7fffea3791f8 type <reference_type 0x7fffea3629d8 type <record_type 0x7fffea362930 S cxx-odr-p type_0 type_5 type_6 VOID align:8 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type 0x7fffea362c78 context <translation_unit_decl 0x7fffea220168 a.c.cpp> full-name "struct S<A>" no-binfo use_template=1 interface-unknown reference_to_this <reference_type 0x7fffea3629d8> chain <type_decl 0x7fffea241b48 S>> unsigned DI size <integer_cst 0x7fffea212f48 constant 64> unit-size <integer_cst 0x7fffea212f60 constant 8> align:64 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type 0x7fffea362f18> QI size <integer_cst 0x7fffea234048 type <integer_type 0x7fffea2320a8 bitsizetype> constant 8> unit-size <integer_cst 0x7fffea234060 type <integer_type 0x7fffea232000 sizetype> constant 1> align:8 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type 0x7fffea3627e0 method basetype <record_type 0x7fffea362c78 S> arg-types <tree_list 0x7fffea378438 value <pointer_type 0x7fffea362dc8 type <record_type 0x7fffea362c78 S> unsigned DI size <integer_cst 0x7fffea212f48 64> unit-size <integer_cst 0x7fffea212f60 8> align:64 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type 0x7fffea362dc8> chain <tree_list 0x7fffea228b68 value <void_type 0x7fffea232f18 void>>> throws <tree_list 0x7fffea378410 purpose <scope_ref 0x7fffea3783e8 tree_0 arg:0 <template_type_parm 0x7fffea362888 A> arg:1 <identifier_node 0x7fffea22e4c0 value normal local bindings <(nil)>> a.c.cpp:6:51 start: a.c.cpp:6:51 finish: a.c.cpp:6:55>>> (gdb) call debug_tree(t2) <method_type 0x7fffea3627e0 type <reference_type 0x7fffea362f18 type <record_type 0x7fffea362c78 S cxx-odr-p type_0 type_5 type_6 VOID size <integer_cst 0x7fffea212fc0 constant 0> unit-size <integer_cst 0x7fffea212f78 constant 0> align:8 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type 0x7fffea362c78 fields <using_decl 0x7fffea241a18 operator=> context <translation_unit_decl 0x7fffea220168 a.c.cpp> full-name "struct S<A>" n_parents=0 use_template=0 interface-unknown pointer_to_this <pointer_type 0x7fffea362dc8> reference_to_this <reference_type 0x7fffea362f18> chain <type_decl 0x7fffea2418e8 S>> unsigned type_0 type_6 DI size <integer_cst 0x7fffea212f48 constant 64> unit-size <integer_cst 0x7fffea212f60 constant 8> align:64 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type 0x7fffea362f18> type_0 type_6 QI size <integer_cst 0x7fffea234048 type <integer_type 0x7fffea2320a8 bitsizetype> constant 8> unit-size <integer_cst 0x7fffea234060 type <integer_type 0x7fffea232000 sizetype> constant 1> align:8 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type 0x7fffea362540 method basetype <record_type 0x7fffea362c78 S> arg-types <tree_list 0x7fffea35cf28 value <pointer_type 0x7fffea362dc8 type <record_type 0x7fffea362c78 S> unsigned DI size <integer_cst 0x7fffea212f48 64> unit-size <integer_cst 0x7fffea212f60 8> align:64 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type 0x7fffea362dc8> chain <tree_list 0x7fffea228b68 value <void_type 0x7fffea232f18 void>>> throws <tree_list 0x7fffea378230 purpose <scope_ref 0x7fffea378208 tree_0 arg:0 <template_type_parm 0x7fffea362bd0 A> arg:1 <identifier_node 0x7fffea22e4c0 value normal local bindings <(nil)>> a.c.cpp:3:30 start: a.c.cpp:3:30 finish: a.c.cpp:3:34>>> If I read the difference correctly `t1` has no `operator=` field while `t2` has.