Commit ac3554c5 by Jason Merrill Committed by Jason Merrill

PR c++/17365, DR 218

	PR c++/17365, DR 218
	* name-lookup.c (add_function): Ignore non-functions.

From-SVN: r153905
parent 7e9dc421
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> 2009-11-03 Jason Merrill <jason@redhat.com>
PR c++/36959 PR c++/36959
......
...@@ -4565,26 +4565,15 @@ add_function (struct arg_lookup *k, tree fn) ...@@ -4565,26 +4565,15 @@ add_function (struct arg_lookup *k, tree fn)
total number of functions being compared, which should usually be the total number of functions being compared, which should usually be the
case. */ case. */
/* We must find only functions, or exactly one non-function. */ if (!is_overloaded_fn (fn))
if (!k->functions) /* All names except those of (possibly overloaded) functions and
function templates are ignored. */;
else if (!k->functions)
k->functions = fn; k->functions = fn;
else if (fn == k->functions) else if (fn == k->functions)
; ;
else if (is_overloaded_fn (k->functions) && is_overloaded_fn (fn))
k->functions = build_overload (fn, k->functions);
else else
{ k->functions = build_overload (fn, k->functions);
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;
}
return false; return false;
} }
......
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> 2009-11-04 Harsha Jagasia <harsha.jagasia@amd.com>
Dwarakanath Rajagopal <dwarak.rajagopal@amd.com> Dwarakanath Rajagopal <dwarak.rajagopal@amd.com>
......
...@@ -8,39 +8,39 @@ ...@@ -8,39 +8,39 @@
namespace N namespace N
{ {
struct A {}; struct A {};
void One (...); // { dg-error "conflict with" "" } void One (...);
void (*Two) (...); // { dg-error "not a function" "" } void (*Two) (...);
namespace Three {} // { dg-error "lookup finds|not a function" "" } namespace Three {}
} }
namespace M namespace M
{ {
struct B {}; struct B {};
struct One {}; // { dg-error "lookup finds|not a function" "" } struct One {};
void (*Two) (...); // { dg-error "conflict with" "" } void (*Two) (...);
void Three (...); // { dg-error "conflict with" "" } void Three (...);
} }
namespace O namespace O
{ {
struct C {}; struct C {};
void Two (...); // { dg-error "conflict with" "" } void Two (...);
} }
void g (N::A *a, M::B *b, O::C *c) void g (N::A *a, M::B *b, O::C *c)
{ {
One (a); // ok One (a); // ok
One (b); // { dg-error "in call to" "" } One (a, b); // ok
One (a, b); // { dg-error "in call to" "" } One (b); // { dg-error "not declared" }
Two (a); // ok
Two (a, a); // ok
Two (b); // ok
Two (c); // ok Two (c); // ok
Two (a, b); // { dg-error "in call to" "" } Two (a, c); // ok
Two (a, c); // { dg-error "in call to" "" } 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 (b); // ok
Three (a, b); // { dg-error "in call to" "" } Three (a, b); // ok
Three (a); // { dg-error "not declared" }
} }
// 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;
}
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
namespace N namespace N
{ {
struct A { A (A*); }; // { dg-error "lookup finds" "" } struct A { A (A*); };
} }
template<typename T> void g (N::A *p) template<typename T> void g (N::A *p)
{ {
(void) A (p); // { dg-error "in call" "" } (void) A (p); // { dg-message "" "" }
} }
// { dg-do assemble } // { 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{ namespace A{
void foo(); void foo();
struct X{}; struct X{};
...@@ -14,5 +14,5 @@ void g() ...@@ -14,5 +14,5 @@ void g()
foo(new X); // ok -- DR 218 says that we find the global foo(new X); // ok -- DR 218 says that we find the global
// foo variable first, and therefore do not // foo variable first, and therefore do not
// perform argument-dependent lookup. // perform argument-dependent lookup.
bar(new X); // ok bar(new X); // { dg-error "not declared" }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment