diff --git a/tccgen.c b/tccgen.c index 1d1fe8a3..5e3373fc 100644 --- a/tccgen.c +++ b/tccgen.c @@ -7859,6 +7859,8 @@ static int decl0(int l, int is_for_loop_init, Sym *func_sym) } #endif if ((type.t & VT_BTYPE) == VT_FUNC) { + if ((type.t & VT_STATIC) && (l == VT_LOCAL)) + tcc_error("function without file scope cannot be static"); /* if old style function prototype, we accept a declaration list */ sym = type.ref; diff --git a/tests/tests2/60_errors_and_warnings.c b/tests/tests2/60_errors_and_warnings.c index 14ff527b..8bc2e5e2 100644 --- a/tests/tests2/60_errors_and_warnings.c +++ b/tests/tests2/60_errors_and_warnings.c @@ -216,14 +216,15 @@ int x[3]; || defined test_func_2 \ || defined test_func_3 \ || defined test_func_4 \ - || defined test_func_5 + || defined test_func_5 \ + || defined test_func_6 #if defined test_func_1 int hello(int); #elif defined test_func_4 static int hello(int); #endif int main () { -#if defined test_func_5 +#if defined test_func_6 static #endif int hello(int); diff --git a/tests/tests2/60_errors_and_warnings.expect b/tests/tests2/60_errors_and_warnings.expect index 93986d80..e8bf251d 100644 --- a/tests/tests2/60_errors_and_warnings.expect +++ b/tests/tests2/60_errors_and_warnings.expect @@ -111,14 +111,17 @@ hello: a = 123 hello: a = 123 [test_func_3] -60_errors_and_warnings.c:241: warning: static storage ignored for redefinition of 'hello' +60_errors_and_warnings.c:242: 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:241: error: incompatible types for redefinition of 'hello' +60_errors_and_warnings.c:242: error: incompatible types for redefinition of 'hello' + +[test_func_6] +60_errors_and_warnings.c:230: error: function without file scope cannot be static [test_var_1] main : 1 ; 1 @@ -131,6 +134,6 @@ main : 2 ; 2 bar : 3 ; 3 [test_var_3] -60_errors_and_warnings.c:273: error: incompatible types for redefinition of 'xxx' +60_errors_and_warnings.c:274: error: incompatible types for redefinition of 'xxx' [test_var_4]