Skip to content

[clang] For-range with structured bindings during constant evaluation #145956

@katzdm

Description

@katzdm

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"constevalC++20 constevaldiverges-from:gccDoes the clang frontend diverge from gcc on this issuediverges-from:msvcDoes the clang frontend diverge from msvc on this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions