Issue 151631
Summary [Clang] Clang and GCC diverge on acceptance of function declaration inside constructor body
Labels clang
Assignees
Reporter Xniao
    I'm seeking clarification on whether the following code is well-formed C++.
Repro: https://godbolt.org/z/jKsaj9a9E

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 and MSVC both accept it.


## Program
```cpp
class S2 {
  int a;
public:
    S2(S2 &s2) : a(s2.a) {}

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

int main() {
    S2 s;
}
```

Is one compiler incorrect or not? Thank you for your time and insight!
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to