]> granicus.if.org Git - clang/commitdiff
Implement test/Sema/init.c by treating functions as constants.
authorChris Lattner <sabre@nondot.org>
Thu, 1 Nov 2007 02:45:17 +0000 (02:45 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 1 Nov 2007 02:45:17 +0000 (02:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43599 91177308-0d34-0410-b5e6-96231b3b80d8

AST/Expr.cpp
test/Sema/init.c [new file with mode: 0644]

index b21aad20cee7aa01e834e395c821d0fe8ae32125..14ef48c7de8ecdaff5646a2d53e48d47c11b542e 100644 (file)
@@ -382,11 +382,14 @@ bool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const {
     if (Loc) *Loc = getLocStart();
     return false;
   }
-  case DeclRefExprClass:
-    if (isa<EnumConstantDecl>(cast<DeclRefExpr>(this)->getDecl()))
+  case DeclRefExprClass: {
+    const Decl *D = cast<DeclRefExpr>(this)->getDecl();
+    // Accept address of function.
+    if (isa<EnumConstantDecl>(D) || isa<FunctionDecl>(D))
       return true;
     if (Loc) *Loc = getLocStart();
     return false;
+  }
   case UnaryOperatorClass: {
     const UnaryOperator *Exp = cast<UnaryOperator>(this);
     
diff --git a/test/Sema/init.c b/test/Sema/init.c
new file mode 100644 (file)
index 0000000..71b1d63
--- /dev/null
@@ -0,0 +1,6 @@
+// RUN: clang %s -verify -fsyntax-only
+
+typedef void (* fp)(void);
+void foo(void);
+fp a[1] = { foo };
+