This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH for 3.4] Fix PR18100 (invalid nested class)




Hi

This is the 3.4 version for patch:

http://gcc.gnu.org/ml/gcc-patches/2004-12/msg00388.html

The patch is different because of different tag name lookup infrastructure in mainline and branch.

In the 3.4 branch, only tagged type are lookup'ed so it cannot find
class name injected into class body.

For example, in this code:

 class C {     // #1
   class C {}; // #2
 };

we don't find injected 'C' from #1.  So we try to push a new tag
for #2.  The function push_class_level_binding detect the above
violation.  However it cannot diagnose:

 class C {
   template <class T> class C {};
 };

because the case for class template in push_class_level_binding is missing there. This is fixed by the patch.

Tested on i686-pc-linux-gnu. OK for 3.4 branch?

--Kriang


2004-12-06  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	PR c++/18100
	* name-lookup.c (push_class_level_binding): Diagnose nested
	class template with the same name as enclosing class.

2004-12-06  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	PR c++/18100
	* g++.dg/lookup/name-clash4.C: New test.


diff -cprN gcc-34-save/gcc/cp/name-lookup.c gcc-34-new/gcc/cp/name-lookup.c
*** gcc-34-save/gcc/cp/name-lookup.c	Tue Nov  9 23:16:09 2004
--- gcc-34-new/gcc/cp/name-lookup.c	Mon Dec  6 19:14:37 2004
*************** push_class_level_binding (tree name, tre
*** 2804,2809 ****
--- 2804,2810 ----
         || TREE_CODE (x) == CONST_DECL
         || (TREE_CODE (x) == TYPE_DECL
  	   && !DECL_SELF_REFERENCE_P (x))
+        || DECL_CLASS_TEMPLATE_P (x)
         /* A data member of an anonymous union.  */
         || (TREE_CODE (x) == FIELD_DECL
  	   && DECL_CONTEXT (x) != current_class_type))
diff -cprN gcc-34-save/gcc/testsuite/g++.dg/lookup/name-clash4.C gcc-34-new/gcc/testsuite/g++.dg/lookup/name-clash4.C
*** gcc-34-save/gcc/testsuite/g++.dg/lookup/name-clash4.C	Thu Jan  1 07:00:00 1970
--- gcc-34-new/gcc/testsuite/g++.dg/lookup/name-clash4.C	Mon Dec  6 19:16:44 2004
***************
*** 0 ****
--- 1,12 ----
+ // { dg-do compile }
+ 
+ // Origin: Volker Reichelt <reichelt@gcc.gnu.org>
+ 
+ // PR c++/18100: Invalid ested type.
+ 
+ struct A
+ {
+     template<int> struct A {};	// { dg-error "same name" }
+ };
+ 
+ A::A<0> a;			// { dg-error "not a template" }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]