[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 12:46:10 PDT 2023
chaitanyav updated this revision to Diff 507090.
chaitanyav added a comment.
Only proceed with scalar initialization if number of elements is less than 2
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D146503/new/
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
@@ -34,7 +34,7 @@
// Random invalid stuff
struct teststruct invalid1 = { 1, 2 }; // expected-warning {{excess elements}}
-_Complex float invalid2 = { 1, 2, 3 }; // expected-warning {{excess elements}}
+_Complex float invalid2 = { 1, 2, 3 }; // expected-warning {{specifying real and imaginary components is an extension}} expected-warning {{excess elements in scalar initializer}}
_Complex float invalid3 = {}; // expected-error {{scalar initializer cannot be empty}} expected-warning {{GNU empty initializer}}
@@ -46,3 +46,7 @@
// Constant-folding with init list.
_Complex float x = 2 + (_Complex float) { 1, 2 }; // expected-warning {{specifying real and imaginary components is an extension}}
+
+// initialization list
+_Complex double cd = {1.0, 2.0, 3.0}; // expected-warning {{specifying real and imaginary components is an extension}} expected-warning {{excess elements in scalar initializer}}
+_Complex float cf = {1.1f, 2.2f, 3.3f, 4.4f}; // expected-warning {{specifying real and imaginary components is an extension}} expected-warning {{excess elements in scalar initializer}}
Index: clang/lib/Sema/SemaInit.cpp
===================================================================
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -1536,7 +1536,7 @@
// the element type of the complex type. The first element initializes
// the real part, and the second element intitializes the imaginary part.
- if (IList->getNumInits() != 2)
+ if (IList->getNumInits() < 2)
return CheckScalarType(Entity, IList, DeclType, Index, StructuredList,
StructuredIndex);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146503.507090.patch
Type: text/x-patch
Size: 1826 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230321/c0978a0a/attachment.bin>
More information about the cfe-commits
mailing list