Skip to content

Commit

Permalink
Replace [[noreturn]], thread_local, noexcept with platform specific m…
Browse files Browse the repository at this point in the history
…acro

Provides support for early C++11 compilers such as g++-4.7 and MSVC 2013 and 2015
  • Loading branch information
AzothAmmo committed Feb 24, 2021
1 parent 9ebf679 commit 0db2349
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 38 deletions.
45 changes: 26 additions & 19 deletions doctest/doctest.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,21 @@ DOCTEST_MSVC_SUPPRESS_WARNING(26812) // Prefer 'enum class' over 'enum'
#define DOCTEST_NOINLINE __declspec(noinline)
#define DOCTEST_UNUSED
#define DOCTEST_ALIGNMENT(x)
#define DOCTEST_NORETURN __declspec(noreturn)
#if DOCTEST_MSVC < DOCTEST_COMPILER(19, 0, 0)
#define DOCTEST_THREAD_LOCAL /* not supported */
#define DOCTEST_NOEXCEPT /* not supported */
#else // MSVC 19 or newer
#define DOCTEST_THREAD_LOCAL __declspec(thread)
#define DOCTEST_NOEXCEPT noexcept
#endif // MSVC version 19 check
#else // MSVC
#define DOCTEST_NOINLINE __attribute__((noinline))
#define DOCTEST_UNUSED __attribute__((unused))
#define DOCTEST_ALIGNMENT(x) __attribute__((aligned(x)))
#define DOCTEST_NORETURN __attribute__((noreturn))
#define DOCTEST_THREAD_LOCAL thread_local
#define DOCTEST_NOEXCEPT noexcept
#endif // MSVC

