llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[clang] Structured bindings cannot be initialized from braced rvalue arrays

Open MagentaTreehouse opened this issue 2 years ago • 2 comments

The following code fails to compile:

struct Array {
    int data[2];
};

Array f() { return {}; }

int main() {
    auto [a, b]{f().data}; // xvalue init
    using T = int [2];
    auto [c, d]{T{}}; // prvalue init
}

See Compiler Explorer: https://godbolt.org/z/P3EPzWdTc

MagentaTreehouse avatar Jul 10 '24 02:07 MagentaTreehouse

@llvm/issue-subscribers-clang-frontend

Author: None (MagentaTreehouse)

The following code fails to compile: ```cpp struct Array { int data[2]; };

Array f() { return {}; }

int main() { auto [a, b]{f().data}; // xvalue init using T = int [2]; auto [c, d]{T{}}; // prvalue init }

See Compiler Explorer: https://godbolt.org/z/P3EPzWdTc
</details>

llvmbot avatar Jul 10 '24 02:07 llvmbot

Duplicate of: https://github.com/llvm/llvm-project/issues/31813

shafik avatar Jul 10 '24 04:07 shafik