diff options
author | ebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-02-10 12:45:54 +0000 |
---|---|---|
committer | ebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-02-10 12:45:54 +0000 |
commit | 5389807a89faca48024325cadbd103f3dae1efaf (patch) | |
tree | 8a1d28c03b69fb9ba8205eed11d31cdecbf9221d | |
parent | e9d7220ba189fde24bd9565a2bcbdfd69254a726 (diff) | |
download | gcc-5389807a89faca48024325cadbd103f3dae1efaf.tar.gz |
PR c/7741
* c-decl.c (duplicate_decls): Discard the initializer of the
new decl when the types are conflicting.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@62631 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/c-decl.c | 6 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/decl-2.c | 10 |
4 files changed, 28 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f1879ddcb1e..d0a9caedfa4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2003-02-10 Eric Botcazou <ebotcazou@libertysurf.fr> + Christian Ehrhardt <ehrhardt@mathematik.uni-ulm.de> + + PR c/7741 + * c-decl.c (duplicate_decls): Discard the initializer of the + new decl when the types are conflicting. + 2003-02-10 Josef Zlomek <zlomekj@suse.cz> * Makefile.in (sreal.o): Added. diff --git a/gcc/c-decl.c b/gcc/c-decl.c index a5439316d2e..01a35874ecb 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -1140,6 +1140,12 @@ duplicate_decls (newdecl, olddecl, different_binding_level) } } error_with_decl (olddecl, "previous declaration of `%s'"); + + /* This is safer because the initializer might contain references + to variables that were declared between olddecl and newdecl. This + will make the initializer invalid for olddecl in case it gets + assigned to olddecl below. */ + DECL_INITIAL (newdecl) = 0; } /* TLS cannot follow non-TLS declaration. */ else if (TREE_CODE (olddecl) == VAR_DECL && TREE_CODE (newdecl) == VAR_DECL diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d9082807b76..fd9d5501d3a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2003-02-10 Eric Botcazou <ebotcazou@libertysurf.fr> + Christian Ehrhardt <ehrhardt@mathematik.uni-ulm.de> + + * gcc.dg/decl-2.c: New test. + Mon Feb 10 11:41:20 CET 2003 Jan Hubicka <jh@suse.cz> * gcc.dg/i386-fpcvt-1.c: New test. diff --git a/gcc/testsuite/gcc.dg/decl-2.c b/gcc/testsuite/gcc.dg/decl-2.c new file mode 100644 index 00000000000..44fbc733027 --- /dev/null +++ b/gcc/testsuite/gcc.dg/decl-2.c @@ -0,0 +1,10 @@ +/* PR c/7411 */ +/* Contributed by Christian Ehrhardt */ +/* { dg-do compile } */ + +void foo(void) +{ + char c; /* { dg-error "previous declaration" } */ + int i; + int c = i; /* { dg-error "conflicting types" } */ +} |