Template instantiation for C++ throw expressions

llvm-svn: 72217
This commit is contained in:
Douglas Gregor 2009-05-21 17:37:52 +00:00
parent 29fe6aeef3
commit 728d41bbb9
3 changed files with 35 additions and 1 deletions

View File

@ -351,6 +351,10 @@ public:
Expr(CXXThrowExprClass, Ty, false, false), Op(expr), ThrowLoc(l) {} Expr(CXXThrowExprClass, Ty, false, false), Op(expr), ThrowLoc(l) {}
const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); } const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
Expr *getSubExpr() { 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 { virtual SourceRange getSourceRange() const {
if (getSubExpr() == 0) if (getSubExpr() == 0)

View File

@ -83,7 +83,7 @@ namespace {
OwningExprResult VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); OwningExprResult VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E);
OwningExprResult VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); OwningExprResult VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E);
// FIXME: CXXTypeIdExpr // FIXME: CXXTypeIdExpr
// FIXME: CXXThrowExpr OwningExprResult VisitCXXThrowExpr(CXXThrowExpr *E);
// FIXME: CXXDefaultArgExpr // FIXME: CXXDefaultArgExpr
OwningExprResult VisitCXXConstructExpr(CXXConstructExpr *E); OwningExprResult VisitCXXConstructExpr(CXXConstructExpr *E);
OwningExprResult VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E); OwningExprResult VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E);
@ -812,6 +812,18 @@ TemplateExprInstantiator::VisitCXXThisExpr(CXXThisExpr *E) {
return SemaRef.Owned(TE); return SemaRef.Owned(TE);
} }
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 Sema::OwningExprResult
TemplateExprInstantiator::VisitCXXConstructExpr(CXXConstructExpr *E) { TemplateExprInstantiator::VisitCXXConstructExpr(CXXConstructExpr *E) {
assert(!cast<CXXRecordDecl>(E->getConstructor()->getDeclContext()) assert(!cast<CXXRecordDecl>(E->getConstructor()->getDeclContext())

View File

@ -95,3 +95,21 @@ struct Delete0 {
template struct Delete0<int*>; template struct Delete0<int*>;
template struct Delete0<X*>; template struct Delete0<X*>;
template struct Delete0<int>; // expected-note{{instantiation}} 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}}