You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Updates some undefined behavior during initialization to instead be a
8
+
* constraint violation.
9
+
*/
10
+
11
+
// The initializer for a scalar shall be a single expression, optionally
12
+
// enclosed in braces, or it shall be an empty initializer.
13
+
inti=12, j= {12}, k= {}; // ped-warning {{use of an empty initializer is a C23 extension}}
14
+
15
+
structS {
16
+
inti;
17
+
floatf;
18
+
int : 0;
19
+
charc;
20
+
};
21
+
22
+
voidtest1(void) {
23
+
// The initializer for an object that has structure or union type shall be
24
+
// either a single expression that has compatible type or a brace-enclosed
25
+
// list of initializers for the elements or named members.
26
+
structSs1= { 1, 1.2f, 'a' };
27
+
structSs2=s1;
28
+
29
+
// Despite being structurally identical to S, T is not compatible with S.
30
+
structT { inti; floatf; int : 0; charc; } t;
31
+
structSs3=t; // expected-error {{initializing 'struct S' with an expression of incompatible type 'struct T'}}
32
+
}
33
+
34
+
voidtest2(void) {
35
+
typedef__WCHAR_TYPE__wchar_t;
36
+
typedef__CHAR16_TYPE__char16_t;
37
+
typedef__CHAR32_TYPE__char32_t;
38
+
39
+
// The initializer for an array shall be either a string literal, optionally
40
+
// enclosed in braces, or a brace-enclosed list of initializers for the
41
+
// elements. An array initialized by character string literal or UTF-8 string
42
+
// literal shall have a character type as element type. An array initialized
43
+
// with a wide string literal shall have element type compatible with a
44
+
// qualified or unqualified wchar_t, char16_t, or char32_t, and the string
45
+
// literal shall have the corresponding encoding prefix (L, u, or U,
46
+
// respectively).
47
+
charstr1[] ="string literal";
48
+
charstr2[] = { "string literal" };
49
+
charstr3[] =u8"string literal";
50
+
charstr4[] = { u8"string literal" };
51
+
52
+
intstr5[] ="this doesn't work"; // expected-error {{array initializer must be an initializer list}}
53
+
intstr6[] = { "this also doesn't work" }; // expected-error {{incompatible pointer to integer conversion initializing 'int' with an expression of type 'char[23]'}}
wchar_tstr14[] = { "nope" }; // expected-error-re {{incompatible pointer to integer conversion initializing 'wchar_t' (aka '{{.*}}') with an expression of type 'char[5]'}}
char16_tstr16[] = { "nope" }; // expected-error-re {{incompatible pointer to integer conversion initializing 'char16_t' (aka '{{.*}}') with an expression of type 'char[5]'}}
char32_tstr18[] = { "nope" }; // expected-error-re {{incompatible pointer to integer conversion initializing 'char32_t' (aka '{{.*}}') with an expression of type 'char[5]'}}
0 commit comments