aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>2004-12-08 10:25:22 +0000
committerKriang Lerdsuwanakij <lerdsuwa@gcc.gnu.org>2004-12-08 10:25:22 +0000
commit4104f0f400f167b37370cbc20f4f7da218a95ded (patch)
treeba2cf8aead370d4ea6daf2310a770af38c8348f3
parent0710ccffc3ddf8e4877fdab6cf712cd65f45d1cb (diff)
downloadgcc-4104f0f400f167b37370cbc20f4f7da218a95ded.zip
gcc-4104f0f400f167b37370cbc20f4f7da218a95ded.tar.gz
gcc-4104f0f400f167b37370cbc20f4f7da218a95ded.tar.bz2
re PR c++/18100 (template member with same name as class not rejected)
PR c++/18100 * decl.c (lookup_and_check_tag): Diagnose nested class with the same name as enclosing class. * g++.dg/lookup/name-clash4.C: New test. From-SVN: r91866
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/decl.c12
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/lookup/name-clash4.C12
4 files changed, 35 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index c0da0a1..13cfc69 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2004-12-08 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
+
+ PR c++/18100
+ * decl.c (lookup_and_check_tag): Diagnose nested class with
+ the same name as enclosing class.
+
2004-12-08 Nathan Sidwell <nathan@codesourcery.com>
PR c++/18803
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 22fcc7c..410f686 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -9169,6 +9169,18 @@ lookup_and_check_tag (enum tag_types tag_code, tree name,
if (decl && TREE_CODE (decl) == TYPE_DECL)
{
+ /* Look for invalid nested type:
+ class C {
+ class C {};
+ }; */
+ if (scope == ts_current && DECL_SELF_REFERENCE_P (decl))
+ {
+ error ("%qD has the same name as the class in which it is "
+ "declared",
+ decl);
+ return error_mark_node;
+ }
+
/* Two cases we need to consider when deciding if a class
template is allowed as an elaborated type specifier:
1. It is a self reference to its own class.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 0527609..468fb31 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2004-12-08 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
+
+ PR c++/18100
+ * g++.dg/lookup/name-clash4.C: New test.
+
2004-12-08 Nathan Sidwell <nathan@codesourcery.com>
PR c++/18672
diff --git a/gcc/testsuite/g++.dg/lookup/name-clash4.C b/gcc/testsuite/g++.dg/lookup/name-clash4.C
new file mode 100644
index 0000000..d4ff551
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lookup/name-clash4.C
@@ -0,0 +1,12 @@
+// { dg-do compile }
+
+// Origin: Volker Reichelt <reichelt@gcc.gnu.org>
+
+// PR c++/18100: Invalid nested type.
+
+struct A
+{
+ template<int> struct A {}; // { dg-error "same name" }
+};
+
+A::A<0> a; // { dg-error "not a template" }