Allow calling an overloaded function set by taking the address of the

functions, e.g., (&f)(0). Fixes <rdar://problem/9803316>.

llvm-svn: 141877
This commit is contained in:
Douglas Gregor 2011-10-13 18:10:35 +00:00
parent 1b282f9619
commit cda2270217
5 changed files with 17 additions and 10 deletions

View File

@ -894,10 +894,8 @@ bool Sema::isExprCallable(const Expr &E, QualType &ZeroArgCallReturnTy,
} }
} }
// Ignore overloads where the address is taken, because apparently // Ignore overloads that are the pointer-to-member.
// overload resolution doesn't apply in these cases. In theory, if (FR.IsAddressOfOperand && FR.HasFormOfMemberPointer)
// this can make us miss a few cases, but whatever.
if (FR.IsAddressOfOperand)
return false; return false;
return true; return true;

View File

@ -3549,8 +3549,8 @@ Sema::ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc,
if (Fn->getType() == Context.OverloadTy) { if (Fn->getType() == Context.OverloadTy) {
OverloadExpr::FindResult find = OverloadExpr::find(Fn); OverloadExpr::FindResult find = OverloadExpr::find(Fn);
// We aren't supposed to apply this logic if there's an '&' involved. // We aren't supposed to apply this logic for if there's an '&' involved.
if (!find.IsAddressOfOperand) { if (!(find.IsAddressOfOperand && find.HasFormOfMemberPointer)) {
OverloadExpr *ovl = find.Expression; OverloadExpr *ovl = find.Expression;
if (isa<UnresolvedLookupExpr>(ovl)) { if (isa<UnresolvedLookupExpr>(ovl)) {
UnresolvedLookupExpr *ULE = cast<UnresolvedLookupExpr>(ovl); UnresolvedLookupExpr *ULE = cast<UnresolvedLookupExpr>(ovl);

View File

@ -29,8 +29,7 @@ bool b8 = !S(); //expected-error {{invalid argument type 'S'}}
namespace PR8181 namespace PR8181
{ {
void f() { } // expected-note{{possible target for call}} bool f() { } // expected-note{{possible target for call}}
void f(char) { } // expected-note{{possible target for call}} void f(char) { } // expected-note{{possible target for call}}
bool b = !&f; //expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}} bool b = !&f; //expected-error {{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}}
} }

View File

@ -11,7 +11,8 @@ void test() {
void f(); // expected-note{{possible target for call}} void f(); // expected-note{{possible target for call}}
void f(int); // expected-note{{possible target for call}} void f(int); // expected-note{{possible target for call}}
void g() { void g() {
sizeof(&f); // expected-error{{reference to overloaded function could not be resolved; did you mean to call it?}} sizeof(&f); // expected-error{{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}} \
// expected-warning{{expression result unused}}
} }
template<typename T> void f_template(); // expected-note{{possible target for call}} template<typename T> void f_template(); // expected-note{{possible target for call}}

View File

@ -525,3 +525,12 @@ namespace PR9507 {
f(n); // expected-error{{call to 'f' is ambiguous}} f(n); // expected-error{{call to 'f' is ambiguous}}
} }
} }
namespace rdar9803316 {
void foo(float);
int &foo(int);
void bar() {
int &ir = (&foo)(0);
}
}