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 c++/44333 (typedefs and using-directives)


The resolution of core issue 14 clarified that the entity declared by a typedef is the type, so multiple typedefs giving the same type to a particular name are OK.

Tested x86_64-pc-linux-gnu, applied to trunk.

commit b51faf19ae1c4c74cd830166b3455ff4324637ae
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Jun 2 14:08:17 2010 -0400

    	PR c++/44333
    	* name-lookup.c (same_entity_p): New.
    	(ambiguous_decl): Multiple declarations of the same entity
    	are not ambiguous.

diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index 051d3c5..936c256 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -3698,6 +3698,31 @@ merge_functions (tree s1, tree s2)
   return s1;
 }
 
+/* Returns TRUE iff OLD and NEW are the same entity.
+
+   3 [basic]/3: An entity is a value, object, reference, function,
+   enumerator, type, class member, template, template specialization,
+   namespace, parameter pack, or this.
+
+   7.3.4 [namespace.udir]/4: If name lookup finds a declaration for a name
+   in two different namespaces, and the declarations do not declare the
+   same entity and do not declare functions, the use of the name is
+   ill-formed.  */
+
+static bool
+same_entity_p (tree one, tree two)
+{
+  if (one == two)
+    return true;
+  if (!one || !two)
+    return false;
+  if (TREE_CODE (one) == TYPE_DECL
+      && TREE_CODE (two) == TYPE_DECL
+      && same_type_p (TREE_TYPE (one), TREE_TYPE (two)))
+    return true;
+  return false;
+}
+
 /* This should return an error not all definitions define functions.
    It is not an error if we find two functions with exactly the
    same signature, only if these are selected in overload resolution.
@@ -3763,7 +3788,7 @@ ambiguous_decl (struct scope_binding *old, cxx_binding *new_binding, int flags)
 
   if (!old->value)
     old->value = val;
-  else if (val && val != old->value)
+  else if (val && !same_entity_p (val, old->value))
     {
       if (is_overloaded_fn (old->value) && is_overloaded_fn (val))
 	old->value = merge_functions (old->value, val);
diff --git a/gcc/testsuite/g++.dg/tc1/dr101.C b/gcc/testsuite/g++.dg/tc1/dr101.C
index c5b34a4..0316aaa 100644
--- a/gcc/testsuite/g++.dg/tc1/dr101.C
+++ b/gcc/testsuite/g++.dg/tc1/dr101.C
@@ -17,15 +17,14 @@ namespace Test1 {
 
 namespace Test2 {
 
-  typedef unsigned int X;   // { dg-bogus "X" "" { xfail *-*-* } }
+  typedef unsigned int X;   // { dg-bogus "X" "" }
   extern "C" int f2();
   namespace N {
-    typedef unsigned int X; // { dg-bogus "X" "" { xfail *-*-* } }
+    typedef unsigned int X; // { dg-bogus "X" "" }
     extern "C" int f2();
   }
   using namespace N;
   int i = f2(); // { dg-bogus "" "redeclaration through 'using' should not be ambiguous" }
-  X x;          // { dg-bogus "" "redeclaration through 'using' should not be ambiguous" { xfail *-*-* } }
+  X x;          // { dg-bogus "" "redeclaration through 'using' should not be ambiguous" }
 
 }
-

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