[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:51 PST 2024


================
@@ -5495,14 +5495,12 @@ static void TryOrBuildParenListInitialization(
         return;
     }
     //   ...and value-initialized for each k < i <= n;
-    if (ArrayLength > Args.size()) {
----------------
alanzhao1 wrote:

> What is this change supposed to do?

`CodeGenFunction::EmitNewArrayInitializer(...)` needs an array filler for dynamic-sized arrays - e.g.

```cpp
void foo(int n) {
  new int[n](1, 2);
}
```

> The existing code is intentionally trying to avoid creating an array filler if it won't be used (so, for example, the code will compile if the default constructor is deleted).

Thanks for pointing this out! There was no test for this case with a deleted constructor, so I'll have to create a separate PR to add one later.

In the meantime, I resolved this by adding `Entity.isVariableLengthArrayNew()` to the conditional here. This is also what we do in `InitListChecker` to detect this condition.


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


More information about the cfe-commits mailing list