This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] PR c++/51427 - Better diagnostic when union/struct tags conflict
- From: Dodji Seketeli <dodji at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Jason Merrill <jason at redhat dot com>, Gabriel Dos Reis <gdr at integrable-solutions dot net>
- Date: Tue, 06 Dec 2011 11:10:01 +0100
- Subject: [PATCH] PR c++/51427 - Better diagnostic when union/struct tags conflict
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 <dodji@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 <dodji@redhat.com>
+
+ PR c++/51427
+ * parser.c (cp_parser_check_class_key): Add note about earlier
+ declaration.
+
2011-12-03 Paolo Carlini <paolo.carlini@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);
+ }
}
/* Issue an error message if DECL is redeclared with different
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 7c6b9b2..94b5be9 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2011-12-06 Dodji Seketeli <dodji@redhat.com>
+
+ PR c++/51427
+ * g++.dg/diagnostic/wrong-tag-1.C
+
2011-12-05 Jakub Jelinek <jakub@redhat.com>
Eric Botcazou <ebotcazou@adacore.com>
diff --git a/gcc/testsuite/g++.dg/diagnostic/wrong-tag-1.C b/gcc/testsuite/g++.dg/diagnostic/wrong-tag-1.C
new file mode 100644
index 0000000..2cf75f8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/wrong-tag-1.C
@@ -0,0 +1,4 @@
+// Origin PR c++/51427
+
+typedef struct _GMutex GMutex; // { dg-message "previously declared here"}
+typedef union _GMutex GMutex; // { dg-error "tag used in naming" }
--
1.7.6.4
--
Dodji