Skip to content

Commit

Permalink
add werror to CI (#67)
Browse files Browse the repository at this point in the history
Co-authored-by: Liss Heidrich <[email protected]>
  • Loading branch information
mcb5637 and liss-h authored Jan 6, 2025
1 parent 631a536 commit 99e159b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code_testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
uses: dice-group/cpp-conan-release-reusable-workflow/.github/actions/add_conan_provider@main

- name: Configure CMake
run: cmake -DCMAKE_CXX_FLAGS="-fsanitize=address,undefined" -DCMAKE_BUILD_TYPE=Debug -DWITH_SVECTOR=ON -DWITH_BOOST=ON -DBUILD_TESTING=On -DBUILD_EXAMPLES=On -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=conan_provider.cmake -G Ninja -B build .
run: cmake -DCMAKE_CXX_FLAGS="-fsanitize=address,undefined" -DCMAKE_BUILD_TYPE=Debug -DWITH_SVECTOR=ON -DWITH_BOOST=ON -DBUILD_TESTING=On -DBUILD_EXAMPLES=On -DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=conan_provider.cmake -G Ninja -B build .
env:
CC: ${{ steps.install_cc.outputs.cc }}
CXX: ${{ steps.install_cc.outputs.cxx }}
Expand Down
73 changes: 31 additions & 42 deletions include/dice/template-library/variant2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@
#include <utility>
#include <variant>

#define DICE_TEMPLATELIBRARY_DETAIL_VARIANT2_TRY(noexcept_spec, action_block) \
if constexpr (noexcept_spec) { \
action_block \
} else { \
try { \
action_block \
} catch (...) { \
discriminant_ = discriminant_type::ValuelessByException; \
throw; \
} \
}


namespace dice::template_library {
template<typename T, typename U>
struct variant2;
Expand Down Expand Up @@ -314,13 +327,10 @@ namespace dice::template_library {
break;
}
case discriminant_type::Second: {
try {
a_.~T();
a_.~T();
DICE_TEMPLATELIBRARY_DETAIL_VARIANT2_TRY(std::is_nothrow_copy_constructible_v<U>, {
new (&b_) U{other.b_};
} catch (...) {
discriminant_ = discriminant_type::ValuelessByException;
throw;
}
});
break;
}
case discriminant_type::ValuelessByException: {
Expand All @@ -337,13 +347,10 @@ namespace dice::template_library {
case discriminant_type::Second: {
switch (other.discriminant_) {
case discriminant_type::First: {
try {
b_.~U();
b_.~U();
DICE_TEMPLATELIBRARY_DETAIL_VARIANT2_TRY(std::is_nothrow_copy_constructible_v<T>, {
new (&a_) T{other.a_};
} catch (...) {
discriminant_ = discriminant_type::ValuelessByException;
throw;
}
});
break;
}
case discriminant_type::Second: {
Expand Down Expand Up @@ -410,12 +417,9 @@ namespace dice::template_library {
}
case discriminant_type::Second: {
a_.~T();
try {
DICE_TEMPLATELIBRARY_DETAIL_VARIANT2_TRY(std::is_nothrow_move_constructible_v<U>, {
new (&b_) U{std::move(other.b_)};
} catch (...) {
discriminant_ = discriminant_type::ValuelessByException;
throw;
}
});
break;
}
case discriminant_type::ValuelessByException: {
Expand All @@ -433,12 +437,9 @@ namespace dice::template_library {
switch (other.discriminant_) {
case discriminant_type::First: {
b_.~U();
try {
DICE_TEMPLATELIBRARY_DETAIL_VARIANT2_TRY(std::is_nothrow_move_constructible_v<T>, {
new (&a_) T{std::move(other.a_)};
} catch (...) {
discriminant_ = discriminant_type::ValuelessByException;
throw;
}
});
break;
}
case discriminant_type::Second: {
Expand Down Expand Up @@ -499,12 +500,9 @@ namespace dice::template_library {
}
case discriminant_type::Second: {
b_.~U();
try {
DICE_TEMPLATELIBRARY_DETAIL_VARIANT2_TRY(std::is_nothrow_copy_constructible_v<T>, {
new (&a_) T{value};
} catch (...) {
discriminant_ = discriminant_type::ValuelessByException;
throw;
}
});
discriminant_ = discriminant_type::First;
break;
}
Expand Down Expand Up @@ -533,12 +531,9 @@ namespace dice::template_library {
}
case discriminant_type::Second: {
b_.~U();
try {
DICE_TEMPLATELIBRARY_DETAIL_VARIANT2_TRY(std::is_nothrow_move_constructible_v<T>, {
new (&a_) T{std::move(value)};
} catch (...) {
discriminant_ = discriminant_type::ValuelessByException;
throw;
}
});
discriminant_ = discriminant_type::First;
break;
}
Expand All @@ -562,12 +557,9 @@ namespace dice::template_library {
switch (discriminant_) {
case discriminant_type::First: {
a_.~T();
try {
DICE_TEMPLATELIBRARY_DETAIL_VARIANT2_TRY(std::is_nothrow_copy_constructible_v<U>, {
new (&b_) U{value};
} catch (...) {
discriminant_ = discriminant_type::ValuelessByException;
throw;
}
});
discriminant_ = discriminant_type::Second;
break;
}
Expand All @@ -594,12 +586,9 @@ namespace dice::template_library {
switch (discriminant_) {
case discriminant_type::First: {
a_.~T();
try {
DICE_TEMPLATELIBRARY_DETAIL_VARIANT2_TRY(std::is_nothrow_move_constructible_v<U>, {
new (&b_) U{std::move(value)};
} catch (...) {
discriminant_ = discriminant_type::ValuelessByException;
throw;
}
});
discriminant_ = discriminant_type::Second;
break;
}
Expand Down

0 comments on commit 99e159b

Please sign in to comment.