[PATCH] D129531: [clang][C++20] P0960R3: Allow initializing aggregates from a parenthesized list of values

Alan Zhao via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 20 15:13:15 PDT 2022


ayzhao added inline comments.


================
Comment at: clang/lib/Sema/SemaInit.cpp:6052
+    } else if (S.getLangOpts().CPlusPlus20 && !TopLevelOfInitList)
+      TryOrBuildParenListInitialization(S, Entity, Kind, Args, *this,
+                                        /*VerifyOnly=*/true);
----------------
ayzhao wrote:
> Status update:
> 
> Right now this is causing the following 2 bugs:
> 
> 1. Currently, the below incorrect line of code:
> 
> ```
> int arr[2] = 1;
> ```
> 
> is being incorrectly treated the same as
> 
> ```
> int arr[2](1);
> ```
> 
> 2. The following below correct line of code:
> ```
> int arr[2] = static_cast<int[2]>(1);
> ```
> 
> fails with the error:
> 
> ```
> test-static-cast.cc:1:12: error: static_cast from 'int' to 'int[2]' is not allowed
> int a[2] = static_cast<int[2]>(1);
>            ^~~~~~~~~~~~~~~~~~~~~~
> 1 error generated.
> ```
small fix: the incorrect error message for the 2nd bug is:

```
test-static-cast.cc:1:12: error: cannot initialize an array element of type 'int' with an rvalue of type 'int[2]'
int a[2] = static_cast<int[2]>(1);
           ^~~~~~~~~~~~~~~~~~~~~~
1 error generated.
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129531/new/

https://reviews.llvm.org/D129531



More information about the cfe-commits mailing list