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/4.0/4.1] Fix PR20240 (Accepting invalid usingdecl involving variable declaration)


Hi

This patch fixes PR20240, a regression on 3.3 up to mainline.
There is a problem deciding whether name from using declaration
and locally declared name conflicts.  That check relies on
decls_match.  Unlike typedef (no conflict if both refer to the
same type), it is always a conflict when they are variable
declaration.  The patch adds a missing check inside decls_match.

Tested on i686-pc-linux-gnu. OK for mainline, 3.4 and 4.0 branches?

--Kriang

2005-03-12  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	PR c++/20240
	* decl.c (decls_match): Compare context of VAR_DECL.

2005-03-12  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	PR c++/20240
	* g++.dg/lookup/using13.C: New test.


diff -cprN gcc-34-save/gcc/cp/decl.c gcc-34-new/gcc/cp/decl.c
*** gcc-34-save/gcc/cp/decl.c	Thu Mar  3 20:58:55 2005
--- gcc-34-new/gcc/cp/decl.c	Sat Mar 12 00:54:43 2005
*************** decls_match (tree newdecl, tree olddecl)
*** 1068,1073 ****
--- 1068,1079 ----
      }
    else
      {
+       /* Need to check scope for variable declaration (VAR_DECL).
+ 	 For typedef (TYPE_DECL), scope is ignored.  */
+       if (TREE_CODE (newdecl) == VAR_DECL
+ 	  && CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl))
+ 	return 0;
+ 
        if (TREE_TYPE (newdecl) == error_mark_node)
  	types_match = TREE_TYPE (olddecl) == error_mark_node;
        else if (TREE_TYPE (olddecl) == NULL_TREE)
diff -cprN gcc-34-save/gcc/testsuite/g++.dg/lookup/using13.C gcc-34-new/gcc/testsuite/g++.dg/lookup/using13.C
*** gcc-34-save/gcc/testsuite/g++.dg/lookup/using13.C	Thu Jan  1 07:00:00 1970
--- gcc-34-new/gcc/testsuite/g++.dg/lookup/using13.C	Sat Mar 12 00:24:18 2005
***************
*** 0 ****
--- 1,12 ----
+ // { dg-do compile }
+ 
+ // Origin: Stefan Straßer <sstrasser@systemhaus-gruppe.de>
+ 
+ // PR c++/20240: 
+ 
+ namespace A { int a; }
+ 
+ namespace C{
+   int a;
+   using A::a;		// { dg-error "already declared" }
+ }

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