History

instruduce C2x _Static_assert syntaxe

matthias committed 6 years ago

Commit 704b6021 parent cb041f13 files · +25 −9Browse files

Unified · Split

3 files
  1. tccgen.c +9 −0
  2. tests/tests2/60_errors_and_warnings.c +4 −0
  3. tests/tests2/60_errors_and_warnings.expect +12 −9
tccgen.c+9−0
@@ -7818,12 +7818,21 @@ static int decl0(int l, int is_for_loop_init, Sym *func_sym) · 7817 unmodified lines
78187818 next();
78197819 skip('(');
78207820 c = expr_const();
7821+
7822+ if (tok == ')') {
7823+ if (!c)
7824+ tcc_error("_Static_assert fail");
7825+ next();
7826+ goto static_assert_out;
7827+ }
7828+
78217829 skip(',');
78227830 parse_mult_str(&error_str, "string constant");
78237831 if (c == 0)
78247832 tcc_error("%s", error_str.data);
78257833 cstr_free(&error_str);
78267834 skip(')');
7835+ static_assert_out:
78277836 skip(';');
78287837 continue;
78297838 }
tests/tests2/60_errors_and_warnings.c+4−0
@@ -190,6 +190,10 @@ void * _Alignas(16) p1; · 189 unmodified lines
190190 _Static_assert(1, "1"" is 1");
191191 _Static_assert(0, "0"" is 0");
192192
193+#elif defined test_static_assert_c2x
194+ _Static_assert(1);
195+ _Static_assert(0);
196+
193197 #elif defined test_void_array
194198 void t[3];
195199
tests/tests2/60_errors_and_warnings.expect+12−9
@@ -94,22 +94,25 @@ · 93 unmodified lines
9494 [test_static_assert_2]
9595 60_errors_and_warnings.c:191: error: 0 is 0
9696
97+[test_static_assert_c2x]
98+60_errors_and_warnings.c:195: error: _Static_assert fail
99+
97100 [test_void_array]
98−60_errors_and_warnings.c:194: error: declaration of an array of incomplete type elements
101+60_errors_and_warnings.c:198: error: declaration of an array of incomplete type elements
99102
100103 [test_incomplete_enum_array]
101−60_errors_and_warnings.c:197: error: declaration of an array of incomplete type elements
104+60_errors_and_warnings.c:201: error: declaration of an array of incomplete type elements
102105
103106 [test_incomplete_struct_array]
104−60_errors_and_warnings.c:200: error: declaration of an array of incomplete type elements
107+60_errors_and_warnings.c:204: error: declaration of an array of incomplete type elements
105108
106109 [test_const_fun_array]
107−60_errors_and_warnings.c:204: error: declaration of an array of functions
110+60_errors_and_warnings.c:208: error: declaration of an array of functions
108111
109112 [test_incomplete_array_array]
110113
111114 [test_extern_array]
112−60_errors_and_warnings.c:220: error: incompatible types for redefinition of 'x'
115+60_errors_and_warnings.c:224: error: incompatible types for redefinition of 'x'
113116
114117 [test_func_1]
115118 hello: a = 123
@@ -118,17 +121,17 @@ hello: a = 123 · 2 unmodified lines
118121 hello: a = 123
119122
120123 [test_func_3]
121−60_errors_and_warnings.c:250: warning: static storage ignored for redefinition of 'hello'
124+60_errors_and_warnings.c:254: warning: static storage ignored for redefinition of 'hello'
122125 hello: a = 123
123126
124127 [test_func_4]
125128 hello: a = 123
126129
127130 [test_func_5]
128−60_errors_and_warnings.c:250: error: incompatible types for redefinition of 'hello'
131+60_errors_and_warnings.c:254: error: incompatible types for redefinition of 'hello'
129132
130133 [test_func_6]
131−60_errors_and_warnings.c:238: error: function without file scope cannot be static
134+60_errors_and_warnings.c:242: error: function without file scope cannot be static
132135
133136 [test_var_1]
134137 main : 1 ; 1
@@ -141,6 +144,6 @@ main : 2 ; 2 · 6 unmodified lines
141144 bar : 3 ; 3
142145
143146 [test_var_3]
144−60_errors_and_warnings.c:282: error: incompatible types for redefinition of 'xxx'
147+60_errors_and_warnings.c:286: error: incompatible types for redefinition of 'xxx'
145148
146149 [test_var_4]

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t