[clang] For-range with structured bindings during constant evaluation (original) (raw)

As far as I can tell, the following should be well-formed:

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.