aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorDale Johannesen <dalej@apple.com>2004-12-17 20:05:34 +0000
committerDale Johannesen <dalej@gcc.gnu.org>2004-12-17 20:05:34 +0000
commit128691426dcb9e2a3cb57c89bc863d03c1009d82 (patch)
treecc6ac8b5b4b86542f8bc16178aa7879397343679 /gcc
parent5429f07f64ebd4b8963489711e2426cc4ab036fc (diff)
downloadgcc-128691426dcb9e2a3cb57c89bc863d03c1009d82.zip
gcc-128691426dcb9e2a3cb57c89bc863d03c1009d82.tar.gz
gcc-128691426dcb9e2a3cb57c89bc863d03c1009d82.tar.bz2
c-decl.c (diagnose_mismatched_decls): Accept mismatched function types: void with previous implicit int.
2004-12-17 Dale Johannesen <dalej@apple.com> * c-decl.c (diagnose_mismatched_decls): Accept mismatched function types: void with previous implicit int. From-SVN: r92329
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/c-decl.c14
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/20041213-1.c32
4 files changed, 54 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 3a80aba..50a1432 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2004-12-17 Dale Johannesen <dalej@apple.com>
+
+ * c-decl.c (diagnose_mismatched_decls): Accept mismatched
+ function types: void with previous implicit int.
+
2004-12-17 Andreas Krebbel <krebbel1@de.ibm.com>
* 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 ea26da4..b728a6b 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 ee52120..6dbca4a 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2004-12-17 Dale Johannesen <dalej@apple.com>
+
+ * gcc.dg/20041213-1.c: New.
+
2004-12-17 Ziemowit Laski <zlaski@apple.com>
* 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 0000000..9902737
--- /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" } */
+