Open
Description
This code doesn't compile on Compiler Explorer. Moving the defaulted parameter to the constructor body seems to be okay.
template<class T>
class single;
template<class T, class U>
class check_constructible {
check_constructible() = default;
static_assert(is_constructible_v<T, U>);
template<class X>
friend class single;
};
template<class T>
struct single {
template<class U>
single(U u, check_constructible<T, U> = {})
: x(u)
{}
T x;
};
int main() {
single<int> x(0);
}
Diagnostic:
<source>:25:45: error: calling a private constructor of class 'check_constructible<int, int>'
25 | single(U u, check_constructible<T, U> = {})
| ^
<source>:14:5: note: implicitly declared private here
14 | check_constructible() = default;
| ^
Compiler info:
clang version 19.0.0git (https://github.com/llvm/llvm-project.git 5b058709536dd883980722ee000bb7b8c7b2cd8b)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-trunk-20240301/bin
Compiler returned: 0
Both GCC and MSVC accept this code. If it's not conforming, should we accept it as an extension?