diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index 2cb927568108..7b9f5909d1c3 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -894,10 +894,8 @@ bool Sema::isExprCallable(const Expr &E, QualType &ZeroArgCallReturnTy, } } - // Ignore overloads where the address is taken, because apparently - // overload resolution doesn't apply in these cases. In theory, - // this can make us miss a few cases, but whatever. - if (FR.IsAddressOfOperand) + // Ignore overloads that are the pointer-to-member. + if (FR.IsAddressOfOperand && FR.HasFormOfMemberPointer) return false; return true; diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index d0ad5c8bfd2a..bfe98498d895 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -3549,8 +3549,8 @@ Sema::ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, if (Fn->getType() == Context.OverloadTy) { OverloadExpr::FindResult find = OverloadExpr::find(Fn); - // We aren't supposed to apply this logic if there's an '&' involved. - if (!find.IsAddressOfOperand) { + // We aren't supposed to apply this logic for if there's an '&' involved. + if (!(find.IsAddressOfOperand && find.HasFormOfMemberPointer)) { OverloadExpr *ovl = find.Expression; if (isa(ovl)) { UnresolvedLookupExpr *ULE = cast(ovl); diff --git a/clang/test/CXX/expr/expr.unary/expr.unary.op/p6.cpp b/clang/test/CXX/expr/expr.unary/expr.unary.op/p6.cpp index 129a4f4e7709..ac11940c80da 100644 --- a/clang/test/CXX/expr/expr.unary/expr.unary.op/p6.cpp +++ b/clang/test/CXX/expr/expr.unary/expr.unary.op/p6.cpp @@ -29,8 +29,7 @@ bool b8 = !S(); //expected-error {{invalid argument type 'S'}} 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}} - 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?}} } diff --git a/clang/test/SemaCXX/alignof-sizeof-reference.cpp b/clang/test/SemaCXX/alignof-sizeof-reference.cpp index 1d65abbcc9fe..6a2d301ff4e1 100644 --- a/clang/test/SemaCXX/alignof-sizeof-reference.cpp +++ b/clang/test/SemaCXX/alignof-sizeof-reference.cpp @@ -11,7 +11,8 @@ void test() { void f(); // expected-note{{possible target for call}} void f(int); // expected-note{{possible target for call}} 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 void f_template(); // expected-note{{possible target for call}} diff --git a/clang/test/SemaCXX/overload-call.cpp b/clang/test/SemaCXX/overload-call.cpp index 9cc48993fde9..00f6a9460a7a 100644 --- a/clang/test/SemaCXX/overload-call.cpp +++ b/clang/test/SemaCXX/overload-call.cpp @@ -525,3 +525,12 @@ namespace PR9507 { f(n); // expected-error{{call to 'f' is ambiguous}} } } + +namespace rdar9803316 { + void foo(float); + int &foo(int); + + void bar() { + int &ir = (&foo)(0); + } +}