From: Douglas Gregor Date: Tue, 26 May 2009 22:09:24 +0000 (+0000) Subject: Template instantiation for "typeof" for both types and expressions. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5f8bd59b448576e0ac5996b5247f653b7476ad3e;p=clang Template instantiation for "typeof" for both types and expressions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72440 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index 3c32a21073..86e69997bc 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -414,17 +414,22 @@ TemplateTypeInstantiator::InstantiateTypedefType(const TypedefType *T, QualType TemplateTypeInstantiator::InstantiateTypeOfExprType(const TypeOfExprType *T, unsigned Quals) const { - // FIXME: Implement this - assert(false && "Cannot instantiate TypeOfExprType yet"); - return QualType(); + Sema::OwningExprResult E + = SemaRef.InstantiateExpr(T->getUnderlyingExpr(), TemplateArgs); + if (E.isInvalid()) + return QualType(); + + return SemaRef.Context.getTypeOfExprType(E.takeAs()); } QualType TemplateTypeInstantiator::InstantiateTypeOfType(const TypeOfType *T, unsigned Quals) const { - // FIXME: Implement this - assert(false && "Cannot instantiate TypeOfType yet"); - return QualType(); + QualType Underlying = Instantiate(T->getUnderlyingType()); + if (Underlying.isNull()) + return QualType(); + + return SemaRef.Context.getTypeOfType(Underlying); } QualType diff --git a/lib/Sema/SemaTemplateInstantiateExpr.cpp b/lib/Sema/SemaTemplateInstantiateExpr.cpp index 0c29839330..9dc14d551b 100644 --- a/lib/Sema/SemaTemplateInstantiateExpr.cpp +++ b/lib/Sema/SemaTemplateInstantiateExpr.cpp @@ -138,9 +138,15 @@ TemplateExprInstantiator::VisitDeclRefExpr(DeclRefExpr *E) { else assert(false && "FIXME: instantiation of non-local variable declarations"); - } else if (isa(D) || isa(D)) { + } else if (isa(D)) { // FIXME: Instantiate decl! NewD = cast(D); + } else if (isa(D)) { + // FIXME: instantiate decls? + return SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(cast(D), + SemaRef.Context.OverloadTy, + E->getLocation(), + false, false)); } else assert(false && "FIXME: unhandled declaration reference kind"); diff --git a/test/SemaTemplate/instantiate-type.cpp b/test/SemaTemplate/instantiate-type.cpp new file mode 100644 index 0000000000..48060c4e38 --- /dev/null +++ b/test/SemaTemplate/instantiate-type.cpp @@ -0,0 +1,17 @@ +// RUN: clang-cc -fsyntax-only %s + +int* f(int); +float *f(...); + +template +struct X { + typedef typeof(T*) typeof_type; + typedef typeof(f(T())) typeof_expr; +}; + +int *iptr0; +float *fptr0; +X::typeof_type &iptr1 = iptr0; + +X::typeof_expr &iptr2 = iptr0; +X::typeof_expr &fptr1 = fptr0;