Skip to content

Commit

Permalink
More constexpr
Browse files Browse the repository at this point in the history
  • Loading branch information
horenmar committed Sep 13, 2024
1 parent 4d0090b commit 3604e56
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/catch2/catch_test_case_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,32 @@ namespace Catch {
static_assert(sizeof(TestCaseProperties) == sizeof(TCP_underlying_type),
"The size of the TestCaseProperties is different from the assumed size");

TestCaseProperties operator|(TestCaseProperties lhs, TestCaseProperties rhs) {
constexpr TestCaseProperties operator|(TestCaseProperties lhs, TestCaseProperties rhs) {
return static_cast<TestCaseProperties>(
static_cast<TCP_underlying_type>(lhs) | static_cast<TCP_underlying_type>(rhs)
);
}

TestCaseProperties& operator|=(TestCaseProperties& lhs, TestCaseProperties rhs) {
constexpr TestCaseProperties& operator|=(TestCaseProperties& lhs, TestCaseProperties rhs) {
lhs = static_cast<TestCaseProperties>(
static_cast<TCP_underlying_type>(lhs) | static_cast<TCP_underlying_type>(rhs)
);
return lhs;
}

TestCaseProperties operator&(TestCaseProperties lhs, TestCaseProperties rhs) {
constexpr TestCaseProperties operator&(TestCaseProperties lhs, TestCaseProperties rhs) {
return static_cast<TestCaseProperties>(
static_cast<TCP_underlying_type>(lhs) & static_cast<TCP_underlying_type>(rhs)
);
}

bool applies(TestCaseProperties tcp) {
constexpr bool applies(TestCaseProperties tcp) {
static_assert(static_cast<TCP_underlying_type>(TestCaseProperties::None) == 0,
"TestCaseProperties::None must be equal to 0");
return tcp != TestCaseProperties::None;
}

TestCaseProperties parseSpecialTag( StringRef tag ) {
constexpr TestCaseProperties parseSpecialTag( StringRef tag ) {
if( !tag.empty() && tag[0] == '.' )
return TestCaseProperties::IsHidden;
else if( tag == "!throws"_sr )
Expand Down Expand Up @@ -80,7 +80,7 @@ namespace Catch {
return "Anonymous test case " + std::to_string(++counter);
}

StringRef extractFilenamePart(StringRef filename) {
constexpr StringRef extractFilenamePart(StringRef filename) {
size_t lastDot = filename.size();
while (lastDot > 0 && filename[lastDot - 1] != '.') {
--lastDot;
Expand All @@ -98,7 +98,7 @@ namespace Catch {
}

// Returns the upper bound on size of extra tags ([#file]+[.])
size_t sizeOfExtraTags(StringRef filepath) {
constexpr size_t sizeOfExtraTags(StringRef filepath) {
// [.] is 3, [#] is another 3
const size_t extras = 3 + 3;
return extractFilenamePart(filepath).size() + extras;
Expand Down
2 changes: 1 addition & 1 deletion src/catch2/internal/catch_test_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace Catch {
TestType m_testAsFunction;

public:
TestInvokerAsFunction( TestType testAsFunction ) noexcept:
constexpr TestInvokerAsFunction( TestType testAsFunction ) noexcept:
m_testAsFunction( testAsFunction ) {}

void invoke() const override { m_testAsFunction(); }
Expand Down
6 changes: 4 additions & 2 deletions src/catch2/internal/catch_test_registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ template<typename C>
class TestInvokerAsMethod : public ITestInvoker {
void (C::*m_testAsMethod)();
public:
TestInvokerAsMethod( void (C::*testAsMethod)() ) noexcept : m_testAsMethod( testAsMethod ) {}
constexpr TestInvokerAsMethod( void ( C::*testAsMethod )() ) noexcept:
m_testAsMethod( testAsMethod ) {}

void invoke() const override {
C obj;
Expand All @@ -53,7 +54,8 @@ class TestInvokerFixture : public ITestInvoker {
Detail::unique_ptr<C> m_fixture = nullptr;

public:
TestInvokerFixture( void ( C::*testAsMethod )() const) noexcept : m_testAsMethod( testAsMethod ) {}
constexpr TestInvokerFixture( void ( C::*testAsMethod )() const ) noexcept:
m_testAsMethod( testAsMethod ) {}

void prepareTestCase() override {
m_fixture = Detail::make_unique<C>();
Expand Down

0 comments on commit 3604e56

Please sign in to comment.