From 704b602184a50fc2999ed51f8e37c2db85cc9b41 Mon Sep 17 00:00:00 2001 From: matthias Date: Sat, 29 Feb 2020 01:55:11 +0100 Subject: [PATCH] instruduce C2x _Static_assert syntaxe --- tccgen.c | 9 +++++++++ tests/tests2/60_errors_and_warnings.c | 4 ++++ tests/tests2/60_errors_and_warnings.expect | 21 ++++++++++++--------- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/tccgen.c b/tccgen.c index cc1f092a..18fbd6b8 100644 --- a/tccgen.c +++ b/tccgen.c @@ -7818,12 +7818,21 @@ static int decl0(int l, int is_for_loop_init, Sym *func_sym) next(); skip('('); c = expr_const(); + + if (tok == ')') { + if (!c) + tcc_error("_Static_assert fail"); + next(); + goto static_assert_out; + } + skip(','); parse_mult_str(&error_str, "string constant"); if (c == 0) tcc_error("%s", error_str.data); cstr_free(&error_str); skip(')'); + static_assert_out: skip(';'); continue; } diff --git a/tests/tests2/60_errors_and_warnings.c b/tests/tests2/60_errors_and_warnings.c index 4456bb04..fcca6456 100644 --- a/tests/tests2/60_errors_and_warnings.c +++ b/tests/tests2/60_errors_and_warnings.c @@ -190,6 +190,10 @@ void * _Alignas(16) p1; _Static_assert(1, "1"" is 1"); _Static_assert(0, "0"" is 0"); +#elif defined test_static_assert_c2x + _Static_assert(1); + _Static_assert(0); + #elif defined test_void_array void t[3]; diff --git a/tests/tests2/60_errors_and_warnings.expect b/tests/tests2/60_errors_and_warnings.expect index 18075189..dca874b6 100644 --- a/tests/tests2/60_errors_and_warnings.expect +++ b/tests/tests2/60_errors_and_warnings.expect @@ -94,22 +94,25 @@ [test_static_assert_2] 60_errors_and_warnings.c:191: error: 0 is 0 +[test_static_assert_c2x] +60_errors_and_warnings.c:195: error: _Static_assert fail + [test_void_array] -60_errors_and_warnings.c:194: error: declaration of an array of incomplete type elements +60_errors_and_warnings.c:198: error: declaration of an array of incomplete type elements [test_incomplete_enum_array] -60_errors_and_warnings.c:197: error: declaration of an array of incomplete type elements +60_errors_and_warnings.c:201: error: declaration of an array of incomplete type elements [test_incomplete_struct_array] -60_errors_and_warnings.c:200: error: declaration of an array of incomplete type elements +60_errors_and_warnings.c:204: error: declaration of an array of incomplete type elements [test_const_fun_array] -60_errors_and_warnings.c:204: error: declaration of an array of functions +60_errors_and_warnings.c:208: error: declaration of an array of functions [test_incomplete_array_array] [test_extern_array] -60_errors_and_warnings.c:220: error: incompatible types for redefinition of 'x' +60_errors_and_warnings.c:224: error: incompatible types for redefinition of 'x' [test_func_1] hello: a = 123 @@ -118,17 +121,17 @@ hello: a = 123 hello: a = 123 [test_func_3] -60_errors_and_warnings.c:250: warning: static storage ignored for redefinition of 'hello' +60_errors_and_warnings.c:254: warning: static storage ignored for redefinition of 'hello' hello: a = 123 [test_func_4] hello: a = 123 [test_func_5] -60_errors_and_warnings.c:250: error: incompatible types for redefinition of 'hello' +60_errors_and_warnings.c:254: error: incompatible types for redefinition of 'hello' [test_func_6] -60_errors_and_warnings.c:238: error: function without file scope cannot be static +60_errors_and_warnings.c:242: error: function without file scope cannot be static [test_var_1] main : 1 ; 1 @@ -141,6 +144,6 @@ main : 2 ; 2 bar : 3 ; 3 [test_var_3] -60_errors_and_warnings.c:282: error: incompatible types for redefinition of 'xxx' +60_errors_and_warnings.c:286: error: incompatible types for redefinition of 'xxx' [test_var_4]