]> granicus.if.org Git - clang/commitdiff
Only allow taking the address of an expression of type 'overloaded
authorDouglas Gregor <dgregor@apple.com>
Sun, 9 Oct 2011 19:10:41 +0000 (19:10 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sun, 9 Oct 2011 19:10:41 +0000 (19:10 +0000)
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

lib/Sema/SemaExpr.cpp
test/SemaCXX/address-of.cpp

index de35ec852526074968f808ba4ef6c226ed6d2da7..ee985f4ba736b4bc0b5279d937b3d41b0f11ee3b 100644 (file)
@@ -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) {
index a7e712b04c1db24bec7cb4c67181abde0a72bbac..69fcaff8f1ed49d1d318fea928f330e5da9980c2 100644 (file)
@@ -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}}
+}
+