From aea6db06c494707da0dd399266cae418c6085fc0 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Mon, 19 Aug 2024 16:26:02 -0700 Subject: [PATCH] Implement ADOBE_CONTRACT_VIOLATED_THROWS --- include/adobe/contract_checks.hpp | 14 ++++++++++---- test/throwing_tests.cpp | 2 ++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/adobe/contract_checks.hpp b/include/adobe/contract_checks.hpp index fc3ceda..d821129 100644 --- a/include/adobe/contract_checks.hpp +++ b/include/adobe/contract_checks.hpp @@ -5,6 +5,12 @@ #include #include +#ifdef ADOBE_CONTRACT_VIOLATED_THROWS +#define INTERNAL_ADOBE_CONTRACT_VIOLATED_NOEXCEPT +#else +#define INTERNAL_ADOBE_CONTRACT_VIOLATED_NOEXCEPT noexcept +#endif + namespace adobe { // A violation of some API contract. @@ -76,13 +82,13 @@ class contract_violation final : public ::std::logic_error contract_violation::kind_t kind, const char *file, std::uint32_t line, - const char *message); + const char *message) INTERNAL_ADOBE_CONTRACT_VIOLATED_NOEXCEPT; [[noreturn]] inline void default_contract_violated(const char *const condition, contract_violation::kind_t kind, const char *const file, std::uint32_t const line, - const char *const message) + const char *const message) noexcept { // This pattern, calling terminate while unwinding, causes most // standard libraries to report the exception that was thrown via @@ -121,7 +127,7 @@ class contract_violation final : public ::std::logic_error ::adobe::contract_violation::kind_t kind, \ const char *const file, \ std::uint32_t const line, \ - const char *const message) \ + const char *const message) noexcept \ { \ ::adobe::default_contract_violated(condition, kind, file, line, message); \ } @@ -148,7 +154,7 @@ class contract_violation final : public ::std::logic_error ::adobe::contract_violation::kind_t, \ const char *const, \ std::uint32_t const, \ - const char *const) \ + const char *const) noexcept \ { \ INTERNAL_ADOBE_BUILTIN_TRAP(); \ } diff --git a/test/throwing_tests.cpp b/test/throwing_tests.cpp index e7f058c..15efe00 100644 --- a/test/throwing_tests.cpp +++ b/test/throwing_tests.cpp @@ -1,3 +1,5 @@ +#define ADOBE_CONTRACT_VIOLATED_THROWS + #include "adobe/contract_checks.hpp" #include #include