summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2004-08-03 22:09:13 +0000
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2004-08-03 22:09:13 +0000
commit0568d4eade0cb7402f52c74a7a05cbf8f385dd59 (patch)
treea534cd9d6e051f107ee4ae8faa1e824cf9bddaeb
parent709ab98be441b552508cd81c0baca69f7631b118 (diff)
downloadgcc-0568d4eade0cb7402f52c74a7a05cbf8f385dd59.tar.gz
* c-decl.c (implicitly_declare): Diagnose incompatible implicit
declarations. testsuite: * gcc.dg/redecl-5.c: New test. * gcc.dg/format/attr-6.c: Expect warning for implicit declaration of scanf. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@85509 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/c-decl.c17
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gcc.dg/format/attr-6.c1
-rw-r--r--gcc/testsuite/gcc.dg/redecl-5.c19
5 files changed, 48 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 16eacafeeff..14c2b37a537 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2004-08-03 Joseph S. Myers <jsm@polyomino.org.uk>
+
+ * c-decl.c (implicitly_declare): Diagnose incompatible implicit
+ declarations.
+
2004-08-03 Mike Stump <mrs@apple.com>
* config/darwin-c.c: Don't search in "/Local/Library/Frameworks"
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index 27860b4bd29..cbdafbb48e1 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -2082,6 +2082,23 @@ implicitly_declare (tree functionid)
implicit_decl_warning (functionid, decl);
C_DECL_IMPLICIT (decl) = 1;
}
+ if (DECL_BUILT_IN (decl))
+ {
+ if (!comptypes (default_function_type, TREE_TYPE (decl)))
+ {
+ warning ("incompatible implicit declaration of built-in"
+ " function %qD", decl);
+ }
+ }
+ else
+ {
+ if (!comptypes (default_function_type, TREE_TYPE (decl)))
+ {
+ error ("incompatible implicit declaration of function %qD",
+ decl);
+ locate_old_decl (decl, error);
+ }
+ }
bind (functionid, decl, current_scope,
/*invisible=*/false, /*nested=*/true);
return decl;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index db11af67a72..f5d0e36b49d 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2004-08-03 Joseph S. Myers <jsm@polyomino.org.uk>
+
+ * gcc.dg/redecl-5.c: New test.
+ * gcc.dg/format/attr-6.c: Expect warning for implicit declaration
+ of scanf.
+
2004-08-03 Roger Sayle <roger@eyesopen.com>
PR middle-end/16790
diff --git a/gcc/testsuite/gcc.dg/format/attr-6.c b/gcc/testsuite/gcc.dg/format/attr-6.c
index 4e95cfb00f6..0f683223d78 100644
--- a/gcc/testsuite/gcc.dg/format/attr-6.c
+++ b/gcc/testsuite/gcc.dg/format/attr-6.c
@@ -18,4 +18,5 @@ void
foo (const char *s, int *p)
{
scanf("%ld", p); /* { dg-warning "format" "implicit scanf" } */
+ /* { dg-warning "implicit" "implicit decl warning" { target *-*-* } 20 } */
}
diff --git a/gcc/testsuite/gcc.dg/redecl-5.c b/gcc/testsuite/gcc.dg/redecl-5.c
new file mode 100644
index 00000000000..a689295bb85
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/redecl-5.c
@@ -0,0 +1,19 @@
+/* Test for multiple declarations and composite types. Diagnosis of
+ incompatible implicit declaration. */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=c89" } */
+
+void
+f (void)
+{
+ long z(); /* { dg-error "previous implicit declaration" } */
+}
+
+void
+g (void)
+{
+ z(); /* { dg-error "incompatible" } */
+ labs(1); /* { dg-warning "incompatible" } */
+ printf("x"); /* { dg-warning "incompatible" } */
+}