c-decl.c (implicitly_declare): Diagnose incompatible implicit declarations.
authorJoseph Myers <jsm@polyomino.org.uk>
Tue, 3 Aug 2004 22:09:13 +0000 (23:09 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Tue, 3 Aug 2004 22:09:13 +0000 (23:09 +0100)
* 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.

From-SVN: r85509

gcc/ChangeLog
gcc/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/format/attr-6.c
gcc/testsuite/gcc.dg/redecl-5.c [new file with mode: 0644]

index 16eacafeeff50003e01ad49f5610dc9478f5a3d4..14c2b37a537f49daa6b3718ed70d572d7aa4d722 100644 (file)
@@ -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"
index 27860b4bd29916171d89ec01e7bdaee3e1ffedfe..cbdafbb48e13325a2411cdf83a53a71ac67cd7ef 100644 (file)
@@ -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;
index db11af67a72182646b7026098b97d34a91b74031..f5d0e36b49db90489c99d683fcad2c1d91d485ca 100644 (file)
@@ -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
index 4e95cfb00f6ed8319166960a203c1abca04ff6f7..0f683223d783aa06b6d9c99d128cb1c309dd8e21 100644 (file)
@@ -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 (file)
index 0000000..a689295
--- /dev/null
@@ -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" } */
+}