diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 285ea187100..96655493ac0 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2019-09-20 Eric Botcazou + + 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-04 Prathamesh Kulkarni PR c/78736 diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 31116b21308..132fa3edb27 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a4323b4b2a7..59c6b7991ad 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-09-20 Eric Botcazou + + * gcc.dg/typedef-var-1.c: New test. + * gcc.dg/typedef-var-2.c: Likewise. + 2019-09-20 Martin Jambor * g++.dg/ipa/pr81248.C: Adjust dg-options and dump-scan. diff --git a/gcc/testsuite/gcc.dg/typedef-var-1.c b/gcc/testsuite/gcc.dg/typedef-var-1.c new file mode 100644 index 00000000000..2cda92d3d04 --- /dev/null +++ b/gcc/testsuite/gcc.dg/typedef-var-1.c @@ -0,0 +1,14 @@ +/* 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; diff --git a/gcc/testsuite/gcc.dg/typedef-var-2.c b/gcc/testsuite/gcc.dg/typedef-var-2.c new file mode 100644 index 00000000000..716d29ca323 --- /dev/null +++ b/gcc/testsuite/gcc.dg/typedef-var-2.c @@ -0,0 +1,15 @@ +/* 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;