aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-10-09 19:10:41 +0000
committerDouglas Gregor <dgregor@apple.com>2011-10-09 19:10:41 +0000
commit44efed03b3ec16148722dfe57e0787a5b5c59741 (patch)
treeb7f372c0142f23eeaa3975e73673d8539d234000
parentb5a0187b12524d2c1e6ac96e81715d1e70bbe0ad (diff)
Only allow taking the address of an expression of type 'overloaded
function type' when that expression is actually an overloaded function reference (and not the address of an overloaded function reference). Fixes PR11066. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141514 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaExpr.cpp9
-rw-r--r--test/SemaCXX/address-of.cpp11
2 files changed, 19 insertions, 1 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index de35ec8525..ee985f4ba7 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -7348,8 +7348,15 @@ static QualType CheckAddressOfOperand(Sema &S, Expr *OrigOp,
SourceLocation OpLoc) {
if (OrigOp->isTypeDependent())
return S.Context.DependentTy;
- if (OrigOp->getType() == S.Context.OverloadTy)
+ if (OrigOp->getType() == S.Context.OverloadTy) {
+ if (!isa<OverloadExpr>(OrigOp->IgnoreParens())) {
+ S.Diag(OpLoc, diag::err_typecheck_invalid_lvalue_addrof)
+ << OrigOp->getSourceRange();
+ return QualType();
+ }
+
return S.Context.OverloadTy;
+ }
if (OrigOp->getType() == S.Context.UnknownAnyTy)
return S.Context.UnknownAnyTy;
if (OrigOp->getType() == S.Context.BoundMemberTy) {
diff --git a/test/SemaCXX/address-of.cpp b/test/SemaCXX/address-of.cpp
index a7e712b04c..69fcaff8f1 100644
--- a/test/SemaCXX/address-of.cpp
+++ b/test/SemaCXX/address-of.cpp
@@ -33,3 +33,14 @@ void test2() {
// PR clang/3222
void xpto();
void (*xyz)(void) = &xpto;
+
+struct PR11066 {
+ static int foo(short);
+ static int foo(float);
+ void test();
+};
+
+void PR11066::test() {
+ int (PR11066::*ptr)(int) = & &PR11066::foo; // expected-error{{address expression must be an lvalue or a function designator}}
+}
+