[clang] [clang] Fix parenthesized list initialization of arrays not working with `new` (PR #76976)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 9 14:47:38 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) {
----------------
efriedma-quic wrote:
This code is assuming the initializer for an array must be one of the following:
- An InitListExpr with a list of elements
- A CXXParentListInitExpr with a list of elements
- An InitListExpr with a "string" (isStringLiteralInit is true)
- A StringLiteral
Looking at the standard, I guess this is a complete list.
The last one seems a little suspect to me, though; if it's using the same IsStringInit() as InitListExpr does, a "string" might not be a StringLiteral.
https://github.com/llvm/llvm-project/pull/76976
More information about the cfe-commits
mailing list