Open
Description
This code is probably valid in C++17, but not in C++14:
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
Clang is the only compiler that currently accepts it. Demo: https://gcc.godbolt.org/z/MbGqGE4Yr
According to C++14 standard class.inhctor#8:
... If that user-written constructor would be ill-formed, the program is ill-formed. Each expression in the expression-list is of the form
static_cast<T&&>(p)
, wherep
is the name of the corresponding constructor parameter andT
is the declared type ofp
.
So struct C
definition must be equivalent to:
struct C : B {
C(int x) : B(static_cast<int&&>(x)) {}
};
making the program ill-formed due to ambiguity. Demo: https://gcc.godbolt.org/z/hK9q4vPdj