mismatched decls w/ both builtin and explicit decl
diff mbox

Message ID 201311060451.rA64pCPq031840@greed.delorie.com
State New
Headers show

Commit Message

DJ Delorie Nov. 6, 2013, 4:51 a.m. UTC
Consider this source:

  extern char *index(const char *,int);
  static int index;

"index" is a builtin as well, but because it's a builtin gcc skips the
"previous declaration was here..." despite having *a* previous decl it
could complain about.  Note that newlib provides decls for many
builtins (the decl above is from newlib), so this could be a common
case.

So I added a check for !C_DECL_DECLARED_BUILTIN (decl) which seems to
specifically cover this case.  Ok to apply?

	* c-decl.c (locate_old_decl): If a previous conflicting decl is
	both explicit and builtin, print the location of the explicit one.

Comments

Joseph Myers Nov. 6, 2013, 12:41 p.m. UTC | #1
On Tue, 5 Nov 2013, DJ Delorie wrote:

> 
> Consider this source:
> 
>   extern char *index(const char *,int);
>   static int index;
> 
> "index" is a builtin as well, but because it's a builtin gcc skips the
> "previous declaration was here..." despite having *a* previous decl it
> could complain about.  Note that newlib provides decls for many
> builtins (the decl above is from newlib), so this could be a common
> case.
> 
> So I added a check for !C_DECL_DECLARED_BUILTIN (decl) which seems to
> specifically cover this case.  Ok to apply?

Please send a patch that adds a testcase to the testsuite to show the 
diagnostics you get after the patch.

Patch
diff mbox

Index: c-decl.c
===================================================================
--- c-decl.c	(revision 204300)
+++ c-decl.c	(working copy)
@@ -1630,13 +1630,14 @@  validate_proto_after_old_defn (tree newd
 /* Subroutine of diagnose_mismatched_decls.  Report the location of DECL,
    first in a pair of mismatched declarations, using the diagnostic
    function DIAG.  */
 static void
 locate_old_decl (tree decl)
 {
-  if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
+  if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl)
+      && !C_DECL_DECLARED_BUILTIN (decl))
     ;
   else if (DECL_INITIAL (decl))
     inform (input_location, "previous definition of %q+D was here", decl);
   else if (C_DECL_IMPLICIT (decl))
     inform (input_location, "previous implicit declaration of %q+D was here", decl);
   else