<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/89010>89010</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang] Diagnostic in immediate-escalating lambda is unnecessarily confusing
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:frontend,
consteval
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Sirraide
</td>
</tr>
</table>
<pre>
Attempting to compile this program
```c++
struct S {
consteval S(bool a) {
if (a) throw 3;
}
};
void f() {
[] { S s{true}; }();
}
```
results in this error (https://godbolt.org/z/edMG8rYYd)
```
<source>:8:5: error: call to immediate function 'f()::(anonymous class)::operator()' is not a constant expression
8 | [] { S s{true}; }();
| ^
<source>:3:16: note: subexpression not valid in a constant expression
3 | if (a) throw 3;
| ^~~~~~~
<source>:8:12: note: in call to 'S(true)'
8 | [] { S s{true}; }();
| ^~~~~~~
<source>:8:5: note: in call to '[] {
S s{true};
}.operator()()'
8 | [] { S s{true}; }();
| ^~~~~~~~~~~~~~~~~~~
```
which I don’t think is wrong, but complaining about the lambda not being a constant expression when the actual problem here is that the `consteval` constructor attempted to throw is rather confusing; I was a bit puzzled by this just now when I ran into this in another codebase. The ‘subexpression not valid in a constant expression’ note should be the actual error here imo.
Also, while this did seem related to #70925 to me at first, that issue seems to have already been fixed.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VU1v4zYQ_TX0ZRBDJq1IPvjgxHGRQ0_pZY8jcmRxS5EGP-J1Dv3tBSnH9qZZdBdoCUESyOHMmzfDRwxB7y3RmtUPrN7OMMXB-fWL9h61olnn1Gm9iZHGQ9R2D9GBdONBG4I46AAH7_YeR1ZtWbU5v--r6ZGMP-SnzIbok4zwAqw5zwAASGdDpFc08MJ42zlnABlffW-Uh-6B8basxcG7IwgmbkxYsz0Hb7aXhen96rSCnvH2H36nlPMcvEBgzUP0iSYHxWHZcvV2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