Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add werror to CI #67

Merged
merged 3 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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