summaryrefslogtreecommitdiffstats
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
commit668d3625030b37a340af05da9c8da0d79179698c (patch)
tree053ea6e31ce1504a2cd1e36178ce042ee887147f
parentbb64afcc39cd0a865610306a8989332ab6e67c4a (diff)
downloadbcm5719-llvm-668d3625030b37a340af05da9c8da0d79179698c.tar.gz
bcm5719-llvm-668d3625030b37a340af05da9c8da0d79179698c.zip
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. llvm-svn: 141514
-rw-r--r--clang/lib/Sema/SemaExpr.cpp9
-rw-r--r--clang/test/SemaCXX/address-of.cpp11
2 files changed, 19 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index de35ec85252..ee985f4ba73 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/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/clang/test/SemaCXX/address-of.cpp b/clang/test/SemaCXX/address-of.cpp
index a7e712b04c1..69fcaff8f1e 100644
--- a/clang/test/SemaCXX/address-of.cpp
+++ b/clang/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}}
+}
+
OpenPOWER on IntegriCloud