From 4ef8dd6e8736097bf9e3c387139c668565d89dca Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 1 Nov 2007 02:45:17 +0000 Subject: [PATCH] Implement test/Sema/init.c by treating functions as constants. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43599 91177308-0d34-0410-b5e6-96231b3b80d8 --- AST/Expr.cpp | 7 +++++-- test/Sema/init.c | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 test/Sema/init.c diff --git a/AST/Expr.cpp b/AST/Expr.cpp index b21aad20ce..14ef48c7de 100644 --- a/AST/Expr.cpp +++ b/AST/Expr.cpp @@ -382,11 +382,14 @@ bool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const { if (Loc) *Loc = getLocStart(); return false; } - case DeclRefExprClass: - if (isa(cast(this)->getDecl())) + case DeclRefExprClass: { + const Decl *D = cast(this)->getDecl(); + // Accept address of function. + if (isa(D) || isa(D)) return true; if (Loc) *Loc = getLocStart(); return false; + } case UnaryOperatorClass: { const UnaryOperator *Exp = cast(this); diff --git a/test/Sema/init.c b/test/Sema/init.c new file mode 100644 index 0000000000..71b1d63d61 --- /dev/null +++ b/test/Sema/init.c @@ -0,0 +1,6 @@ +// RUN: clang %s -verify -fsyntax-only + +typedef void (* fp)(void); +void foo(void); +fp a[1] = { foo }; + -- 2.40.0