[cfe-commits] r141877 - in /cfe/trunk: lib/Sema/Sema.cpp lib/Sema/SemaExpr.cpp test/CXX/expr/expr.unary/expr.unary.op/p6.cpp test/SemaCXX/alignof-sizeof-reference.cpp test/SemaCXX/overload-call.cpp
Douglas Gregor
dgregor at apple.com
Thu Oct 13 11:10:35 PDT 2011
Author: dgregor
Date: Thu Oct 13 13:10:35 2011
New Revision: 141877
URL: http://llvm.org/viewvc/llvm-project?rev=141877&view=rev
Log:
Allow calling an overloaded function set by taking the address of the
functions, e.g., (&f)(0). Fixes <rdar://problem/9803316>.
Modified:
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/CXX/expr/expr.unary/expr.unary.op/p6.cpp
cfe/trunk/test/SemaCXX/alignof-sizeof-reference.cpp
cfe/trunk/test/SemaCXX/overload-call.cpp
Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=141877&r1=141876&r2=141877&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Thu Oct 13 13:10:35 2011
@@ -894,10 +894,8 @@
}
}
- // 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;
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=141877&r1=141876&r2=141877&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Oct 13 13:10:35 2011
@@ -3549,8 +3549,8 @@
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<UnresolvedLookupExpr>(ovl)) {
UnresolvedLookupExpr *ULE = cast<UnresolvedLookupExpr>(ovl);
Modified: cfe/trunk/test/CXX/expr/expr.unary/expr.unary.op/p6.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.unary/expr.unary.op/p6.cpp?rev=141877&r1=141876&r2=141877&view=diff
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.unary/expr.unary.op/p6.cpp (original)
+++ cfe/trunk/test/CXX/expr/expr.unary/expr.unary.op/p6.cpp Thu Oct 13 13:10:35 2011
@@ -29,8 +29,7 @@
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?}}
}
Modified: cfe/trunk/test/SemaCXX/alignof-sizeof-reference.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/alignof-sizeof-reference.cpp?rev=141877&r1=141876&r2=141877&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/alignof-sizeof-reference.cpp (original)
+++ cfe/trunk/test/SemaCXX/alignof-sizeof-reference.cpp Thu Oct 13 13:10:35 2011
@@ -11,7 +11,8 @@
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<typename T> void f_template(); // expected-note{{possible target for call}}
Modified: cfe/trunk/test/SemaCXX/overload-call.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/overload-call.cpp?rev=141877&r1=141876&r2=141877&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/overload-call.cpp (original)
+++ cfe/trunk/test/SemaCXX/overload-call.cpp Thu Oct 13 13:10:35 2011
@@ -525,3 +525,12 @@
f(n); // expected-error{{call to 'f' is ambiguous}}
}
}
+
+namespace rdar9803316 {
+ void foo(float);
+ int &foo(int);
+
+ void bar() {
+ int &ir = (&foo)(0);
+ }
+}
More information about the cfe-commits
mailing list