[cfe-commits] r72217 - in /cfe/trunk: include/clang/AST/ExprCXX.h lib/Sema/SemaTemplateInstantiateExpr.cpp test/SemaTemplate/instantiate-expr-4.cpp
Douglas Gregor
dgregor at apple.com
Thu May 21 10:38:00 PDT 2009
Author: dgregor
Date: Thu May 21 12:37:52 2009
New Revision: 72217
URL: http://llvm.org/viewvc/llvm-project?rev=72217&view=rev
Log:
Template instantiation for C++ throw expressions
Modified:
cfe/trunk/include/clang/AST/ExprCXX.h
cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp
cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp
Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=72217&r1=72216&r2=72217&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Thu May 21 12:37:52 2009
@@ -351,6 +351,10 @@
Expr(CXXThrowExprClass, Ty, false, false), Op(expr), ThrowLoc(l) {}
const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
+ void setSubExpr(Expr *E) { Op = E; }
+
+ SourceLocation getThrowLoc() const { return ThrowLoc; }
+ void setThrowLoc(SourceLocation L) { ThrowLoc = L; }
virtual SourceRange getSourceRange() const {
if (getSubExpr() == 0)
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp?rev=72217&r1=72216&r2=72217&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp Thu May 21 12:37:52 2009
@@ -83,7 +83,7 @@
OwningExprResult VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E);
OwningExprResult VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E);
// FIXME: CXXTypeIdExpr
- // FIXME: CXXThrowExpr
+ OwningExprResult VisitCXXThrowExpr(CXXThrowExpr *E);
// FIXME: CXXDefaultArgExpr
OwningExprResult VisitCXXConstructExpr(CXXConstructExpr *E);
OwningExprResult VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E);
@@ -813,6 +813,18 @@
}
Sema::OwningExprResult
+TemplateExprInstantiator::VisitCXXThrowExpr(CXXThrowExpr *E) {
+ OwningExprResult SubExpr(SemaRef, (void *)0);
+ if (E->getSubExpr()) {
+ SubExpr = Visit(E->getSubExpr());
+ if (SubExpr.isInvalid())
+ return SemaRef.ExprError();
+ }
+
+ return SemaRef.ActOnCXXThrow(E->getThrowLoc(), move(SubExpr));
+}
+
+Sema::OwningExprResult
TemplateExprInstantiator::VisitCXXConstructExpr(CXXConstructExpr *E) {
assert(!cast<CXXRecordDecl>(E->getConstructor()->getDeclContext())
->isDependentType() && "Dependent constructor shouldn't be here");
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=72217&r1=72216&r2=72217&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp Thu May 21 12:37:52 2009
@@ -95,3 +95,21 @@
template struct Delete0<int*>;
template struct Delete0<X*>;
template struct Delete0<int>; // expected-note{{instantiation}}
+
+// ---------------------------------------------------------------------
+// throw expressions
+// ---------------------------------------------------------------------
+template<typename T>
+struct Throw1 {
+ void f(T t) {
+ throw;
+ throw t; // expected-error{{incomplete type}}
+ }
+};
+
+struct Incomplete; // expected-note{{forward}}
+
+template struct Throw1<int>;
+template struct Throw1<int*>;
+template struct Throw1<Incomplete*>; // expected-note{{instantiation}}
+
More information about the cfe-commits
mailing list