chaitanyav created this revision. chaitanyav added a reviewer: tbaeder. Herald added a project: All. chaitanyav requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Fixes https://github.com/llvm/llvm-project/issues/61518 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D146503 Files: clang/lib/Sema/SemaInit.cpp clang/test/Sema/complex-init-list.c Index: clang/test/Sema/complex-init-list.c =================================================================== --- clang/test/Sema/complex-init-list.c +++ 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; }; Index: clang/lib/Sema/SemaInit.cpp =================================================================== --- clang/lib/Sema/SemaInit.cpp +++ 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,
Index: clang/test/Sema/complex-init-list.c =================================================================== --- clang/test/Sema/complex-init-list.c +++ 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; }; Index: clang/lib/Sema/SemaInit.cpp =================================================================== --- clang/lib/Sema/SemaInit.cpp +++ 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,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits