@@ -8517,7 +8517,7 @@ static int decl(int l)
85178517{
85188518 int v , has_init , r , oldint ;
85198519 CType type , btype ;
8520- Sym * sym ;
8520+ Sym * sym , * s ;
85218521 AttributeDef ad , adbase ;
85228522 ElfSym * esym ;
85238523
@@ -8589,6 +8589,21 @@ static int decl(int l)
85898589 if (sym -> f .func_type == FUNC_OLD && l == VT_CONST ) {
85908590 func_vt = type ;
85918591 decl (VT_CMP );
8592+
8593+ /* Allow mixing old/new prototypes
8594+ * void func(float a);
8595+ * int main(void) { func(1.0); }
8596+ * void func(a) float a; { printf("%g\n", a); }
8597+ */
8598+ s = sym_find (v );
8599+ if (type .ref -> next && // skip old func(); definitions
8600+ s && s -> type .ref &&
8601+ s -> type .ref -> f .func_type == FUNC_NEW ) {
8602+ sym -> f .func_type = FUNC_NEW ;
8603+ if (!is_compatible_types (& s -> type , & type ))
8604+ tcc_error ("incompatible redefinition of '%s'" ,
8605+ get_tok_str (v , NULL ));
8606+ }
85928607 }
85938608
85948609 if ((type .t & (VT_EXTERN |VT_INLINE )) == (VT_EXTERN |VT_INLINE )) {
@@ -8646,6 +8661,9 @@ static int decl(int l)
86468661 while ((sym = sym -> next ) != NULL ) {
86478662 if (!(sym -> v & ~SYM_FIELD ))
86488663 expect ("identifier" );
8664+ if (type .ref -> f .func_type == FUNC_OLD &&
8665+ sym -> type .t == VT_FLOAT )
8666+ sym -> type .t = VT_DOUBLE ;
86498667 if (sym -> type .t == VT_VOID )
86508668 sym -> type = int_type ;
86518669 }
@@ -8693,9 +8711,6 @@ static int decl(int l)
86938711 if (sym -> type .t != VT_VOID )
86948712 tcc_error ("redefinition of parameter '%s'" ,
86958713 get_tok_str (v , NULL ));
8696- if (func_vt .ref -> f .func_type == FUNC_OLD &&
8697- type .t == VT_FLOAT )
8698- type .t = VT_DOUBLE ;
86998714 convert_parameter_type (& type );
87008715 sym -> type = type ;
87018716 } else if (type .t & VT_TYPEDEF ) {
0 commit comments