diff options
author | Anders Carlsson <andersca@mac.com> | 2009-09-11 01:22:35 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-09-11 01:22:35 +0000 |
commit | 773f3973cf5e2b6b8788e895967dcb3c1e6ffe79 (patch) | |
tree | 2b8e01dee5c2431267b9d607c02a50ad562b384b | |
parent | f4aa4f61de7d364364dc94bbf83ff71448a11327 (diff) |
Instantiate PredefinedExprs correctly. Patch by Sam Weinig!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81498 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/Expr.h | 3 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 15 | ||||
-rw-r--r-- | lib/Sema/SemaTemplateInstantiate.cpp | 24 |
3 files changed, 36 insertions, 6 deletions
diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 604765f66d..14e5972f0f 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -363,7 +363,8 @@ private: IdentType Type; public: PredefinedExpr(SourceLocation l, QualType type, IdentType IT) - : Expr(PredefinedExprClass, type), Loc(l), Type(IT) {} + : Expr(PredefinedExprClass, type, type->isDependentType(), + type->isDependentType()), Loc(l), Type(IT) {} /// \brief Construct an empty predefined expression. explicit PredefinedExpr(EmptyShell Empty) diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 53f3dde283..3f456d4d9b 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -1157,12 +1157,17 @@ Sema::OwningExprResult Sema::ActOnPredefinedExpr(SourceLocation Loc, currentDecl = Context.getTranslationUnitDecl(); } - unsigned Length = - PredefinedExpr::ComputeName(Context, IT, currentDecl).length(); + QualType ResTy; + if (cast<DeclContext>(currentDecl)->isDependentContext()) { + ResTy = Context.DependentTy; + } else { + unsigned Length = + PredefinedExpr::ComputeName(Context, IT, currentDecl).length(); - llvm::APInt LengthI(32, Length + 1); - QualType ResTy = Context.CharTy.getQualifiedType(QualType::Const); - ResTy = Context.getConstantArrayType(ResTy, LengthI, ArrayType::Normal, 0); + llvm::APInt LengthI(32, Length + 1); + ResTy = Context.CharTy.getQualifiedType(QualType::Const); + ResTy = Context.getConstantArrayType(ResTy, LengthI, ArrayType::Normal, 0); + } return Owned(new (Context) PredefinedExpr(Loc, ResTy, IT)); } diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index 912b965507..651d4a50dc 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -391,6 +391,7 @@ namespace { IdentifierInfo *Name, SourceLocation Loc, SourceRange TypeRange); + Sema::OwningExprResult TransformPredefinedExpr(PredefinedExpr *E); Sema::OwningExprResult TransformDeclRefExpr(DeclRefExpr *E); /// \brief Transforms a template type parameter type by performing @@ -451,6 +452,29 @@ TemplateInstantiator::RebuildExceptionDecl(VarDecl *ExceptionDecl, } Sema::OwningExprResult +TemplateInstantiator::TransformPredefinedExpr(PredefinedExpr *E) { + if (!E->isTypeDependent()) + return SemaRef.Owned(E->Retain()); + + FunctionDecl *currentDecl = getSema().getCurFunctionDecl(); + assert(currentDecl && "Must have current function declaration when " + "instantiating."); + + PredefinedExpr::IdentType IT = E->getIdentType(); + + unsigned Length = + PredefinedExpr::ComputeName(getSema().Context, IT, currentDecl).length(); + + llvm::APInt LengthI(32, Length + 1); + QualType ResTy = getSema().Context.CharTy.getQualifiedType(QualType::Const); + ResTy = getSema().Context.getConstantArrayType(ResTy, LengthI, + ArrayType::Normal, 0); + PredefinedExpr *PE = + new (getSema().Context) PredefinedExpr(E->getLocation(), ResTy, IT); + return getSema().Owned(PE); +} + +Sema::OwningExprResult TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) { // FIXME: Clean this up a bit NamedDecl *D = E->getDecl(); |