<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/137270>137270</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang fails to redo overload resolution in `typeid` operand after lambda _id-expression_ transformation
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:frontend,
rejects-valid,
lambda,
diverges-from:gcc,
diverges-from:msvc,
diverges-from:edg
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hubert-reinterpretcast
</td>
</tr>
</table>
<pre>
The transformation in https://wg21.link/expr.prim.lambda.capture#11 can change the `const` qualification of a glvalue expression in a non-mutable lambda and whether or not a `typeid` has an unevaluated operand or not.
Clang fails to redo overload resolution after the `const` qualification of an argument changes because of the rewrite.
Unlike https://github.com/llvm/llvm-project/issues/22978, the type of the operand is _correctly_ `const` in the end. The error here is in the choice of `f`.
https://godbolt.org/z/qzs6bnfMo
### Source (`<stdin>`)
```cpp
#include <typeinfo>
struct A {
virtual void f();
};
int &f(const int &);
A &f(int &);
constexpr auto q(int &&x) {
return [=] { return &typeid(f(x)); }(); // x has type `int`, causing odr-use and triggering rewrite;
// after rewrite x has type `const int` and the result is `typeid(int)`.
}
static_assert(q(0) == &typeid(int));
```
### Compiler invocation command
```
clang++ -fsyntax-only -Wall -Wextra -pedantic -std=c++2c -stdlib=libc++ -xc++ -
```
### Actual compiler output
```
<stdin>:8:33: error: binding reference of type 'int' to value of type 'const int' drops 'const' qualifier
8 | return [=] { return &typeid(f(x)); }(); // x has type `int`, causing odr-use and triggering rewrite;
| ^
<stdin>:6:11: note: passing argument to parameter here
6 | A &f(int &);
| ^
<stdin>:11:20: error: invalid operands to binary expression ('void' and 'const std::type_info *')
11 | static_assert(q(0) == &typeid(int));
| ~~~~ ^ ~~~~~~~~~~~~
2 errors generated.
```
### Expected compiler output
(clean compile)
### Compiler version info (`clang++ -v`)
```
clang version 21.0.0git (https://github.com/llvm/llvm-project.git 6ba704a7f4e72ba088fa19c7622e42b9c460da47)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/wandbox/clang-head/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/13
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/14
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/14
Candidate multilib: .;@m64
Selected multilib: .;@m64
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMV0uT27gR_jXQpYsqCHzqoAMtWakcctpN7XEKBJoUYhCgAVCj2YN_ewogpfHM2hsnzmFVqhoIjX5__RjuvRoM4oGUH0h52vA5XKw7XOYOXcgcKhPQTQ6D4D5sOitfDr9eEILjxvfWjTwoa0AZuIQweZK3hJ0JOz8PbLfVynwi7Iy3yW0np8at5mMn-VbwKcwOCct3OxDcgLhwMyCECwKpqLDGB1JR-DxzrXolFh22Bw6DvnI9I0SZ6P2qm4OxJhvnwDuNsGgBbiQ8XzBc0IF1YGwAHsWHlwmVjPIv3AM3MBuMQnlACXZCFxkXhi2hLaHtUXMzQM-V9hAsOJQW7BWdtlyCQ2_1nCzkfUD3A14Y4G6YRzRh9dxDh4LPHiM58jt8dirgqv-fRqtP-C7CgwqXudsKOxJ21vp6_5NNzv4LRSDsrLyf0RN2ZmxfN4Qdk-zo_13P3V3l4UlY51AE_fL0xnxl0ks0cgsx8-icdXBBh5FrpYqLVSJJJRXtSUVXy9-ZbGVnddhaNxB2_p2w8-fffdWZ_h92eU5YvnzhFzs7gUBYQypK8qMPUhmSf4y_2D4-rejyFdO0cCoj9CwRSH5MKTa9jQy09cHNIkALpP5AaAtwVS7MXMPVKgl91MH2JI80Up-WgzIBCKsiMUUC1ovHy_ZOfk9IzyM8gc_Bwuevn1Q3wvZ3MxyG2RmIdZefSHmK949LVq0wZU1UEvkWDRBNvFsMsAQWbgnLKbOkosqEFKcjRFApM4CVLovwirkOTg0Duni9wmwxHH78s2pd8L4KeWf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