<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/78213>78213</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
When name lookup fails, clang just gets it from an unrelated class
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
davidstone
</td>
</tr>
</table>
<pre>
Given the following ill-formed translation unit:
```cpp
struct S {
};
struct T {
static int m;
};
template<typename T>
auto a(T x) {
int * y = x;
}
void b() {
a(S::m);
}
```
When compiled with `-Wfatal-errors`, clang outputs
```console
<source>:10:8: fatal error: cannot initialize a variable of type 'int *' with an lvalue of type 'int'
10 | int * y = x;
| ^ ~
<source>:13:2: note: in instantiation of function template specialization 'a<int>' requested here
13 | a(S::m);
| ^
1 error generated.
Compiler returned: 1
```
See it live: https://godbolt.org/z/q4zx5n9jn
You can get a sane error message about `S` not having an `m` data member by:
* changing the type of `y` to `int`
* changing the return type of `a` to not be deduced
* removing `m` from `T`
Without `-Wfatal-errors`, you still get the very bad error message but then it's followed up with the right error message:
```console
<source>:10:8: error: cannot initialize a variable of type 'int *' with an lvalue of type 'int'
10 | int * y = x;
| ^ ~
<source>:13:2: note: in instantiation of function template specialization 'a<int>' requested here
13 | a(S::m);
| ^
<source>:13:4: error: no member named 'm' in 'S'; did you mean 'T::m'?
13 | a(S::m);
| ^~~~
| T::m
<source>:5:13: note: 'T::m' declared here
5 | static int m;
|
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsVstyqzgQ_Rp505UUSBDsBQvHiecDkqpbsxSoAWWExNXDN84i3z4lwM84U3c1q-ty2dB0S-ecfgjunGw1YknyR5I_LXjwnbGl4DspnDcaF5UR-_IvuUMNvkNojFLml9QtSKXuGmN7FOAt105xL42GoKUnbE2SJ5Icfh-S6VsPw2Rx3obawwuQ4nH2KZ4IezyPmn1ez3ySlfPcyxqk9tC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