[cfe-commits] r72218 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiateExpr.cpp test/SemaTemplate/instantiate-expr-4.cpp
Douglas Gregor
dgregor at apple.com
Thu May 21 11:35:07 PDT 2009
Author: dgregor
Date: Thu May 21 13:34:44 2009
New Revision: 72218
URL: http://llvm.org/viewvc/llvm-project?rev=72218&view=rev
Log:
Template instantiation for C++ "typeid" expressions.
Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp
cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp?rev=72218&r1=72217&r2=72218&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp Thu May 21 13:34:44 2009
@@ -82,7 +82,7 @@
OwningExprResult VisitCXXThisExpr(CXXThisExpr *E);
OwningExprResult VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E);
OwningExprResult VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E);
- // FIXME: CXXTypeIdExpr
+ OwningExprResult VisitCXXTypeidExpr(CXXTypeidExpr *E);
OwningExprResult VisitCXXThrowExpr(CXXThrowExpr *E);
// FIXME: CXXDefaultArgExpr
OwningExprResult VisitCXXConstructExpr(CXXConstructExpr *E);
@@ -813,6 +813,38 @@
}
Sema::OwningExprResult
+TemplateExprInstantiator::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
+ if (E->isTypeOperand()) {
+ QualType T = SemaRef.InstantiateType(E->getTypeOperand(),
+ TemplateArgs,
+ /*FIXME*/E->getSourceRange().getBegin(),
+ DeclarationName());
+ if (T.isNull())
+ return SemaRef.ExprError();
+
+ return SemaRef.ActOnCXXTypeid(E->getSourceRange().getBegin(),
+ /*FIXME*/E->getSourceRange().getBegin(),
+ true, T.getAsOpaquePtr(),
+ E->getSourceRange().getEnd());
+ }
+
+ OwningExprResult Operand = Visit(E->getExprOperand());
+ if (Operand.isInvalid())
+ return SemaRef.ExprError();
+
+ OwningExprResult Result
+ = SemaRef.ActOnCXXTypeid(E->getSourceRange().getBegin(),
+ /*FIXME*/E->getSourceRange().getBegin(),
+ false, Operand.get(),
+ E->getSourceRange().getEnd());
+ if (Result.isInvalid())
+ return SemaRef.ExprError();
+
+ Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
+ return move(Result);
+}
+
+Sema::OwningExprResult
TemplateExprInstantiator::VisitCXXThrowExpr(CXXThrowExpr *E) {
OwningExprResult SubExpr(SemaRef, (void *)0);
if (E->getSubExpr()) {
Modified: cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp?rev=72218&r1=72217&r2=72218&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp Thu May 21 13:34:44 2009
@@ -113,3 +113,29 @@
template struct Throw1<int*>;
template struct Throw1<Incomplete*>; // expected-note{{instantiation}}
+// ---------------------------------------------------------------------
+// typeid expressions
+// ---------------------------------------------------------------------
+
+// FIXME: This should really include <typeinfo>, but we don't have that yet.
+namespace std {
+ class type_info;
+}
+
+template<typename T>
+struct TypeId0 {
+ const std::type_info &f(T* ptr) {
+ if (ptr)
+ return typeid(ptr);
+ else
+ return typeid(T);
+ }
+};
+
+struct Abstract {
+ virtual void f() = 0;
+};
+
+template struct TypeId0<int>;
+template struct TypeId0<Incomplete>;
+template struct TypeId0<Abstract>;
More information about the cfe-commits
mailing list