<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/145956>145956</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] For-range with structured bindings during constant evaluation
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
katzdm
</td>
</tr>
</table>
<pre>
As far as I can tell, the following should be well-formed:
```cpp
consteval auto f() -> int {
struct Pair { int first; int second; };
Pair arr[] = {{1, 1}};
for (auto const& [key, value] : arr) {
[=] { [[maybe_unused]] int s = key; }();
}
return 0;
}
int p = f();
```
https://compiler-explorer.com/z/5cGfrMTd7
GCC and MSVC accept; Clang and EDG reject, but EDG has acknowledged their behavior as a bug.
I did some preliminary digging, and the issue looks to occur while computing the lvalue-to-rvalue conversion of the `DeclRefExpr` that names `key` in the initializer of `s`; the `findCompleteObject` routine seems to be tripping over the structured binding and returns an empty `CompleteObject` [here](https://github.com/llvm/llvm-project/blob/a0c5f1992d2188dd58987445aa00a55edad2357f/clang/lib/AST/ExprConstant.cpp#L4488).
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVE2P2zYQ_TX0ZWCDpr4POvhjvQjQoEUT9FpQ4khilyIFkvJm99cXQ3mbFO0lhgCL5MybN_OeKEPQo0VsWXFmxXUn1zg5377I-K7mXefUW3sKMEgPMsAn6KWFiMYwcYE4IQzOGPeq7QhhcqtR0CG8ojH7wfkZFctOjKen5NvTLwvjp97ZEPEuDcg1OhiYqJloYM-yJ9A2AqvOjJ8AAEL0ax_hN6k97abTQfsQWbYtAvbOKlqx6sqy81aPUlOO9H7rDFh2TbjV-UjsjxT-kUHhg_PARJ0IJX5MlMCK8wu-UfxdmhU3nFNCFc0PNOlHdbJrCqnOaVWcZ_nW4Z-rXQMqVqTDRDqxIeQH79T_dy60tb15jKu3wB-dpX3GTwSyJJDhx9x_xsz4aYpx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