[SEH] Defer checking filter expression types until instantiaton

While here, wordsmith the error a bit. Now clang says:
  error: filter expression has non-integral type 'Foo'

Fixes PR43779

Reviewers: amccarth

Differential Revision: https://reviews.llvm.org/D69969
This commit is contained in:
Reid Kleckner 2019-11-07 14:13:26 -08:00
parent d3c744313c
commit 7177ce978e
4 changed files with 24 additions and 13 deletions

View File

@ -8935,7 +8935,7 @@ def err_unknown_any_function : Error<
"function %0 with unknown type must be given a function type">;
def err_filter_expression_integral : Error<
"filter expression type should be an integral value not %0">;
"filter expression has non-integral type %0">;
def err_non_asm_stmt_in_naked_function : Error<
"non-ASM statement in naked function is not supported">;

View File

@ -4184,19 +4184,16 @@ StmtResult Sema::ActOnSEHTryBlock(bool IsCXXTry, SourceLocation TryLoc,
return SEHTryStmt::Create(Context, IsCXXTry, TryLoc, TryBlock, Handler);
}
StmtResult
Sema::ActOnSEHExceptBlock(SourceLocation Loc,
Expr *FilterExpr,
Stmt *Block) {
StmtResult Sema::ActOnSEHExceptBlock(SourceLocation Loc, Expr *FilterExpr,
Stmt *Block) {
assert(FilterExpr && Block);
if(!FilterExpr->getType()->isIntegerType()) {
return StmtError(Diag(FilterExpr->getExprLoc(),
diag::err_filter_expression_integral)
<< FilterExpr->getType());
QualType FTy = FilterExpr->getType();
if (!FTy->isIntegerType() && !FTy->isDependentType()) {
return StmtError(
Diag(FilterExpr->getExprLoc(), diag::err_filter_expression_integral)
<< FTy);
}
return SEHExceptStmt::Create(Context,Loc,FilterExpr,Block);
return SEHExceptStmt::Create(Context, Loc, FilterExpr, Block);
}
void Sema::ActOnStartSEHFinallyBlock() {

View File

@ -111,7 +111,7 @@ void TEST() {
__try {
}
__except ( NotFilterExpression() ) { // expected-error{{filter expression type should be an integral value not 'const char *'}}
__except ( NotFilterExpression() ) { // expected-error{{filter expression has non-integral type 'const char *'}}
}
}

View File

@ -113,3 +113,17 @@ void (^use_cxx_in_global_block)() = ^{
} catch(int) {
}
};
template <class T> void dependent_filter() {
__try {
might_crash();
} __except (T()) { // expected-error {{filter expression has non-integral type 'NotInteger'}}
}
}
struct NotInteger { int x; };
void instantiate_dependent_filter() {
dependent_filter<int>();
dependent_filter<NotInteger>(); // expected-note {{requested here}}
}