From 128691426dcb9e2a3cb57c89bc863d03c1009d82 Mon Sep 17 00:00:00 2001 From: Dale Johannesen Date: Fri, 17 Dec 2004 20:05:34 +0000 Subject: [PATCH] c-decl.c (diagnose_mismatched_decls): Accept mismatched function types: void with previous implicit int. 2004-12-17 Dale Johannesen * c-decl.c (diagnose_mismatched_decls): Accept mismatched function types: void with previous implicit int. From-SVN: r92329 --- gcc/ChangeLog | 5 +++++ gcc/c-decl.c | 14 +++++++++++++- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/20041213-1.c | 32 +++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/20041213-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3a80abab8aa..50a14327d99 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2004-12-17 Dale Johannesen + + * c-decl.c (diagnose_mismatched_decls): Accept mismatched + function types: void with previous implicit int. + 2004-12-17 Andreas Krebbel * config/s390/s390.c (s390_gimplify_va_arg): Set alias set to diff --git a/gcc/c-decl.c b/gcc/c-decl.c index ea26da44a3c..b728a6b3faa 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -1191,7 +1191,7 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl, else if (TREE_CODE (newdecl) == FUNCTION_DECL && DECL_INITIAL (newdecl) && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == void_type_node && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == integer_type_node - && C_FUNCTION_IMPLICIT_INT (newdecl)) + && C_FUNCTION_IMPLICIT_INT (newdecl) && !DECL_INITIAL (olddecl)) { pedwarn ("%Jconflicting types for %qD", newdecl, newdecl); /* Make sure we keep void as the return type. */ @@ -1199,6 +1199,18 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl, C_FUNCTION_IMPLICIT_INT (newdecl) = 0; pedwarned = true; } + /* Permit void foo (...) to match an earlier call to foo (...) with + no declared type (thus, implicitly int). */ + else if (TREE_CODE (newdecl) == FUNCTION_DECL + && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == void_type_node + && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == integer_type_node + && C_DECL_IMPLICIT (olddecl) && !DECL_INITIAL (olddecl)) + { + pedwarn ("%Jconflicting types for %qD", newdecl, newdecl); + /* Make sure we keep void as the return type. */ + TREE_TYPE (olddecl) = *oldtypep = oldtype = newtype; + pedwarned = true; + } else { if (TYPE_QUALS (newtype) != TYPE_QUALS (oldtype)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ee5212094b2..6dbca4ac5d6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2004-12-17 Dale Johannesen + + * gcc.dg/20041213-1.c: New. + 2004-12-17 Ziemowit Laski * objc.dg/stabs-1.m: Allow assembly label to begin diff --git a/gcc/testsuite/gcc.dg/20041213-1.c b/gcc/testsuite/gcc.dg/20041213-1.c new file mode 100644 index 00000000000..99027371447 --- /dev/null +++ b/gcc/testsuite/gcc.dg/20041213-1.c @@ -0,0 +1,32 @@ +/* { dg-do compile } */ +/* test redeclarations with void and implicit int */ +extern foo1(); /* { dg-error "error: previous declaration" } */ +extern void foo1(); /* { dg-error "error: conflicting types" } */ + +extern void foo2(); /* { dg-error "error: previous declaration" } */ +extern foo2(); /* { dg-error "error: conflicting types" } */ + +void foo3() {} /* { dg-error "error: previous definition" } */ +extern foo3(); /* { dg-error "error: conflicting types" } */ + +extern foo4(); /* { dg-error "error: previous declaration" } */ +void foo4() {} /* { dg-error "error: conflicting types" } */ + +extern void foo5(); /* { dg-warning "previous declaration" } */ +foo5() {} /* { dg-warning "conflicting types" } */ + +foo6() {} /* { dg-error "error: previous definition" } */ +extern void foo6(); /* { dg-error "error: conflicting types" } */ + +foo7() {} /* { dg-error "error: previous definition" } */ +void foo7() {} /* { dg-error "error: conflicting types" } */ + +void foo8() {} /* { dg-error "error: previous definition" } */ +foo8() {} /* { dg-error "error: conflicting types" } */ + +int use9() { foo9(); } /* { dg-warning "previous implicit declaration" } */ +extern void foo9(); /* { dg-warning "conflicting types" } */ + +int use10() { foo10(); } /* { dg-warning "previous implicit declaration" } */ +void foo10() {} /* { dg-warning "conflicting types" } */ + -- 2.30.2