diff --git a/tccgen.c b/tccgen.c index 739670c8..31c4f472 100644 --- a/tccgen.c +++ b/tccgen.c @@ -3695,6 +3695,12 @@ again: df = is_float(dbt); dbt_bt = dbt & VT_BTYPE; sbt_bt = sbt & VT_BTYPE; + if (dbt_bt == VT_VOID) + goto done; + if (sbt_bt == VT_VOID) { +error: + cast_error(&vtop->type, type); + } c = (vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST; #if !defined TCC_IS_NATIVE && !defined TCC_IS_NATIVE_387 @@ -3791,11 +3797,9 @@ again: ds = btype_size(dbt_bt); ss = btype_size(sbt_bt); - if (ds == 0 || ss == 0) { - if (dbt_bt == VT_VOID) - goto done; - cast_error(&vtop->type, type); - } + if (ds == 0 || ss == 0) + goto error; + if (IS_ENUM(type->t) && type->ref->c < 0) tcc_error("cast to incomplete type"); diff --git a/tests/tests2/60_errors_and_warnings.c b/tests/tests2/60_errors_and_warnings.c index 29c302ba..5024ac70 100644 --- a/tests/tests2/60_errors_and_warnings.c +++ b/tests/tests2/60_errors_and_warnings.c @@ -394,4 +394,9 @@ struct S2 { #elif defined test_conflicting_array_definition extern int array[2]; int array[] = { 1, 2, 3 }; + +#elif defined test_cast_from_void +void v() {} +int f() { return v(); } + #endif diff --git a/tests/tests2/60_errors_and_warnings.expect b/tests/tests2/60_errors_and_warnings.expect index fb39cc21..96bed534 100644 --- a/tests/tests2/60_errors_and_warnings.expect +++ b/tests/tests2/60_errors_and_warnings.expect @@ -186,3 +186,6 @@ bar : 3 ; 3 [test_conflicting_array_definition] 60_errors_and_warnings.c:396: error: incompatible types for redefinition of 'array' + +[test_cast_from_void] +60_errors_and_warnings.c:400: error: cannot convert 'void' to 'int'