On Tue, Dec 6, 2011 at 4:10 AM, Dodji Seketeli <do...@redhat.com> wrote:
> Hello,
>
> Consider this short invalid example:
>
>    typedef struct _GMutex GMutex; // #1
>    typedef union _GMutex GMutex;  // #2 <-- _GMutex named again using a
>                                   // "union" class-key even though it was
>                                   // named using a "struct" class-key in #1.
>
> This is a simple diagnostics tweak to add a note, telling the user
> where the struct _GMutex was first named using a different class-key
> previously.  This can greatly help understand the error in cases where
> e.g, #1 and #2 are in different header files.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk,
> approved in the audit trail of the PR and applied to trunk.
>
> Thanks.
>
>
> From: Dodji Seketeli <do...@redhat.com>
> Date: Mon, 5 Dec 2011 23:24:23 +0100
> Subject: [PATCH] PR c++/51427 - Better diagnostic when union/struct tags
>  conflicts
>
> gcc/cp/
>
>        PR c++/51427
>        * parser.c (cp_parser_check_class_key): Add note about earlier
>        declaration.
>
> gcc/testsuite/
>
>        PR c++/51427
>        * g++.dg/diagnostic/wrong-tag-1.C
> ---
>  gcc/cp/ChangeLog                              |    6 ++++++
>  gcc/cp/parser.c                               |   12 ++++++++----
>  gcc/testsuite/ChangeLog                       |    5 +++++
>  gcc/testsuite/g++.dg/diagnostic/wrong-tag-1.C |    4 ++++
>  4 files changed, 23 insertions(+), 4 deletions(-)
>  create mode 100644 gcc/testsuite/g++.dg/diagnostic/wrong-tag-1.C
>
> diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
> index 8f26f23..eb9b163 100644
> --- a/gcc/cp/ChangeLog
> +++ b/gcc/cp/ChangeLog
> @@ -1,3 +1,9 @@
> +2011-12-06  Dodji Seketeli  <do...@redhat.com>
> +
> +       PR c++/51427
> +       * parser.c (cp_parser_check_class_key): Add note about earlier
> +       declaration.
> +
>  2011-12-03  Paolo Carlini  <paolo.carl...@oracle.com>
>
>        PR c++/51313
> diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
> index 2fdd675..6559116 100644
> --- a/gcc/cp/parser.c
> +++ b/gcc/cp/parser.c
> @@ -22520,10 +22520,14 @@ static void
>  cp_parser_check_class_key (enum tag_types class_key, tree type)
>  {
>   if ((TREE_CODE (type) == UNION_TYPE) != (class_key == union_type))
> -    permerror (input_location, "%qs tag used in naming %q#T",
> -           class_key == union_type ? "union"
> -            : class_key == record_type ? "struct" : "class",
> -            type);
> +    {
> +      permerror (input_location, "%qs tag used in naming %q#T",
> +                class_key == union_type ? "union"
> +                : class_key == record_type ? "struct" : "class",
> +                type);
> +      inform (DECL_SOURCE_LOCATION (TYPE_NAME (type)),
> +             "%q#T was previously declared here", type);
> +    }
>  }

Hmm, I am wondering if we shouldn't remove the permerror and make it
an unconditional error.

Reply via email to