public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Fix PR c/91815
@ 2019-09-20  9:12 Eric Botcazou
  0 siblings, 0 replies; only message in thread
From: Eric Botcazou @ 2019-09-20  9:12 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 737 bytes --]

This gets rid of a bogus error issued by the C compiler on a type definition 
at file scope when there is a preceding external declaration in a local scope 
for the same symbol (but the error is still issued if the preceding external 
declaration is also at file scope).

Bootstrapped/regtested on x86-64/Linux, approved by Joseph in the audit trail 
and applied on the mainline.


2019-09-20  Eric Botcazou  <ebotcazou@adacore.com>

	PR c/91815
	* c-decl.c (pushdecl): In C detect duplicate declarations across scopes
	of identifiers in the external scope only for variables and functions.


2019-09-20  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc.dg/typedef-var-1.c: New test.
	* gcc.dg/typedef-var-2.c: Likewise.

-- 
Eric Botcazou

[-- Attachment #2: pr91815.diff --]
[-- Type: text/x-patch, Size: 886 bytes --]

Index: c-decl.c
===================================================================
--- c-decl.c	(revision 275988)
+++ c-decl.c	(working copy)
@@ -3130,8 +3130,11 @@ pushdecl (tree x)
      detecting duplicate declarations of the same object, no matter
      what scope they are in; this is what we do here.  (C99 6.2.7p2:
      All declarations that refer to the same object or function shall
-     have compatible type; otherwise, the behavior is undefined.)  */
-  if (DECL_EXTERNAL (x) || scope == file_scope)
+     have compatible type; otherwise, the behavior is undefined.)
+     However, in Objective-C, we also want to detect declarations
+     conflicting with those of the basic types.  */
+  if ((DECL_EXTERNAL (x) || scope == file_scope)
+      && (VAR_OR_FUNCTION_DECL_P (x) || c_dialect_objc ()))
     {
       tree type = TREE_TYPE (x);
       tree vistype = NULL_TREE;

[-- Attachment #3: typedef-var-1.c --]
[-- Type: text/x-csrc, Size: 149 bytes --]

/* PR c/91815 */
/* { dg-do compile } */

int f (void)
{
  extern int t;
  extern float v;   

  return (v > 0.0f);
}

typedef float t;

t v = 4.5f;

[-- Attachment #4: typedef-var-2.c --]
[-- Type: text/x-csrc, Size: 208 bytes --]

/* PR c/91815 */
/* { dg-do compile } */

int f (void)
{
  extern float v;   

  return (v > 0.0f);
}

extern int t;

typedef float t; /* { dg-error "redeclared as different kind of symbol" } */

t v = 4.5f;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-09-20  9:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-20  9:12 Fix PR c/91815 Eric Botcazou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).