Issue |
89501
|
Summary |
[clang] User-defined conversion function called instead of converting constructor
|
Labels |
clang:frontend
|
Assignees |
|
Reporter |
BertalanD
|
Just noticed the following example fail to compile starting with GCC 14. MSVC also agrees that the converting constructor should be called, and also produces a compile error, but Clang accepts it and calls `UISize::operator IntSize`:
```c++
template <typename T> struct Size {
template <typename U> Size(Size<U> other) : m_width(other.width()) {}
T width();
T m_width;
};
using IntSize = Size<int>;
struct UIDimension {};
struct UISize : Size<UIDimension> {
operator IntSize();
};
void test(UISize u) { IntSize foo = IntSize(u); }
```
Godbolt: https://godbolt.org/z/MMYWc68xP
Compile error with GCC trunk (14.0.1 20240420):
```
<source>: In instantiation of 'Size<T>::Size(Size<U>) [with U = UIDimension; T = int]':
<source>:13:46: required from here
13 | void test(UISize u) { IntSize foo = IntSize(u); }
| ^
<source>:2:66: error: cannot convert 'UIDimension' to 'int' in initialization
2 | template <typename U> Size(Size<U> other) : m_width(other.width()) {}
| ~~~~~~~~~~~^~
| |
| UIDimension
```
I'm not sure who's right here, but this discrepancy in behavior is definitely odd.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs