<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62466>62466</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang mis-compilation with SFINAE/enable_if
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:frontend
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
njames93
</td>
</tr>
</table>
<pre>
We recently tried to add clang as a supported compiler for a project, however we noticed what appears to be a nasty bug with overload resolution. Take this reduced example here
```cpp
#include <type_traits>
struct B {
template <typename T>
operator T() const;
};
struct C {
template <typename T>
operator T() const;
};
template <typename Base = C>
struct A : Base {
template <typename T, typename B = Base,
typename = std::enable_if_t<std::is_same_v<B, C>>>
operator T() const;
};
enum class Enum {};
void foo() {
A<B> a;
Enum b;
b = a; // Error cause
}
```
In this example, during overload resolution, The `operator T()` in `struct A` has a substitution failure due to the failed `enable_if` condition, therefore it is disregarded as a candidate. However, in its base struct,`B`, there is a valid candidate with no restrictions that should be selected.
Both MSVC and GCC latest release and trunk compile this code correctly, clang 16.0 and trunk both reject this
https://godbolt.org/z/b1nf68bds
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VU2T4jYQ_TXi0jWUkcF4Dj6AZ0j2kFx2KjlO6aPB2pUll9RmQn59qm0GdjabS6qWcoFp9Xt6aj21VM7uFBAbsdmLzdNCjdTF1IQvqsf8WC50tJfmT4SEBgP5C1ByaIEiKGvBeBVOoDIoyOMwxERowcR-cB4THGMCBUOKX9CQkC108Q3PmOANIURyBi28dYpADQOqlJlVIygIKtMF9HiCN0cdxDMmH5WFhDn6kVwMS3hRXxGocxkS2pGp8C_VDx6hw4SieBLFTlTF_JhhuEZk6YLxo0UQZUuXAV8pKUdZlM_XjOk7UxoNwR7Edj9HAAAI-8ErumGD6hFeblBOiQMmRTHBi5C1kI9gYsgkyiuL2D7d37-dqf35M_2Qc68yB56gvZFfFe1A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