Issue 145956
Summary [clang] For-range with structured bindings during constant evaluation
Labels clang
Assignees
Reporter katzdm
    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).
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to