Skip to content

Commit

Permalink
Implement ADOBE_CONTRACT_VIOLATED_THROWS
Browse files Browse the repository at this point in the history
  • Loading branch information
dabrahams committed Aug 19, 2024
1 parent 7069d00 commit aea6db0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 10 additions & 4 deletions include/adobe/contract_checks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
#include <exception>
#include <stdexcept>

#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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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); \
}
Expand All @@ -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(); \
}
Expand Down
2 changes: 2 additions & 0 deletions test/throwing_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define ADOBE_CONTRACT_VIOLATED_THROWS

#include "adobe/contract_checks.hpp"
#include <cstdint>
#include <gtest/gtest.h>
Expand Down

0 comments on commit aea6db0

Please sign in to comment.