https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111079
Bug ID: 111079
Summary: Failing to reject a defaulted/deleted local function
definition if it is a friend of a local class
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: janschultke at googlemail dot com
Target Milestone: ---
## Code to Reproduce A (https://godbolt.org/z/ar34vn5dT)
void foo() {
struct A;
bool operator ==(const A&, const A&);
struct A {
friend bool operator ==(const A&, const A&);
};
bool operator ==(const A&, const A&) = default;
}
## Code to Reproduce B (https://godbolt.org/z/sdo9fhacb)
void foo() {
struct A;
bool bar(const A&, const A&);
struct A {
friend bool bar(const A&, const A&);
};
bool bar(const A&, const A&) = delete;
}
## Expected Output
Compiler error.
## Actual Output
<source>: In function 'void foo()':
<source>:7:40: warning: declaration of 'bool operator==(const foo()::A&, const
foo()::A&)' has 'extern' and is initialized
7 | bool operator ==(const A&, const A&) = default;
|
## Explanation
According to [dcl.fct.def.general] p2:
> A function shall be defined only in namespace or class scope.
There is a definition of `operator==` at block scope, which is obviously
invalid. Operator overloads are also considered functions
([over.oper.general]), so they should be subject to the same rules.