OSDN Git Service

PR c++/17365, DR 218
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 4 Nov 2009 18:13:57 +0000 (18:13 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 4 Nov 2009 18:13:57 +0000 (18:13 +0000)
* name-lookup.c (add_function): Ignore non-functions.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@153905 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/name-lookup.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/lookup/koenig5.C
gcc/testsuite/g++.dg/lookup/koenig6.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/crash56.C
gcc/testsuite/g++.old-deja/g++.ns/koenig5.C

index 2ef626d..1014832 100644 (file)
@@ -1,3 +1,8 @@
+2009-11-04  Jason Merrill  <jason@redhat.com>
+
+       PR c++/17365, DR 218
+       * name-lookup.c (add_function): Ignore non-functions.
+
 2009-11-03  Jason Merrill  <jason@redhat.com>
 
        PR c++/36959
index 25c8ac0..c3f742e 100644 (file)
@@ -4565,26 +4565,15 @@ add_function (struct arg_lookup *k, tree fn)
      total number of functions being compared, which should usually be the
      case.  */
 
-  /* We must find only functions, or exactly one non-function.  */
-  if (!k->functions)
+  if (!is_overloaded_fn (fn))
+    /* All names except those of (possibly overloaded) functions and
+       function templates are ignored.  */;
+  else if (!k->functions)
     k->functions = fn;
   else if (fn == k->functions)
     ;
-  else if (is_overloaded_fn (k->functions) && is_overloaded_fn (fn))
-    k->functions = build_overload (fn, k->functions);
   else
-    {
-      tree f1 = OVL_CURRENT (k->functions);
-      tree f2 = fn;
-      if (is_overloaded_fn (f1))
-       {
-         fn = f1; f1 = f2; f2 = fn;
-       }
-      error ("%q+D is not a function,", f1);
-      error ("  conflict with %q+D", f2);
-      error ("  in call to %qD", k->name);
-      return true;
-    }
+    k->functions = build_overload (fn, k->functions);
 
   return false;
 }
index a9df865..f11bfa2 100644 (file)
@@ -1,3 +1,11 @@
+2009-11-04  Jason Merrill  <jason@redhat.com>
+
+       PR c++/17365, DR 218
+       * g++.dg/lookup/koenig6.C: New.
+       * g++.dg/lookup/koenig5.C: Adjust.
+       * g++.dg/template/crash56.C: Adjust.
+       * g++.old-deja/g++.ns/koenig5.C: Adjust.
+
 2009-11-04  Harsha Jagasia  <harsha.jagasia@amd.com>
            Dwarakanath Rajagopal  <dwarak.rajagopal@amd.com>
 
index 139e3b8..6ecc25d 100644 (file)
@@ -8,39 +8,39 @@
 namespace N
 {
   struct A {};
-  void One (...);  // { dg-error "conflict with" "" }
-  void (*Two) (...);  // { dg-error "not a function" "" }
-  namespace Three {} // { dg-error "lookup finds|not a function" "" }
+  void One (...);
+  void (*Two) (...);
+  namespace Three {}
 }
 
 namespace M
 {
   struct B {};
-  struct One {};  // { dg-error "lookup finds|not a function" "" }
-  void (*Two) (...);  // { dg-error "conflict with" "" }
-  void Three (...);  // { dg-error "conflict with" "" }
+  struct One {};
+  void (*Two) (...);
+  void Three (...);
 }
 
 namespace O 
 {
   struct C {};
-  void Two (...); // { dg-error "conflict with" "" }
+  void Two (...);
 }
   
 void g (N::A *a, M::B *b, O::C *c)
 {
   One (a); // ok
-  One (b); // { dg-error "in call to" "" }
-  One (a, b); // { dg-error "in call to" "" }
+  One (a, b); // ok
+  One (b); // { dg-error "not declared" }
 
-  Two (a); // ok
-  Two (a, a); // ok
-  Two (b); // ok
   Two (c); // ok
-  Two (a, b); // { dg-error "in call to" "" }
-  Two (a, c); // { dg-error "in call to" "" }
+  Two (a, c); // ok
+  Two (a); // { dg-error "not declared" }
+  Two (a, a); // error masked by earlier error
+  Two (b); // error masked by earlier error
+  Two (a, b); // error masked by earlier error
   
-  Three (a); // { dg-error "in call to" "" }
   Three (b); // ok
-  Three (a, b); // { dg-error "in call to" "" }
+  Three (a, b); // ok
+  Three (a); // { dg-error "not declared" }
 }
diff --git a/gcc/testsuite/g++.dg/lookup/koenig6.C b/gcc/testsuite/g++.dg/lookup/koenig6.C
new file mode 100644 (file)
index 0000000..9fdf771
--- /dev/null
@@ -0,0 +1,18 @@
+// PR c++/17365
+// ADL should not find B::N.
+
+namespace A
+{
+  namespace B
+  {
+    template <typename T> struct N {int n_;};
+  }
+  template <typename T> int N( T p ) { return p->n_; }
+  template <typename T> void f( T p ) { N(p); }  // #1
+}
+int main()
+{
+  A::B::N<int> n;
+  A::f(&n);
+  return 0;
+}
index 1efa350..03bddf4 100644 (file)
@@ -7,10 +7,10 @@
 
 namespace N
 {
-  struct A { A (A*); }; // { dg-error "lookup finds" "" }
+  struct A { A (A*); };
 }
 
 template<typename T> void g (N::A *p)
 {
-  (void) A (p); // { dg-error "in call" "" }
+  (void) A (p); // { dg-message "" "" }
 }
index d84fc8d..33061ad 100644 (file)
@@ -1,5 +1,5 @@
 // { dg-do assemble  }
-// To find function pointers in Koenig lookup is ok as long as we only find one.
+// Function pointers are ignored in Koenig lookup. (DR 218)
 namespace A{
   void foo();             
   struct X{};
@@ -14,5 +14,5 @@ void g()
   foo(new X);            // ok -- DR 218 says that we find the global
                         // foo variable first, and therefore do not
                         // perform argument-dependent lookup.
-  bar(new X);            // ok
+  bar(new X);            // { dg-error "not declared" }
 }