[clang] [clang] Fix parenthesized list initialization of arrays not working with `new` (PR #76976)
Alan Zhao via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 9 17:26:57 PST 2024
================
@@ -1038,11 +1038,14 @@ void CodeGenFunction::EmitNewArrayInitializer(
return true;
};
+ const InitListExpr *ILE = dyn_cast<InitListExpr>(Init);
+ const CXXParenListInitExpr *CPLIE = dyn_cast<CXXParenListInitExpr>(Init);
+ const StringLiteral *SL = dyn_cast<StringLiteral>(Init);
// If the initializer is an initializer list, first do the explicit elements.
- if (const InitListExpr *ILE = dyn_cast<InitListExpr>(Init)) {
+ if (ILE || CPLIE || SL) {
----------------
alanzhao1 wrote:
This is parsed as a `StringLiteral` as shown in the AST.
`new-array.cc`:
```cpp
char* x = new char[]("asdf");
```
```
$ ./bin/clang -Xclang -ast-dump -std=c++20 ~/src/tests/new-array.cc
(irrelevant bits omitted)
|-VarDecl 0x557ce6fee8c0 </usr/local/google/home/ayzhao/src/tests/new-array.cc:1:1, col:28> col:7 x 'char *' cinit
| `-CXXNewExpr 0x557ce700cca0 <col:11, col:28> 'char *' array Function 0x557ce6fef0a0 'operator new[]' 'void *(unsigned long)'
| |-IntegerLiteral 0x557ce700cc50 <col:15> 'unsigned long' 5
| `-StringLiteral 0x557ce6feea00 <col:22> 'char[5]' "asdf"
```
https://github.com/llvm/llvm-project/pull/76976
More information about the cfe-commits
mailing list