In the following program, struct B
has two user-defined constructors: one from int
and another from int&&
(clearly this is not very practical). And an object of B
is created from an l-value, which should unambiguously select the first constructor. Then struct C
is derived from B
inheriting its constructor by the using
-declaration, and an object of C
is created from the very same l-value:
struct B {
B(int) {}
B(int&&) {}
};
int i = 1;
B b(i); //ok everywhere
struct C : B {
using B::B;
};
C c(i); //ok in Clang only
MSVC prints rather strange error in the last line:
source>(10): error C2668: 'B::B': ambiguous call to overloaded function
<source>(3): note: could be 'B::B(int &&)'
<source>(2): note: or 'B::B(int)'
<source>(10): note: while trying to match the argument list '(int)'
despite l-value argument.
GCC error seems to agree and explains more:
source>:13:6: error: use of deleted function 'C::C(int) [inherited from B]'
13 | C c(i);
| ^
<source>:10:14: note: 'C::C(int) [inherited from B]' is implicitly deleted because the default definition would be ill-formed:
10 | using B::B;
| ^
<source>:10:14: error: call of overloaded 'B(int)' is ambiguous
At the same time Clang accepts the code just fine, demo: https://gcc.godbolt.org/z/oGjzrYEhz
Which compiler is right here?