]> granicus.if.org Git - clang/commitdiff
fix PR 3222: allow one to get the address of a global function in C++
authorNuno Lopes <nunoplopes@sapo.pt>
Tue, 16 Dec 2008 22:58:26 +0000 (22:58 +0000)
committerNuno Lopes <nunoplopes@sapo.pt>
Tue, 16 Dec 2008 22:58:26 +0000 (22:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61111 91177308-0d34-0410-b5e6-96231b3b80d8

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

index affe2ae2403a3c4eaf2115e33989cc32ccca2162..cdaa2fc49c109edd5deec6ab8b3b7c7345a64bac 100644 (file)
@@ -2889,7 +2889,7 @@ QualType Sema::CheckAddressOfOperand(Expr *op, SourceLocation OpLoc) {
   }
   NamedDecl *dcl = getPrimaryDecl(op);
   Expr::isLvalueResult lval = op->isLvalue(Context);
-  
+  printf("oleee\n");
   if (lval != Expr::LV_Valid) { // C99 6.5.3.2p1
     if (!dcl || !isa<FunctionDecl>(dcl)) {// allow function designators
       // FIXME: emit more specific diag...
@@ -2922,8 +2922,10 @@ QualType Sema::CheckAddressOfOperand(Expr *op, SourceLocation OpLoc) {
       return Context.OverloadTy;
     } else if (isa<FieldDecl>(dcl)) {
       // Okay: we can take the address of a field.
+    } else if (isa<FunctionDecl>(dcl)) {
+      // Okay: we can take the address of a function.
     }
-    else 
+    else
       assert(0 && "Unknown/unexpected decl type");
   }
   
index 5451f32688b4729cb4a9be7e74fb849a4b9bb89f..3d0e57f6e3aec94465a0b00f65d735222695cfec 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: clang -fsyntax-only -verify %S
+// RUN: clang -fsyntax-only -verify %s
 // PR clang/3175
 
 void bar(int*);
@@ -29,3 +29,7 @@ template<int N>
 void test2() {
   (void)&N; // expected-error{{address expression must be an lvalue or a function designator}}
 }
+
+// PR clang/3222
+void xpto();
+void (*xyz)(void) = &xpto;