Clang accepts a constructor template whose default argument initializes int from nullptr
Open
c++11
clang:frontend
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Clang 22 accepts the following C++20 program, while Clang GCC 15.2.0 rejects it:
```c++
struct C {
C() {}
template
C(C&, T = nullptr) {}
};
C c;
struct A {
explicit operator C&() const { return c; }
};
int main() {
A a;
C x(a);
}
```
Clang: clang++-22 22.0.0
-std=c++20: accepts
-std=c++20 -pedantic-errors: accepts
GCC: gcc15 15.2.0
-std=c++20: rejects
-std=c++20 -pedantic-errors: rejects
GCC diagnostic:
```
error: could not convert 'nullptr' from 'std::nullptr_t' to 'int'
note: when instantiating default argument for call to 'C::C(C&, T) [with T = int]'
```
Contributor guide
Assessment
This issue has not been assessed yet.