[clang] [Clang][Sema] Fix wrong initialization kind when handling initializing structured bindings from an array with direct-list-initialization (PR #124793)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 28 10:39:10 PST 2025


================
@@ -4861,8 +4861,9 @@ static void TryListInitialization(Sema &S,
             S.Context.hasSameUnqualifiedType(SubInit[0]->getType(), DestType) &&
             "Deduced to other type?");
         TryArrayCopy(S,
-                     InitializationKind::CreateCopy(Kind.getLocation(),
-                                                    InitList->getLBraceLoc()),
+                     InitializationKind::CreateDirect(Kind.getLocation(),
+                                                      InitList->getLBraceLoc(),
+                                                      InitList->getRBraceLoc()),
----------------
cor3ntin wrote:

> and each element is copy-initialized or direct-initialized from the corresponding element of the [assignment-expression](https://eel.is/c++draft/expr.ass#nt:assignment-expression) as specified by the form of the [initializer](https://eel.is/c++draft/dcl.init.general#nt:initializer)[.](https://eel.is/c++draft/dcl.struct.bind#1.sentence-8) Otherwise, e is defined as-if by

So I think 

```cpp
auto [_]{a}; // direct-initialization
auto [_](a); // copy-initializer
```

Is my understanding correct that we need that we need to look at `Kind.getKind()` and call either `CreateCopy` or CreateDirect?


https://github.com/llvm/llvm-project/pull/124793


More information about the cfe-commits mailing list