Skip to content

Commit

Permalink
[clang] Fix crash when passing a braced-init list to a parentehsized …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
alanzhao1 authored and tstellar committed Jun 1, 2023
1 parent 42f2e6e commit 185b81e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,9 @@ Bug Fixes in This Version
- Fix crash when handling nested immediate invocations in initializers of global
variables.
(`#58207 <https://github.com/llvm/llvm-project/issues/58207>`_)
- Fix crash when passing a braced initializer list to a parentehsized aggregate
initialization expression.
(`#63008 <https://github.com/llvm/llvm-project/issues/63008>`_).

Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,7 @@ static void warnBracedScalarInit(Sema &S, const InitializedEntity &Entity,
case InitializedEntity::EK_Parameter_CF_Audited:
case InitializedEntity::EK_TemplateParameter:
case InitializedEntity::EK_Result:
case InitializedEntity::EK_ParenAggInitMember:
// Extra braces here are suspicious.
DiagID = diag::warn_braces_around_init;
break;
Expand Down Expand Up @@ -1186,7 +1187,6 @@ static void warnBracedScalarInit(Sema &S, const InitializedEntity &Entity,
case InitializedEntity::EK_LambdaToBlockConversionBlockElement:
case InitializedEntity::EK_Binding:
case InitializedEntity::EK_StmtExprResult:
case InitializedEntity::EK_ParenAggInitMember:
llvm_unreachable("unexpected braced scalar init");
}

Expand Down
6 changes: 6 additions & 0 deletions clang/test/SemaCXX/paren-list-agg-init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,9 @@ O o2(0, 0); // no-error
O o3(0);
// expected-error@-1 {{reference member of type 'int &&' uninitialized}}
}

namespace gh63008 {
auto a = new A('a', {1.1});
// expected-warning@-1 {{braces around scalar init}}
// beforecxx20-warning@-2 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
}

0 comments on commit 185b81e

Please sign in to comment.