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 @@ -1633,7 +1633,11 @@ } } UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr); - ++Index; + + if (DeclType->isAnyComplexType() && IList->getNumInits() > 2) + Index = 2; + else + ++Index; } void InitListChecker::CheckReferenceType(const InitializedEntity &Entity, diff --git a/clang/test/Sema/complex-init-list.c b/clang/test/Sema/complex-init-list.c --- a/clang/test/Sema/complex-init-list.c +++ b/clang/test/Sema/complex-init-list.c @@ -19,6 +19,9 @@ // Basic testcase _Complex float valid1 = { 1.0f, 2.0f }; // expected-warning {{specifying real and imaginary components is an extension}} +// initialization list +_Complex double cd = {1.0, 2.0, 3.0}; // expected-warning {{excess elements in scalar initializer}} +_Complex float cf = {1.1f, 2.2f, 3.3f, 4.4f}; // expected-warning {{excess elements in scalar initializer}} // Struct for nesting tests struct teststruct { _Complex float x; };