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);
 


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);
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to