Patch for c/13801
Joseph S. Myers
jsm@polyomino.org.uk
Tue Aug 3 19:02:00 GMT 2004
On Mon, 2 Aug 2004, Zack Weinberg wrote:
> > There are also some extra diagnostics for incompatible implicit
> > function declarations as part of making implicit function declarations
> > work properly if the previous declaration is out of scope. For
> > discussion of that for incompatibly implicitly declaring a built-in
> > function, see <http://gcc.gnu.org/ml/gcc/2004-08/msg00021.html>.
>
> Submit this change separately. With regard to the incompatible
> declarations of built-ins, I agree with Geoff, and I'd add that you
> should not diagnose incompatible redeclarations of built-ins that are
> not covered by the currently selected standard.
Here is the provisional separate patch to add the warnings / errors
for incompatible implicit function declarations.
I have made no changes regarding built-in functions not in the current
standard, i.e. redeclaring them gets the mandatory warning. Apart
from the question as to which function the user wants, for which such
a diagnostic seems entirely appropriate, this is consistent with the
warnings for (for example)
int imaxabs;
(declaring such explicitly as a different type of symbol), and
DECL_BUILT_IN_NONANSI (which allowed different types of built-in
functions to be distinguished) was removed some time ago.
Bootstrapped with no regressions on i686-pc-linux-gnu.
--
Joseph S. Myers http://www.srcf.ucam.org/~jsm28/gcc/
jsm@polyomino.org.uk (personal mail)
jsm28@gcc.gnu.org (Bugzilla assignments and CCs)
2004-08-03 Joseph S. Myers <jsm@polyomino.org.uk>
* c-decl.c (implicitly_declare): Diagnose incompatible implicit
declarations.
testsuite:
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.
diff -rupN GCC.orig/gcc/c-decl.c GCC.mid/gcc/c-decl.c
--- GCC.orig/gcc/c-decl.c 2004-07-31 17:18:48.000000000 +0000
+++ GCC.mid/gcc/c-decl.c 2004-08-03 08:53:42.000000000 +0000
@@ -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 -rupN GCC.orig/gcc/testsuite/gcc.dg/format/attr-6.c GCC.mid/gcc/testsuite/gcc.dg/format/attr-6.c
--- GCC.orig/gcc/testsuite/gcc.dg/format/attr-6.c 2001-10-02 07:07:23.000000000 +0000
+++ GCC.mid/gcc/testsuite/gcc.dg/format/attr-6.c 2004-08-01 21:08:51.000000000 +0000
@@ -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 -rupN GCC.orig/gcc/testsuite/gcc.dg/redecl-5.c GCC.mid/gcc/testsuite/gcc.dg/redecl-5.c
--- GCC.orig/gcc/testsuite/gcc.dg/redecl-5.c 1970-01-01 00:00:00.000000000 +0000
+++ GCC.mid/gcc/testsuite/gcc.dg/redecl-5.c 2004-08-01 20:36:26.000000000 +0000
@@ -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" } */
+}
More information about the Gcc-patches
mailing list