Skip to content

Commit 185b81e

Browse files
alanzhao1tstellar
authored andcommitted
[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 llvm#63008 Reviewed By: shafik Differential Revision: https://reviews.llvm.org/D151763
1 parent 42f2e6e commit 185b81e

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
@@ -721,6 +721,9 @@ Bug Fixes in This Version
721721
- Fix crash when handling nested immediate invocations in initializers of global
722722
variables.
723723
(`#58207 <https://github.com/llvm/llvm-project/issues/58207>`_)
724+
- Fix crash when passing a braced initializer list to a parentehsized aggregate
725+
initialization expression.
726+
(`#63008 <https://github.com/llvm/llvm-project/issues/63008>`_).
724727

725728
Bug Fixes to Compiler Builtins
726729
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaInit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,7 @@ static void warnBracedScalarInit(Sema &S, const InitializedEntity &Entity,
11521152
case InitializedEntity::EK_Parameter_CF_Audited:
11531153
case InitializedEntity::EK_TemplateParameter:
11541154
case InitializedEntity::EK_Result:
1155+
case InitializedEntity::EK_ParenAggInitMember:
11551156
// Extra braces here are suspicious.
11561157
DiagID = diag::warn_braces_around_init;
11571158
break;
@@ -1186,7 +1187,6 @@ static void warnBracedScalarInit(Sema &S, const InitializedEntity &Entity,
11861187
case InitializedEntity::EK_LambdaToBlockConversionBlockElement:
11871188
case InitializedEntity::EK_Binding:
11881189
case InitializedEntity::EK_StmtExprResult:
1189-
case InitializedEntity::EK_ParenAggInitMember:
11901190
llvm_unreachable("unexpected braced scalar init");
11911191
}
11921192

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)