Description
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 A(const C & n)
of class A
has the same parameter list as the inherited ctor, which leads to ambiguity:
<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