[PATCH] D146503: Fix highlighting issue with _complex and initialization list with more than 2 items

NagaChaitanya Vellanki via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 21 01:18:27 PDT 2023


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,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146503.506867.patch
Type: text/x-patch
Size: 1135 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230321/057b9b10/attachment.bin>


More information about the cfe-commits mailing list