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

            Bug ID: 121367
           Summary: Clang and GCC diverge on acceptance of function
                    declaration inside constructor body
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jirehguo at tju dot edu.cn
  Target Milestone: ---

Repro: https://godbolt.org/z/4Tev5x6os

GCC rejects it with:
<source>: In constructor 'S2::S2()':
<source>:7:5: error: return type specification for constructor invalid
    7 |     S2(S2());
      |     ^~
<source>:7:12: error: 'S2' declared in a non-class scope
    7 |     S2(S2());
      |            ^
Compiler returned: 1

However, Clang, EDG and MSVC all accept it.
Is one compiler incorrect or not? Thank you for your time and insight!

Code:
-----------------------------
class S2 {
  int a;
public:
    S2(S2 &s2) : a(s2.a) {}

  S2() : a(0) {
    S2(S2());
  }
};

int main() {
    S2 s;
}

Reply via email to