[Bug c++/124745] New: [16 Regression]ICE in decl_mismatch_context on mismatched constrained friend declaration

attackerj1113 at gmail dot com gcc-bugzilla@gcc.gnu.org
Wed Apr 1 08:49:55 GMT 2026


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124745

            Bug ID: 124745
           Summary: [16 Regression]ICE in decl_mismatch_context on
                    mismatched constrained friend declaration
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: ice-on-invalid-code
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: attackerj1113 at gmail dot com
  Target Milestone: ---

The following code causes ICE out on x86-64 gcc only on trunk, while Clang
accepts it:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template<typename T> concept C = true;

struct A {
    template<C T> void f();
};

template<typename X>
struct Friends {
    template<C T> friend void A::f();
};

Friends<int> f1;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
https://godbolt.org/z/hW7rbnM8E

I lean toward the view that Clang’s acceptance of this code is incorrect.
When instantiating Friends<int>, GCC correctly detects this mismatch but then
hits an internal compiler error in decl_mismatch_context while attempting to
reconcile the friend declaration with the existing member template.

Output:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>: In instantiation of 'struct Friends<int>':
<source>:12:14:   required from here
   12 | Friends<int> f1;
      |              ^~
<source>:9:31: error: no declaration matches 'template<class T>  requires  C<T>
void A::f()'
    9 |     template<C T> friend void A::f();
      |                               ^
<source>:9:31: internal compiler error: in decl_mismatch_context, at
cp/decl2.cc:960
0x2968998 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
        ???:0
0x295d5db internal_error(char const*, ...)
        ???:0
0xb23244 fancy_abort(char const*, int, char const*)
        ???:0
0xdda16b instantiate_class_template(tree_node*)
        ???:0
0xbfdc9d start_decl_1(tree_node*, bool)
        ???:0
0xc2258d start_decl(cp_declarator const*, cp_decl_specifier_seq*, int,
tree_node*, tree_node*, tree_node**)
        ???:0
0xd6fad3 c_parse_file()
        ???:0
0xefa7a9 c_common_parse_file()
        ???:0
/cefs/01/016f6d483223a38503416650_gcc-trunk-20260401/bin/../libexec/gcc/x86_64-linux-gnu/16.0.1/cc1plus
-quiet -imultiarch x86_64-linux-gnu -iprefix
/cefs/01/016f6d483223a38503416650_gcc-trunk-20260401/bin/../lib/gcc/x86_64-linux-gnu/16.0.1/
-D_GNU_SOURCE <source> -quiet -dumpdir /app/ -dumpbase output.cpp -dumpbase-ext
.cpp -masm=intel -mtune=generic -march=x86-64 -g -std=c++20
-fdiagnostics-color=always -fno-verbose-asm -o /app/output.s
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


More information about the Gcc-bugs mailing list