[cfe-commits] r72440 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiate.cpp lib/Sema/SemaTemplateInstantiateExpr.cpp test/SemaTemplate/instantiate-type.cpp
Douglas Gregor
dgregor at apple.com
Tue May 26 15:09:25 PDT 2009
Author: dgregor
Date: Tue May 26 17:09:24 2009
New Revision: 72440
URL: http://llvm.org/viewvc/llvm-project?rev=72440&view=rev
Log:
Template instantiation for "typeof" for both types and expressions.
Added:
cfe/trunk/test/SemaTemplate/instantiate-type.cpp
Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=72440&r1=72439&r2=72440&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Tue May 26 17:09:24 2009
@@ -414,17 +414,22 @@
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<Expr>());
}
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
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp?rev=72440&r1=72439&r2=72440&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp Tue May 26 17:09:24 2009
@@ -138,9 +138,15 @@
else
assert(false &&
"FIXME: instantiation of non-local variable declarations");
- } else if (isa<FunctionDecl>(D) || isa<OverloadedFunctionDecl>(D)) {
+ } else if (isa<FunctionDecl>(D)) {
// FIXME: Instantiate decl!
NewD = cast<ValueDecl>(D);
+ } else if (isa<OverloadedFunctionDecl>(D)) {
+ // FIXME: instantiate decls?
+ return SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(cast<NamedDecl>(D),
+ SemaRef.Context.OverloadTy,
+ E->getLocation(),
+ false, false));
} else
assert(false && "FIXME: unhandled declaration reference kind");
Added: cfe/trunk/test/SemaTemplate/instantiate-type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-type.cpp?rev=72440&view=auto
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-type.cpp (added)
+++ cfe/trunk/test/SemaTemplate/instantiate-type.cpp Tue May 26 17:09:24 2009
@@ -0,0 +1,17 @@
+// RUN: clang-cc -fsyntax-only %s
+
+int* f(int);
+float *f(...);
+
+template<typename T>
+struct X {
+ typedef typeof(T*) typeof_type;
+ typedef typeof(f(T())) typeof_expr;
+};
+
+int *iptr0;
+float *fptr0;
+X<int>::typeof_type &iptr1 = iptr0;
+
+X<int>::typeof_expr &iptr2 = iptr0;
+X<float*>::typeof_expr &fptr1 = fptr0;
More information about the cfe-commits
mailing list