// =================================================================================================
Expand Down Expand Up @@ -583,7 +594,7 @@ namespace assertType {
DT_WARN_THROWS_WITH = is_throws_with | is_warn,
DT_CHECK_THROWS_WITH = is_throws_with | is_check,
DT_REQUIRE_THROWS_WITH = is_throws_with | is_require,

DT_WARN_THROWS_WITH_AS = is_throws_with | is_throws_as | is_warn,
DT_CHECK_THROWS_WITH_AS = is_throws_with | is_throws_as | is_check,
DT_REQUIRE_THROWS_WITH_AS = is_throws_with | is_throws_as | is_require,
Expand Down Expand Up @@ -990,7 +1001,7 @@ namespace detail {
DOCTEST_INTERFACE bool checkIfShouldThrow(assertType::Enum at);

#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
[[noreturn]]
DOCTEST_NORETURN
#endif // DOCTEST_CONFIG_NO_EXCEPTIONS
DOCTEST_INTERFACE void throwException();

Expand Down Expand Up @@ -1483,7 +1494,7 @@ namespace detail {
DOCTEST_INTERFACE void toStream(std::ostream* s, int long long in);
DOCTEST_INTERFACE void toStream(std::ostream* s, int long long unsigned in);

// ContextScope base class used to allow implementing methods of ContextScope
// ContextScope base class used to allow implementing methods of ContextScope
// that don't depend on the template parameter in doctest.cpp.
class DOCTEST_INTERFACE ContextScopeBase : public IContextScope {
protected:
Expand Down Expand Up @@ -1523,7 +1534,7 @@ namespace detail {
bool log();
void react();
};

template <typename L>
ContextScope<L> MakeContextScope(const L &lambda) {
return ContextScope<L>(lambda);
Expand Down Expand Up @@ -2780,10 +2791,6 @@ DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_END
#define DOCTEST_CONFIG_OPTIONS_PREFIX "dt-"
#endif

#ifndef DOCTEST_THREAD_LOCAL
#define DOCTEST_THREAD_LOCAL thread_local
#endif

#ifdef DOCTEST_CONFIG_NO_UNPREFIXED_OPTIONS
#define DOCTEST_OPTIONS_PREFIX_DISPLAY DOCTEST_CONFIG_OPTIONS_PREFIX
#else
Expand Down Expand Up @@ -3437,7 +3444,7 @@ namespace detail {
}

#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
[[noreturn]] void throwException() {
DOCTEST_NORETURN void throwException() {
g_cs->shouldLogCurrentException = false;
throw TestFailureException();
} // NOLINT(cert-err60-cpp)
Expand Down Expand Up @@ -3519,7 +3526,7 @@ namespace detail {
if(matchesAny(m_signature.m_name, s->filters[7], false, s->case_sensitive))
return;
}

// if a Subcase on the same level has already been entered
if(s->subcasesStack.size() < size_t(s->subcasesCurrentMaxLevel)) {
s->should_reenter = true;
Expand Down Expand Up @@ -4222,7 +4229,7 @@ namespace {
using namespace detail;

template <typename Ex>
[[noreturn]] void throw_exception(Ex const& e) {
DOCTEST_NORETURN void throw_exception(Ex const& e) {
#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
throw e;
#else // DOCTEST_CONFIG_NO_EXCEPTIONS
Expand Down Expand Up @@ -4265,8 +4272,8 @@ namespace {
public:
ScopedElement( XmlWriter* writer );

ScopedElement( ScopedElement&& other ) noexcept;
ScopedElement& operator=( ScopedElement&& other ) noexcept;
ScopedElement( ScopedElement&& other ) DOCTEST_NOEXCEPT;
ScopedElement& operator=( ScopedElement&& other ) DOCTEST_NOEXCEPT;

~ScopedElement();

Expand Down Expand Up @@ -4483,11 +4490,11 @@ namespace {
: m_writer( writer )
{}

XmlWriter::ScopedElement::ScopedElement( ScopedElement&& other ) noexcept
XmlWriter::ScopedElement::ScopedElement( ScopedElement&& other ) DOCTEST_NOEXCEPT
: m_writer( other.m_writer ){
other.m_writer = nullptr;
}
XmlWriter::ScopedElement& XmlWriter::ScopedElement::operator=( ScopedElement&& other ) noexcept {
XmlWriter::ScopedElement& XmlWriter::ScopedElement::operator=( ScopedElement&& other ) DOCTEST_NOEXCEPT {
if ( m_writer ) {
m_writer->endElement();
}
Expand Down Expand Up @@ -4757,7 +4764,7 @@ namespace {
test_case_start_impl(in);
xml.ensureTagClosed();
}

void test_case_reenter(const TestCaseData&) override {}

void test_case_end(const CurrentTestCaseStats& st) override {
Expand Down Expand Up @@ -5180,7 +5187,7 @@ namespace {
hasLoggedCurrentTestStart = false;
tc = &in;
}

void test_case_reenter(const TestCaseData&) override {}

void test_case_end(const CurrentTestCaseStats& st) override {
Expand Down Expand Up @@ -5826,7 +5833,7 @@ int Context::run() {
DOCTEST_ITERATE_THROUGH_REPORTERS(test_case_start, tc);

p->timer.start();

bool run_test = true;

do {
Expand Down Expand Up @@ -5863,7 +5870,7 @@ int Context::run() {
run_test = false;
p->failure_flags |= TestCaseFailureReason::TooManyFailedAsserts;
}

if(p->should_reenter && run_test)
DOCTEST_ITERATE_THROUGH_REPORTERS(test_case_reenter, tc);
if(!p->should_reenter)
Expand Down
26 changes: 11 additions & 15 deletions doctest/parts/doctest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,6 @@ DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_END
#define DOCTEST_CONFIG_OPTIONS_PREFIX "dt-"
#endif

#ifndef DOCTEST_THREAD_LOCAL
#define DOCTEST_THREAD_LOCAL thread_local
#endif

#ifdef DOCTEST_CONFIG_NO_UNPREFIXED_OPTIONS
#define DOCTEST_OPTIONS_PREFIX_DISPLAY DOCTEST_CONFIG_OPTIONS_PREFIX
#else
Expand Down Expand Up @@ -822,7 +818,7 @@ namespace detail {
}

#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
[[noreturn]] void throwException() {
DOCTEST_NORETURN void throwException() {
g_cs->shouldLogCurrentException = false;
throw TestFailureException();
} // NOLINT(cert-err60-cpp)
Expand Down Expand Up @@ -904,7 +900,7 @@ namespace detail {
if(matchesAny(m_signature.m_name, s->filters[7], false, s->case_sensitive))
return;
}

// if a Subcase on the same level has already been entered
if(s->subcasesStack.size() < size_t(s->subcasesCurrentMaxLevel)) {
s->should_reenter = true;
Expand Down Expand Up @@ -1607,7 +1603,7 @@ namespace {
using namespace detail;

template <typename Ex>
[[noreturn]] void throw_exception(Ex const& e) {
DOCTEST_NORETURN void throw_exception(Ex const& e) {
#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
throw e;
#else // DOCTEST_CONFIG_NO_EXCEPTIONS
Expand Down Expand Up @@ -1650,8 +1646,8 @@ namespace {
public:
ScopedElement( XmlWriter* writer );

ScopedElement( ScopedElement&& other ) noexcept;
ScopedElement& operator=( ScopedElement&& other ) noexcept;
ScopedElement( ScopedElement&& other ) DOCTEST_NOEXCEPT;
ScopedElement& operator=( ScopedElement&& other ) DOCTEST_NOEXCEPT;

~ScopedElement();

Expand Down Expand Up @@ -1868,11 +1864,11 @@ namespace {
: m_writer( writer )
{}

XmlWriter::ScopedElement::ScopedElement( ScopedElement&& other ) noexcept
XmlWriter::ScopedElement::ScopedElement( ScopedElement&& other ) DOCTEST_NOEXCEPT
: m_writer( other.m_writer ){
other.m_writer = nullptr;
}
XmlWriter::ScopedElement& XmlWriter::ScopedElement::operator=( ScopedElement&& other ) noexcept {
XmlWriter::ScopedElement& XmlWriter::ScopedElement::operator=( ScopedElement&& other ) DOCTEST_NOEXCEPT {
if ( m_writer ) {
m_writer->endElement();
}
Expand Down Expand Up @@ -2142,7 +2138,7 @@ namespace {
test_case_start_impl(in);
xml.ensureTagClosed();
}

void test_case_reenter(const TestCaseData&) override {}

void test_case_end(const CurrentTestCaseStats& st) override {
Expand Down Expand Up @@ -2565,7 +2561,7 @@ namespace {
hasLoggedCurrentTestStart = false;
tc = &in;
}

void test_case_reenter(const TestCaseData&) override {}

void test_case_end(const CurrentTestCaseStats& st) override {
Expand Down Expand Up @@ -3211,7 +3207,7 @@ int Context::run() {
DOCTEST_ITERATE_THROUGH_REPORTERS(test_case_start, tc);

p->timer.start();

bool run_test = true;

do {
Expand Down Expand Up @@ -3248,7 +3244,7 @@ int Context::run() {
run_test = false;
p->failure_flags |= TestCaseFailureReason::TooManyFailedAsserts;
}

if(p->should_reenter && run_test)
DOCTEST_ITERATE_THROUGH_REPORTERS(test_case_reenter, tc);
if(!p->should_reenter)
Expand Down
19 changes: 15 additions & 4 deletions doctest/parts/doctest_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,21 @@ DOCTEST_MSVC_SUPPRESS_WARNING(26812) // Prefer 'enum class' over 'enum'
#define DOCTEST_NOINLINE __declspec(noinline)
#define DOCTEST_UNUSED
#define DOCTEST_ALIGNMENT(x)
#define DOCTEST_NORETURN __declspec(noreturn)
#if DOCTEST_MSVC < DOCTEST_COMPILER(19, 0, 0)
#define DOCTEST_THREAD_LOCAL /* not supported */
#define DOCTEST_NOEXCEPT /* not supported */
#else // MSVC 19 or newer
#define DOCTEST_THREAD_LOCAL __declspec(thread)
#define DOCTEST_NOEXCEPT noexcept
#endif // MSVC version 19 check
#else // MSVC
#define DOCTEST_NOINLINE __attribute__((noinline))
#define DOCTEST_UNUSED __attribute__((unused))
#define DOCTEST_ALIGNMENT(x) __attribute__((aligned(x)))
#define DOCTEST_NORETURN __attribute__((noreturn))
#define DOCTEST_THREAD_LOCAL thread_local
#define DOCTEST_NOEXCEPT noexcept
#endif // MSVC

// =================================================================================================
Expand Down Expand Up @@ -580,7 +591,7 @@ namespace assertType {
DT_WARN_THROWS_WITH = is_throws_with | is_warn,
DT_CHECK_THROWS_WITH = is_throws_with | is_check,
DT_REQUIRE_THROWS_WITH = is_throws_with | is_require,

DT_WARN_THROWS_WITH_AS = is_throws_with | is_throws_as | is_warn,
DT_CHECK_THROWS_WITH_AS = is_throws_with | is_throws_as | is_check,
DT_REQUIRE_THROWS_WITH_AS = is_throws_with | is_throws_as | is_require,
Expand Down Expand Up @@ -987,7 +998,7 @@ namespace detail {
DOCTEST_INTERFACE bool checkIfShouldThrow(assertType::Enum at);

#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
[[noreturn]]
DOCTEST_NORETURN
#endif // DOCTEST_CONFIG_NO_EXCEPTIONS
DOCTEST_INTERFACE void throwException();

Expand Down Expand Up @@ -1480,7 +1491,7 @@ namespace detail {
DOCTEST_INTERFACE void toStream(std::ostream* s, int long long in);
DOCTEST_INTERFACE void toStream(std::ostream* s, int long long unsigned in);

// ContextScope base class used to allow implementing methods of ContextScope
// ContextScope base class used to allow implementing methods of ContextScope
// that don't depend on the template parameter in doctest.cpp.
class DOCTEST_INTERFACE ContextScopeBase : public IContextScope {
protected:
Expand Down Expand Up @@ -1520,7 +1531,7 @@ namespace detail {
bool log();
void react();
};

template <typename L>
ContextScope<L> MakeContextScope(const L &lambda) {
return ContextScope<L>(lambda);
Expand Down

0 comments on commit 0db2349

Please sign in to comment.