diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -630,6 +630,8 @@ - Allow abstract parameter and return types in functions that are either deleted or not defined. (`#63012 `_) +- Fix a crash when trying to parentheses-initialize an invalid aggregate. + (`#63278 `_) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -9387,10 +9387,13 @@ } } + auto *Init = CurInit.get(); + if (!Init) + return ExprError(); + // Check whether the initializer has a shorter lifetime than the initialized // entity, and if not, either lifetime-extend or warn as appropriate. - if (auto *Init = CurInit.get()) - S.checkInitializerLifetime(Entity, Init); + S.checkInitializerLifetime(Entity, Init); // Diagnose non-fatal problems with the completed initialization. if (InitializedEntity::EntityKind EK = Entity.getKind(); @@ -9398,16 +9401,13 @@ EK == InitializedEntity::EK_ParenAggInitMember) && cast(Entity.getDecl())->isBitField()) S.CheckBitFieldInitialization(Kind.getLocation(), - cast(Entity.getDecl()), - CurInit.get()); + cast(Entity.getDecl()), Init); // Check for std::move on construction. - if (const Expr *E = CurInit.get()) { - CheckMoveOnConstruction(S, E, - Entity.getKind() == InitializedEntity::EK_Result); - } + CheckMoveOnConstruction(S, Init, + Entity.getKind() == InitializedEntity::EK_Result); - return CurInit; + return Init; } /// Somewhere within T there is an uninitialized reference subobject. diff --git a/clang/test/SemaCXX/paren-list-agg-init.cpp b/clang/test/SemaCXX/paren-list-agg-init.cpp --- a/clang/test/SemaCXX/paren-list-agg-init.cpp +++ b/clang/test/SemaCXX/paren-list-agg-init.cpp @@ -272,3 +272,24 @@ // 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}} } + + +namespace GH63278 { +struct S { + int a = 0; + int b {0}; + auto x = 1; // expected-error {{'auto' not allowed in non-static struct member}} +}; + +int test() { + // used to crash + S a(0, 1); + S b(0); + S c(0, 0, 1); + + S d {0, 1}; + S e {0}; + S f {0, 0, 1}; +} + +}