diff options
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 15 | ||||
-rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiate.cpp | 24 |
2 files changed, 34 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 53f3dde2831..3f456d4d9b5 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/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/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 912b965507e..651d4a50dc8 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/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(); |