From: Chris Lattner Date: Sat, 12 Jan 2008 19:32:28 +0000 (+0000) Subject: allow __func__ in objc methods. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8f978d560d91f56ddecb8969d3b5a9f1e157a0e6;p=clang allow __func__ in objc methods. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45915 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp index 1e81d5c242..73c1687d11 100644 --- a/Sema/SemaExpr.cpp +++ b/Sema/SemaExpr.cpp @@ -122,16 +122,20 @@ Sema::ExprResult Sema::ActOnPreDefinedExpr(SourceLocation Loc, } // Verify that this is in a function context. - if (CurFunctionDecl == 0) + if (CurFunctionDecl == 0 && CurMethodDecl == 0) return Diag(Loc, diag::err_predef_outside_function); // Pre-defined identifiers are of type char[x], where x is the length of the // string. - llvm::APSInt Length(32); - Length = CurFunctionDecl->getIdentifier()->getLength() + 1; + unsigned Length; + if (CurFunctionDecl) + Length = CurFunctionDecl->getIdentifier()->getLength(); + else + Length = CurMethodDecl->getSelector().getName().size(); + llvm::APInt LengthI(32, Length + 1); QualType ResTy = Context.CharTy.getQualifiedType(QualType::Const); - ResTy = Context.getConstantArrayType(ResTy, Length, ArrayType::Normal, 0); + ResTy = Context.getConstantArrayType(ResTy, LengthI, ArrayType::Normal, 0); return new PreDefinedExpr(Loc, ResTy, IT); }