Skip to content

Commit 1cf5188

Browse files
committed
[clang] Fix crash when passing a braced-init list to a parentehsized aggregate init expression
The previous code incorrectly assumed that we would never call warnBracedScalarInit(...) with a EK_ParenAggInitMember. This patch fixes the bug by warning when a scalar member is initialized via a braced-init list when performing a parentehsized aggregate initialization. This behavior is consistent with parentehsized list aggregate initialization. Fixes #63008 Reviewed By: shafik Differential Revision: https://reviews.llvm.org/D151763
1 parent 1ab4438 commit 1cf5188

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,9 @@ Bug Fixes in This Version
460460
- Fix crash when diagnosing default comparison method.
461461
(`#62791 <https://github.com/llvm/llvm-project/issues/62791>`_) and
462462
(`#62102 <https://github.com/llvm/llvm-project/issues/62102>`_).
463+
- Fix crash when passing a braced initializer list to a parentehsized aggregate
464+
initialization expression.
465+
(`#63008 <https://github.com/llvm/llvm-project/issues/63008>`_).
463466

464467
Bug Fixes to Compiler Builtins
465468
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaInit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,7 @@ static void warnBracedScalarInit(Sema &S, const InitializedEntity &Entity,
11581158
case InitializedEntity::EK_Parameter_CF_Audited:
11591159
case InitializedEntity::EK_TemplateParameter:
11601160
case InitializedEntity::EK_Result:
1161+
case InitializedEntity::EK_ParenAggInitMember:
11611162
// Extra braces here are suspicious.
11621163
DiagID = diag::warn_braces_around_init;
11631164
break;
@@ -1192,7 +1193,6 @@ static void warnBracedScalarInit(Sema &S, const InitializedEntity &Entity,
11921193
case InitializedEntity::EK_LambdaToBlockConversionBlockElement:
11931194
case InitializedEntity::EK_Binding:
11941195
case InitializedEntity::EK_StmtExprResult:
1195-
case InitializedEntity::EK_ParenAggInitMember:
11961196
llvm_unreachable("unexpected braced scalar init");
11971197
}
11981198

clang/test/SemaCXX/paren-list-agg-init.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,9 @@ O o2(0, 0); // no-error
266266
O o3(0);
267267
// expected-error@-1 {{reference member of type 'int &&' uninitialized}}
268268
}
269+
270+
namespace gh63008 {
271+
auto a = new A('a', {1.1});
272+
// expected-warning@-1 {{braces around scalar init}}
273+
// beforecxx20-warning@-2 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
274+
}

0 commit comments

Comments
 (0)