https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128656
Bug ID: 128656
Summary: Accepts method definition of local class outside of
the function
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: accepts-invalid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
GCC accepts function definition of a local class from outside of the function:
```
auto f() {
struct A {
A();
void g();
};
return A{};
}
using A = decltype(f());
A::A() = default;
void A::g() {}
```
[class.local]/2: "Member functions of a local class shall be defined within
their class definition, if they are defined at all."
See also https://stackoverflow.com/q/79808341/7325599 and CWG2890.
Note GCC also accepts inner class definition too:
```
void f1() {
class A { class B; };
{
class A::B {};
}
}
```