diff options
author | Marek Polacek <polacek@redhat.com> | 2017-06-06 17:40:34 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2017-06-06 17:40:34 +0000 |
commit | dc949728324201174ce6000933435a8d0392799e (patch) | |
tree | 411298b442a48b3524633e5f64427bfa4c5ed550 /gcc/c | |
parent | 100d0700a81ba6cc9cc4910c1fb8de8e53e23d1f (diff) | |
download | gcc-dc949728324201174ce6000933435a8d0392799e.zip gcc-dc949728324201174ce6000933435a8d0392799e.tar.gz gcc-dc949728324201174ce6000933435a8d0392799e.tar.bz2 |
re PR c/79983 (Improve enum and struct redefinition diagnostic)
PR c/79983
* c-decl.c (start_struct): Use the location of TYPE_STUB_DECL of
ref.
(start_enum): Use the location of TYPE_STUB_DECL of enumtype.
* gcc.dg/pr79983.c: New test.
From-SVN: r248927
Diffstat (limited to 'gcc/c')
-rw-r--r-- | gcc/c/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/c/c-decl.c | 8 |
2 files changed, 14 insertions, 1 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index d849b01..63cd3d4 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,10 @@ +2017-06-06 Marek Polacek <polacek@redhat.com> + + PR c/79983 + * c-decl.c (start_struct): Use the location of TYPE_STUB_DECL of + ref. + (start_enum): Use the location of TYPE_STUB_DECL of enumtype. + 2017-06-02 Bernd Edlinger <bernd.edlinger@hotmail.de> * c-parser.c (c_parser_binary_expression): Implement the diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index f2b8096..3a0a4f5 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -7453,6 +7453,9 @@ start_struct (location_t loc, enum tree_code code, tree name, ref = lookup_tag (code, name, true, &refloc); if (ref && TREE_CODE (ref) == code) { + if (TYPE_STUB_DECL (ref)) + refloc = DECL_SOURCE_LOCATION (TYPE_STUB_DECL (ref)); + if (TYPE_SIZE (ref)) { if (code == UNION_TYPE) @@ -8185,7 +8188,10 @@ start_enum (location_t loc, struct c_enum_contents *the_enum, tree name) /* Update type location to the one of the definition, instead of e.g. a forward declaration. */ else if (TYPE_STUB_DECL (enumtype)) - DECL_SOURCE_LOCATION (TYPE_STUB_DECL (enumtype)) = loc; + { + enumloc = DECL_SOURCE_LOCATION (TYPE_STUB_DECL (enumtype)); + DECL_SOURCE_LOCATION (TYPE_STUB_DECL (enumtype)) = loc; + } if (C_TYPE_BEING_DEFINED (enumtype)) error_at (loc, "nested redefinition of %<enum %E%>", name); |