-
Notifications
You must be signed in to change notification settings - Fork 12.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clang does not realize erroneous overload with inherited constructor #121331
Comments
@llvm/issue-subscribers-c-1 Author: Bo Wang (wangbo15)
The following code is rejected by GCC, MSVC, and EDG but accepted by Clang:
struct C
{
C(int = 1){}
};
struct D
{
D (C);
};
struct A : D
{
A (const C & n) : D (C{100}) {}
using D:: D;
};
int main(){
A a=C{};
} As the diagnostic shows, the user-defined ctor <source>: In function 'int main()':
<source>:18:9: error: conversion from 'C' to 'A' is ambiguous
18 | A a=C{};
| ^~~
<source>:18:9: note: there are 6 candidates
<source>:8:3: note: candidate 1: 'D::D(C)'
8 | D (C);
| ^
<source>:14:13: note: inherited here
14 | using D:: D;
| ^
<source>:13:3: note: candidate 2: 'A::A(const C&)'
13 | A (const C & n) : D (C{100}) {} Please see https://godbolt.org/z/vG9cqvMbc |
@llvm/issue-subscribers-clang-frontend Author: Bo Wang (wangbo15)
The following code is rejected by GCC, MSVC, and EDG but accepted by Clang:
struct C
{
C(int = 1){}
};
struct D
{
D (C);
};
struct A : D
{
A (const C & n) : D (C{100}) {}
using D:: D;
};
int main(){
A a=C{};
} As the diagnostic shows, the user-defined ctor <source>: In function 'int main()':
<source>:18:9: error: conversion from 'C' to 'A' is ambiguous
18 | A a=C{};
| ^~~
<source>:18:9: note: there are 6 candidates
<source>:8:3: note: candidate 1: 'D::D(C)'
8 | D (C);
| ^
<source>:14:13: note: inherited here
14 | using D:: D;
| ^
<source>:13:3: note: candidate 2: 'A::A(const C&)'
13 | A (const C & n) : D (C{100}) {} Please see https://godbolt.org/z/vG9cqvMbc |
It looks like Clang implements a pre-standard version of [over.match.best.general]/2.7 without the "all parameters have the same type" portion. There's a FIXME for this here. |
The following code is rejected by GCC, MSVC, and EDG but accepted by Clang:
As the diagnostic shows, the user-defined ctor
A(const C & n)
of classA
has the same parameter list as the inherited ctor, which leads to ambiguity:Please see https://godbolt.org/z/vG9cqvMbc
The text was updated successfully, but these errors were encountered: