mirror of
https://github.com/mirror/tinycc.git
synced 2025-02-12 07:00:07 +08:00
improve _Static_assert
Fix static assert to support literal string instead of just printing the sring of the current token as it use to be so we can now use _Static_assert(0, "0" "1") which will print __FILE__ __LINE__ error: 01
This commit is contained in:
parent
e050ae845e
commit
cb041f11f6
6
tccgen.c
6
tccgen.c
@ -7812,15 +7812,17 @@ static int decl0(int l, int is_for_loop_init, Sym *func_sym)
|
|||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (tok == TOK_STATIC_ASSERT) {
|
if (tok == TOK_STATIC_ASSERT) {
|
||||||
|
CString error_str;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
next();
|
next();
|
||||||
skip('(');
|
skip('(');
|
||||||
c = expr_const();
|
c = expr_const();
|
||||||
skip(',');
|
skip(',');
|
||||||
|
parse_mult_str(&error_str, "string constant");
|
||||||
if (c == 0)
|
if (c == 0)
|
||||||
tcc_error("%s", get_tok_str(tok, &tokc));
|
tcc_error("%s", error_str.data);
|
||||||
next();
|
cstr_free(&error_str);
|
||||||
skip(')');
|
skip(')');
|
||||||
skip(';');
|
skip(';');
|
||||||
continue;
|
continue;
|
||||||
|
@ -186,6 +186,10 @@ void * _Alignas(16) p1;
|
|||||||
_Static_assert(ONE == 0, "don't show me this");
|
_Static_assert(ONE == 0, "don't show me this");
|
||||||
_Static_assert(ONE == 1, "ONE is not 1");
|
_Static_assert(ONE == 1, "ONE is not 1");
|
||||||
|
|
||||||
|
#elif defined test_static_assert_2
|
||||||
|
_Static_assert(1, "1"" is 1");
|
||||||
|
_Static_assert(0, "0"" is 0");
|
||||||
|
|
||||||
#elif defined test_void_array
|
#elif defined test_void_array
|
||||||
void t[3];
|
void t[3];
|
||||||
|
|
||||||
|
@ -89,24 +89,27 @@
|
|||||||
60_errors_and_warnings.c:181: error: identifier expected
|
60_errors_and_warnings.c:181: error: identifier expected
|
||||||
|
|
||||||
[test_static_assert]
|
[test_static_assert]
|
||||||
60_errors_and_warnings.c:187: error: "ONE is not 1"
|
60_errors_and_warnings.c:187: error: ONE is not 1
|
||||||
|
|
||||||
|
[test_static_assert_2]
|
||||||
|
60_errors_and_warnings.c:191: error: 0 is 0
|
||||||
|
|
||||||
[test_void_array]
|
[test_void_array]
|
||||||
60_errors_and_warnings.c:190: error: declaration of an array of incomplete type elements
|
60_errors_and_warnings.c:194: error: declaration of an array of incomplete type elements
|
||||||
|
|
||||||
[test_incomplete_enum_array]
|
[test_incomplete_enum_array]
|
||||||
60_errors_and_warnings.c:193: error: declaration of an array of incomplete type elements
|
60_errors_and_warnings.c:197: error: declaration of an array of incomplete type elements
|
||||||
|
|
||||||
[test_incomplete_struct_array]
|
[test_incomplete_struct_array]
|
||||||
60_errors_and_warnings.c:196: error: declaration of an array of incomplete type elements
|
60_errors_and_warnings.c:200: error: declaration of an array of incomplete type elements
|
||||||
|
|
||||||
[test_const_fun_array]
|
[test_const_fun_array]
|
||||||
60_errors_and_warnings.c:200: error: declaration of an array of functions
|
60_errors_and_warnings.c:204: error: declaration of an array of functions
|
||||||
|
|
||||||
[test_incomplete_array_array]
|
[test_incomplete_array_array]
|
||||||
|
|
||||||
[test_extern_array]
|
[test_extern_array]
|
||||||
60_errors_and_warnings.c:216: error: incompatible types for redefinition of 'x'
|
60_errors_and_warnings.c:220: error: incompatible types for redefinition of 'x'
|
||||||
|
|
||||||
[test_func_1]
|
[test_func_1]
|
||||||
hello: a = 123
|
hello: a = 123
|
||||||
@ -115,17 +118,17 @@ hello: a = 123
|
|||||||
hello: a = 123
|
hello: a = 123
|
||||||
|
|
||||||
[test_func_3]
|
[test_func_3]
|
||||||
60_errors_and_warnings.c:246: warning: static storage ignored for redefinition of 'hello'
|
60_errors_and_warnings.c:250: warning: static storage ignored for redefinition of 'hello'
|
||||||
hello: a = 123
|
hello: a = 123
|
||||||
|
|
||||||
[test_func_4]
|
[test_func_4]
|
||||||
hello: a = 123
|
hello: a = 123
|
||||||
|
|
||||||
[test_func_5]
|
[test_func_5]
|
||||||
60_errors_and_warnings.c:246: error: incompatible types for redefinition of 'hello'
|
60_errors_and_warnings.c:250: error: incompatible types for redefinition of 'hello'
|
||||||
|
|
||||||
[test_func_6]
|
[test_func_6]
|
||||||
60_errors_and_warnings.c:234: error: function without file scope cannot be static
|
60_errors_and_warnings.c:238: error: function without file scope cannot be static
|
||||||
|
|
||||||
[test_var_1]
|
[test_var_1]
|
||||||
main : 1 ; 1
|
main : 1 ; 1
|
||||||
@ -138,6 +141,6 @@ main : 2 ; 2
|
|||||||
bar : 3 ; 3
|
bar : 3 ; 3
|
||||||
|
|
||||||
[test_var_3]
|
[test_var_3]
|
||||||
60_errors_and_warnings.c:278: error: incompatible types for redefinition of 'xxx'
|
60_errors_and_warnings.c:282: error: incompatible types for redefinition of 'xxx'
|
||||||
|
|
||||||
[test_var_4]
|
[test_var_4]
|
||||||
|
Loading…
Reference in New Issue
Block a user