[clang-cl] Ignore /Wv and /Wv:17 flags
[llvm-project.git] / clang / test / SemaCXX / designated-initializers.cpp
bloba897e5a4e544c4cea03f5c8051543e9e5eb0d2f0
1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -Wno-reorder -Wno-c99-designator -Winitializer-overrides %s
2 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -Wno-reorder -Wno-c99-designator -Woverride-init %s
4 template <typename T> struct Foo {
5 struct SubFoo {
6 int bar1;
7 int bar2;
8 };
10 static void Test() { SubFoo sf = {.bar1 = 10, .bar2 = 20}; } // Expected no warning
13 void foo() {
14 Foo<int>::Test();
15 Foo<bool>::Test();
16 Foo<float>::Test();
19 template <typename T> struct Bar {
20 struct SubFoo {
21 int bar1;
22 int bar2;
25 static void Test() { SubFoo sf = {.bar1 = 10, // expected-note 2 {{previous initialization is here}}
26 .bar1 = 20}; } // expected-warning 2 {{initializer overrides prior initialization of this subobject}}
29 void bar() {
30 Bar<int>::Test(); // expected-note {{in instantiation of member function 'Bar<int>::Test' requested here}}
31 Bar<bool>::Test(); // expected-note {{in instantiation of member function 'Bar<bool>::Test' requested here}}
34 namespace Reorder {
35 struct X {
36 X(int n);
37 private:
38 int i;
41 struct foo {
42 X x;
43 X y;
46 foo n = {.y = 4, .x = 5};
47 X arr[2] = {[1] = 1, [0] = 2};
50 namespace Reorder2 {
51 struct S {
52 S();
53 S(const S &);
54 ~S();
57 struct EF {
58 S s;
61 struct PN {
62 PN(const PN &);
64 extern PN pn;
66 struct FLN {
67 EF ef;
68 int it;
69 PN pn;
72 void f() {
73 FLN new_elem = {
74 .ef = EF(),
75 .pn = pn,
76 .it = 0,
81 namespace Reorder3 {
82 struct S {
83 int a, &b, &c; // expected-note 2{{here}}
85 S s1 = {
86 .a = 1, .c = s1.a, .b = s1.a
88 S s2 = {
89 .a = 1, .c = s2.a
90 }; // expected-error {{uninitialized}}
91 S s3 = {
92 .b = s3.a, .a = 1,
93 }; // expected-error {{uninitialized}}
96 // Check that we don't even think about whether holes in a designated
97 // initializer are zero-initializable if the holes are filled later.
98 namespace NoCheckingFilledHoles {
99 template<typename T> struct Error { using type = typename T::type; }; // expected-error 3{{'::'}}
101 template<int N>
102 struct DefaultInitIsError {
103 DefaultInitIsError(Error<int[N]> = {}); // expected-note 3{{instantiation}} expected-note 3{{passing}}
104 DefaultInitIsError(int, int);
107 template<int N>
108 struct X {
109 int a;
110 DefaultInitIsError<N> e;
111 int b;
113 X<1> x1 = {
114 .b = 2,
115 .a = 1,
116 {4, 4}
118 X<2> x2 = {
119 .e = {4, 4},
120 .b = 2,
121 .a = 1
123 X<3> x3 = {
124 .b = 2,
125 .a = 1
126 }; // expected-note {{default function argument}}
127 X<4> x4 = {
128 .a = 1,
129 .b = 2
130 }; // expected-note {{default function argument}}
131 X<5> x5 = {
132 .e = {4, 4},
133 .a = 1,
134 .b = 2
136 X<6> x6 = {
137 .a = 1,
138 .b = 2,
139 .e = {4, 4}
142 template<int N> struct Y { X<N> x; };
143 Y<7> y7 = {
144 .x = {.a = 1, .b = 2}, // expected-note {{default function argument}}
145 .x.e = {3, 4}
147 Y<8> y8 = {
148 .x = {.e = {3, 4}},
149 .x.a = 1,
150 .x.b = 2
154 namespace LargeArrayDesignator {
155 struct X {
156 int arr[1000000000];
158 struct Y {
159 int arr[3];
161 void f(X x);
162 void f(Y y) = delete;
163 void g() {
164 f({.arr[4] = 1});
168 namespace ADL {
169 struct A {};
170 void f(A, int);
172 namespace X {
173 void f(A, int);
174 // OK. Would fail if checking {} against type A set the type of the
175 // initializer list to A, because ADL would find ADL::f, resulting in
176 // ambiguity.
177 void g() { f({}, {}); }