Commit 7177ce97 authored by Reid Kleckner's avatar Reid Kleckner
Browse files

[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
parent d3c74431
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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">;
+8 −11
Original line number Diff line number Diff line
@@ -4184,18 +4184,15 @@ StmtResult Sema::ActOnSEHTryBlock(bool IsCXXTry, SourceLocation TryLoc,
  return SEHTryStmt::Create(Context, IsCXXTry, TryLoc, TryBlock, Handler);
}

StmtResult
Sema::ActOnSEHExceptBlock(SourceLocation Loc,
                          Expr *FilterExpr,
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);
}

+1 −1
Original line number Diff line number Diff line
@@ -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 *'}}

  }
}
+14 −0
Original line number Diff line number Diff line
@@ -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}}
}