Skip to content

Commit 1c91733

Browse files
committed
Fix highlighting issue with _complex and initialization list with more than 2 items
Fixes llvm#61518 Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D146503
1 parent 805f51f commit 1c91733

File tree

4 files changed

+56
-5
lines changed

4 files changed

+56
-5
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ Bug Fixes in This Version
225225
enabling short-circuiting coroutines use cases. This fixes
226226
(`#56532 <https://github.com/llvm/llvm-project/issues/56532>`_) in
227227
antecipation of `CWG2563 <https://cplusplus.github.io/CWG/issues/2563.html>_`.
228+
- Fix highlighting issue with ``_Complex`` and initialization list with more than
229+
2 items. (`#61518 <https://github.com/llvm/llvm-project/issues/61518>`_)
228230

229231
Bug Fixes to Compiler Builtins
230232
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaInit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,7 @@ void InitListChecker::CheckComplexType(const InitializedEntity &Entity,
15361536
// the element type of the complex type. The first element initializes
15371537
// the real part, and the second element intitializes the imaginary part.
15381538

1539-
if (IList->getNumInits() != 2)
1539+
if (IList->getNumInits() < 2)
15401540
return CheckScalarType(Entity, IList, DeclType, Index, StructuredList,
15411541
StructuredIndex);
15421542

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// RUN: not %clang_cc1 -std=c++11 -fsyntax-only -fcaret-diagnostics-max-lines 5 %s 2>&1 | FileCheck %s -strict-whitespace
2+
3+
4+
//CHECK: {{.*}}: error: excess elements in scalar initializer
5+
//CHECK-NEXT: {{^}}_Complex double gz1 = {1, 2, 3};
6+
//CHECK-NEXT: {{^}} ^{{$}}
7+
_Complex double gz1 = {1, 2, 3};
8+
9+
//CHECK: {{.*}}: error: excess elements in scalar initializer
10+
//CHECK-NEXT: {{^}}_Complex double dd = {1.0, 2.0, 3.0};
11+
//CHECK-NEXT: {{^}} ^~~{{$}}
12+
_Complex double dd = {1.0, 2.0, 3.0};
13+
14+
//CHECK: {{.*}}: error: excess elements in scalar initializer
15+
//CHECK-NEXT: {{^}}_Complex float fd = {1.0, 2.0, 3.0, 4.0, 5.0};
16+
//CHECK-NEXT: {{^}} ^~~{{$}}
17+
_Complex float fd = {1.0, 2.0, 3.0, 4.0, 5.0};
18+
19+
//CHECK: {{.*}}: error: no viable conversion from 'foo' to 'double'
20+
//CHECK-NEXT: {{^}}_Complex double ds = {f, 1.0, b};
21+
//CHECK-NEXT: {{^}} ^{{$}}
22+
struct foo{};
23+
struct bar{};
24+
25+
foo f;
26+
bar b;
27+
_Complex double ds = {f, 1.0, b};
28+
29+
//CHECK: {{.*}}: error: no viable conversion from 'foo' to 'double'
30+
//CHECK-NEXT: {{^}}_Complex double fg = {1.0, f};
31+
//CHECK-NEXT: {{^}} ^{{$}}
32+
_Complex double fg = {1.0, f};
33+
34+
35+
//CHECK: {{.*}}: error: excess elements in scalar initializer
36+
//CHECK-NEXT: {{^}}_Complex double gg = {1.0, 2.0, f};
37+
//CHECK-NEXT: {{^}} ^{{$}}
38+
//CHECK-NEXT: {{^}}6 errors generated.
39+
_Complex double gg = {1.0, 2.0, f};

clang/test/Sema/complex-init-list.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,21 @@ struct teststruct { _Complex float x; };
2525

2626

2727
// Random other valid stuff
28-
_Complex int valid2 = { 1, 2 }; // expected-warning {{complex integer}} expected-warning {{specifying real and imaginary components is an extension}}
28+
_Complex int valid2 = { 1, 2 }; // expected-warning {{complex integer}} \
29+
// expected-warning {{specifying real and imaginary components is an extension}}
2930
struct teststruct valid3 = { { 1.0f, 2.0f} }; // expected-warning {{specifying real and imaginary components is an extension}}
3031
_Complex float valid4[2] = { {1.0f, 1.0f}, {1.0f, 1.0f} }; // expected-warning 2 {{specifying real and imaginary components is an extension}}
3132
// FIXME: We need some sort of warning for valid5
32-
_Complex float valid5 = {1.0f, 1.0fi}; // expected-warning {{imaginary constants}} expected-warning {{specifying real and imaginary components is an extension}}
33+
_Complex float valid5 = {1.0f, 1.0fi}; // expected-warning {{imaginary constants}} \
34+
// expected-warning {{specifying real and imaginary components is an extension}}
3335

3436

3537
// Random invalid stuff
3638
struct teststruct invalid1 = { 1, 2 }; // expected-warning {{excess elements}}
37-
_Complex float invalid2 = { 1, 2, 3 }; // expected-warning {{excess elements}}
38-
_Complex float invalid3 = {}; // expected-error {{scalar initializer cannot be empty}} expected-warning {{GNU empty initializer}}
39+
_Complex float invalid2 = { 1, 2, 3 }; // expected-warning {{specifying real and imaginary components is an extension}} \
40+
// expected-warning {{excess elements in scalar initializer}}
41+
_Complex float invalid3 = {}; // expected-error {{scalar initializer cannot be empty}} \
42+
// expected-warning {{GNU empty initializer}}
3943

4044

4145
// Check incomplete array sizing
@@ -46,3 +50,9 @@ _Complex float sizecheck2[(sizeof(sizetest2) == sizeof(*sizetest2)*3) ? 1 : -1];
4650

4751
// Constant-folding with init list.
4852
_Complex float x = 2 + (_Complex float) { 1, 2 }; // expected-warning {{specifying real and imaginary components is an extension}}
53+
54+
// initialization list
55+
_Complex double cd = {1.0, 2.0, 3.0}; // expected-warning {{specifying real and imaginary components is an extension}} \
56+
// expected-warning {{excess elements in scalar initializer}}
57+
_Complex float cf = {1.1f, 2.2f, 3.3f, 4.4f}; // expected-warning {{specifying real and imaginary components is an extension}} \
58+
// expected-warning {{excess elements in scalar initializer}}

0 commit comments

Comments
 (0)