diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index b893d358dfe79..6db211a20e311 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -9387,10 +9387,13 @@ ExprResult InitializationSequence::Perform(Sema &S, } } + Expr *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 @@ ExprResult InitializationSequence::Perform(Sema &S, 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 index 042ce3b3ddce2..88d9b95c0e4be 100644 --- a/clang/test/SemaCXX/paren-list-agg-init.cpp +++ b/clang/test/SemaCXX/paren-list-agg-init.cpp @@ -272,3 +272,25 @@ 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}} } + + +namespace GH63278 { +struct S { + int a = 0; + int b {0}; + auto x = 1; // expected-error {{'auto' not allowed in non-static struct member}} + static const auto y = 1; +}; + +int test() { + // used to crash + S a(0, 1); + S b(0); + S c(0, 0, 1); // beforecxx20-warning {{aggregate initialization of type 'S' from a parenthesized list of values is a C++20 extension}} + + S d {0, 1}; + S e {0}; + S f {0, 0, 1}; +} + +}