diff --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp index 509abe3ae867f..b1ab5fcf9cb64 100644 --- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp @@ -255,6 +255,8 @@ bool ByteCodeStmtGen::visitStmt(const Stmt *S) { return visitAsmStmt(cast(S)); case Stmt::AttributedStmtClass: return visitAttributedStmt(cast(S)); + case Stmt::CXXTryStmtClass: + return visitCXXTryStmt(cast(S)); case Stmt::NullStmtClass: return true; default: { @@ -643,6 +645,12 @@ bool ByteCodeStmtGen::visitAttributedStmt(const AttributedStmt *S) { return this->visitStmt(S->getSubStmt()); } +template +bool ByteCodeStmtGen::visitCXXTryStmt(const CXXTryStmt *S) { + // Ignore all handlers. + return this->visitStmt(S->getTryBlock()); +} + namespace clang { namespace interp { diff --git a/clang/lib/AST/Interp/ByteCodeStmtGen.h b/clang/lib/AST/Interp/ByteCodeStmtGen.h index 31f9dbb8064c7..64e03587ab211 100644 --- a/clang/lib/AST/Interp/ByteCodeStmtGen.h +++ b/clang/lib/AST/Interp/ByteCodeStmtGen.h @@ -65,6 +65,7 @@ class ByteCodeStmtGen final : public ByteCodeExprGen { bool visitDefaultStmt(const DefaultStmt *S); bool visitAsmStmt(const AsmStmt *S); bool visitAttributedStmt(const AttributedStmt *S); + bool visitCXXTryStmt(const CXXTryStmt *S); bool emitLambdaStaticInvokerBody(const CXXMethodDecl *MD); diff --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp index f0bb4e9e0d071..50a7c02925878 100644 --- a/clang/test/AST/Interp/cxx20.cpp +++ b/clang/test/AST/Interp/cxx20.cpp @@ -739,3 +739,16 @@ namespace NonPrimitiveOpaqueValue static_assert(!ternary(), ""); } + +namespace TryCatch { + constexpr int foo() { + int a = 10; + try { + ++a; + } catch(int m) { + --a; + } + return a; + } + static_assert(foo() == 11); +}