Friend function with requires causes segfault
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_
???:0
0xf5da9b pushdecl_
???:0
0x109001a push_template_
???:0
0x151d391 do_friend(
???:0
0xfbfc27 grokdeclarator(
???:0
0x1003fd4 grokfield(
???:0
0x1492c03 c_parse_file()
???:0
0x148061e c_common_
???:0
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <file:/
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:/
Whether the function actually exists does not have any impact. The error message always points to the second definition, in this case Bar.
this works with gcc-11 on Ubuntu 22.04 LTS