rnk created this revision. rnk added a reviewer: amccarth. Herald added a project: clang.
While here, wordsmith the error a bit. Now clang says: error: filter expression has non-integral type 'Foo' Fixes PR43779 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D69969 Files: clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/Sema/SemaStmt.cpp clang/test/Sema/__try.c clang/test/SemaCXX/exceptions-seh.cpp Index: clang/test/SemaCXX/exceptions-seh.cpp =================================================================== --- clang/test/SemaCXX/exceptions-seh.cpp +++ clang/test/SemaCXX/exceptions-seh.cpp @@ -113,3 +113,17 @@ } 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}} +} Index: clang/test/Sema/__try.c =================================================================== --- clang/test/Sema/__try.c +++ clang/test/Sema/__try.c @@ -111,7 +111,7 @@ __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 *'}} } } Index: clang/lib/Sema/SemaStmt.cpp =================================================================== --- clang/lib/Sema/SemaStmt.cpp +++ clang/lib/Sema/SemaStmt.cpp @@ -4184,19 +4184,16 @@ 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() { Index: clang/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticSemaKinds.td +++ clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8935,7 +8935,7 @@ "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">;
Index: clang/test/SemaCXX/exceptions-seh.cpp =================================================================== --- clang/test/SemaCXX/exceptions-seh.cpp +++ clang/test/SemaCXX/exceptions-seh.cpp @@ -113,3 +113,17 @@ } 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}} +} Index: clang/test/Sema/__try.c =================================================================== --- clang/test/Sema/__try.c +++ clang/test/Sema/__try.c @@ -111,7 +111,7 @@ __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 *'}} } } Index: clang/lib/Sema/SemaStmt.cpp =================================================================== --- clang/lib/Sema/SemaStmt.cpp +++ clang/lib/Sema/SemaStmt.cpp @@ -4184,19 +4184,16 @@ 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() { Index: clang/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticSemaKinds.td +++ clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8935,7 +8935,7 @@ "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">;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits