<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61819>61819</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang instantiates overload despite failing constraint
</td>
</tr>
<tr>
<th>Labels</th>
<td>
c++20,
rejects-valid,
concepts
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
cjdb
</td>
</tr>
</table>
<pre>
This GCC test should be well-formed, but is currently incorrect.
```cpp
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
template <class T> struct Z {
typedef typename T::x xx;
};
template <class T> concept C = requires { typename T::A; };
template <C T> typename Z<T>::xx f(void *, T); // #1
template <class T> void f(int, T); // #2
struct A {} a;
struct ZZ {
template <class T, class = typename Z<T>::xx> operator T *();
operator int();
};
int main() {
ZZ zz;
f(1, a); // OK, deduction fails for #1 because there is no conversion from int to void*
f(zz, 42); // OK, deduction fails for #1 because C<int> is not satisfied
}
```
Diagnostic issued:
```
<source>:5:20: error: type 'void' cannot be used prior to '::' because it has no members
typedef typename T::x xx;
^
<source>:12:39: note: in instantiation of template class 'Z<void>' requested here
template <class T, class = typename Z<T>::xx> operator T *();
^
<source>:12:49: note: in instantiation of default argument for 'operator type-parameter-0-0 *<void>' required here
template <class T, class = typename Z<T>::xx> operator T *();
^~~~~~~~~~~~~~
<source>:18:5: note: while substituting deduced template arguments into function template 'operator type-parameter-0-0 *' [with T = void, $1 = (no value)]
f(zz, 42); // OK, deduction fails for #1 because C<int> is not satisfied
^
<source>:18:3: note: while substituting deduced template arguments into function template 'f' [with T = int]
f(zz, 42); // OK, deduction fails for #1 because C<int> is not satisfied
^
```
Note that `struct A` and `T::A` are completely unrelated.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VkFv6zYM_jXKhUhhS0mcHHJInHaHAW_A0F16GWSZTvQgS5lEp00P--0DbTdN0fa9YcBqFLVDU-T3fSRl6ZT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