Friend function with requires causes segfault

Bug #1950053 reported by Christoph Neumann
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gcc-11 (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

From the versions installed on my machine, the bug occurs in g++ 10.2.0, g++ 10.3.0 and g++ 11.1.0, the only argument in -std=c++2a. The code works on version 9.3.0 with -std=c++2a and -fconcepts. I have also compiled with clang++ 12.0.0 without problems. The bug occurs when two or more classes declare a template friend function with a requires. The return type, number of arguments, number of template parameters, and condition for requires does not make any difference.Example:

class Foo
    {
        template <typename T>
        friend void func() requires true;
    };
    class Bar
    {
        template <typename T>
        friend void func() requires true;
    };

This code results in the following error message:

internal compiler error: Segmentation fault
    9 | friend void func() requires true;
      | ^~~~
0xe30681 internal_error(char const*, ...)
        ???:0
0xf54144 duplicate_decls(tree_node*, tree_node*, bool, bool)
        ???:0
0xf5da9b pushdecl_namespace_level(tree_node*, bool)
        ???:0
0x109001a push_template_decl(tree_node*, bool)
        ???:0
0x151d391 do_friend(tree_node*, tree_node*, tree_node*, tree_node*, overload_flags, bool)
        ???:0
0xfbfc27 grokdeclarator(cp_declarator const*, cp_decl_specifier_seq*, decl_context, int, tree_node**)
        ???:0
0x1003fd4 grokfield(cp_declarator const*, cp_decl_specifier_seq*, tree_node*, bool, tree_node*, tree_node*)
        ???:0
0x1492c03 c_parse_file()
        ???:0
0x148061e c_common_parse_file()
        ???:0
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-11/README.Bugs> for instructions.

On g++-10.x the error is only

internal compiler error: Segmentation fault
    9 | friend void func() requires true;
      | ^~~~
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-10/README.Bugs> for instructions.

Whether the function actually exists does not have any impact. The error message always points to the second definition, in this case Bar.

Revision history for this message
Matthias Klose (doko) wrote :

this works with gcc-11 on Ubuntu 22.04 LTS

Changed in gcc-11 (Ubuntu):
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.