Skip to content

Commit

Permalink
build: Make all GCC warnings into errors
Browse files Browse the repository at this point in the history
  • Loading branch information
oboukli committed Oct 20, 2024
1 parent 48d8b64 commit 318da3f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
7 changes: 3 additions & 4 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,15 @@
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CMAKE_COMPILE_WARNING_AS_ERROR": true,
"CMAKE_C_FLAGS": "-Wall -Wextra -pedantic",
"CMAKE_CXX_FLAGS": "-Wall -pedantic -Wcast-align=strict -Wcast-qual -Wchanges-meaning -Wconversion -Wconversion-null -Wctor-dtor-privacy -Wdangling-pointer -Wdangling-reference -Wdate-time -Wdelete-incomplete -Wdelete-non-virtual-dtor -Wdeprecated-copy -Wdeprecated-copy-dtor -Wdeprecated-enum-enum-conversion -Wdeprecated-enum-float-conversion -Wdisabled-optimization -Wdouble-promotion -Wduplicated-branches -Wduplicated-cond -Wexceptions -Wextra -Wformat=2 -Wimplicit-fallthrough=5 -Winaccessible-base -Winherited-variadic-ctor -Winit-list-lifetime -Winit-self -Winterference-size -Winvalid-constexpr -Winvalid-imported-macros -Winvalid-offsetof -Winvalid-pch -Winvalid-utf8 -Wlogical-op -Wmisleading-indentation -Wmismatched-new-delete -Wmismatched-tags -Wmissing-declarations -Wmissing-noreturn -Wmissing-requires -Wmissing-template-keyword -Wmultichar -Wmultiple-inheritance -Wnarrowing -Wnoexcept -Wnoexcept-type -Wnon-template-friend -Wnon-virtual-dtor -Wnull-dereference -Wold-style-cast -Wopenacc-parallelism -Woverlength-strings -Woverloaded-virtual -Wpacked -Wpacked-bitfield-compat -Wrange-loop-construct -Wredundant-decls -Wredundant-move -Wredundant-tags -Wregister -Wreorder -Wself-move -Wshadow -Wshift-negative-value -Wsign-conversion -Wsign-promo -Wsized-deallocation -Wstack-protector -Wstrict-null-sentinel -Wstrict-overflow -Wunused -Wunused-macros -Wuseless-cast -Wvariadic-macros -Wvector-operation-performance -Wvexing-parse -Wvirtual-inheritance -Wvirtual-move-assign -Wvla -Wvolatile -Wwrite-strings -Wzero-as-null-pointer-constant",
"CMAKE_EXPORT_COMPILE_COMMANDS": true,
"CMAKE_CONFIGURATION_TYPES": "Release;RelWithDebInfo;Debug",
"CMAKE_TOOLCHAIN_FILE": {
"value": "${sourceDir}/vcpkg/scripts/buildsystems/vcpkg.cmake",
"type": "FILEPATH"
}
},
"environment": {
"CFLAGS": "-Wall -Wextra -pedantic",
"CXXFLAGS": "-Wall -pedantic -Wcast-align=strict -Wcast-qual -Wchanges-meaning -Wconversion -Wconversion-null -Wctor-dtor-privacy -Wdangling-pointer -Wdangling-reference -Wdate-time -Wdelete-incomplete -Wdelete-non-virtual-dtor -Wdeprecated-copy -Wdeprecated-copy-dtor -Wdeprecated-enum-enum-conversion -Wdeprecated-enum-float-conversion -Wdisabled-optimization -Wdouble-promotion -Wduplicated-branches -Wduplicated-cond -Wexceptions -Wextra -Wformat=2 -Wimplicit-fallthrough=5 -Winaccessible-base -Winherited-variadic-ctor -Winit-list-lifetime -Winit-self -Winterference-size -Winvalid-constexpr -Winvalid-imported-macros -Winvalid-offsetof -Winvalid-pch -Winvalid-utf8 -Wlogical-op -Wmisleading-indentation -Wmismatched-new-delete -Wmismatched-tags -Wmissing-declarations -Wmissing-noreturn -Wmissing-requires -Wmissing-template-keyword -Wmultichar -Wmultiple-inheritance -Wnarrowing -Wnoexcept -Wnoexcept-type -Wnon-template-friend -Wnon-virtual-dtor -Wnull-dereference -Wold-style-cast -Wopenacc-parallelism -Woverlength-strings -Woverloaded-virtual -Wpacked -Wpacked-bitfield-compat -Wrange-loop-construct -Wredundant-decls -Wredundant-move -Wredundant-tags -Wregister -Wreorder -Wself-move -Wshadow -Wshift-negative-value -Wsign-conversion -Wsign-promo -Wsized-deallocation -Wstack-protector -Wstrict-null-sentinel -Wstrict-overflow -Wunused -Wunused-macros -Wuseless-cast -Wvariadic-macros -Wvector-operation-performance -Wvexing-parse -Wvirtual-inheritance -Wvirtual-move-assign -Wvla -Wvolatile -Wwrite-strings -Wzero-as-null-pointer-constant"
}
}
],
Expand Down
8 changes: 4 additions & 4 deletions benchmark/last_stone_weight_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ TEST_CASE("Last stone weight benchmarking", "[benchmark][last_stone_weight]")
.run(
NAMEOF_RAW(naive::last_stone_weight<Iter, Iter>).c_str(),
[]() noexcept {
std::vector<int> stones{
std::vector stones{
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31,
37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79,
83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137,
Expand All @@ -47,7 +47,7 @@ TEST_CASE("Last stone weight benchmarking", "[benchmark][last_stone_weight]")
.run(
NAMEOF_RAW(partially_sorted::last_stone_weight<Iter, Iter>).c_str(),
[]() noexcept {
std::vector<int> stones{
std::vector stones{
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31,
37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79,
83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137,
Expand All @@ -65,7 +65,7 @@ TEST_CASE("Last stone weight benchmarking", "[benchmark][last_stone_weight]")
.run(
NAMEOF_RAW(priority_queue_based::last_stone_weight).c_str(),
[]() noexcept {
std::vector<int> stones{
std::vector stones{
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31,
37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79,
83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137,
Expand All @@ -83,7 +83,7 @@ TEST_CASE("Last stone weight benchmarking", "[benchmark][last_stone_weight]")
.run(
NAMEOF_RAW(heapified::last_stone_weight<Iter, Iter>).c_str(),
[]() noexcept {
std::vector<int> stones{
std::vector stones{
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31,
37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79,
83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137,
Expand Down
30 changes: 16 additions & 14 deletions include/forfun/last_stone_weight.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,27 @@ namespace partially_sorted {
/// non-negative, otherwise the function's behavior is undefined.
template <std::contiguous_iterator Iter, std::sentinel_for<Iter> Sentinel>
requires std::integral<std::iter_value_t<Iter>>
[[nodiscard]] constexpr auto
last_stone_weight(Iter const first, Sentinel end) noexcept
[[nodiscard]] constexpr auto last_stone_weight(Iter iter, Sentinel end) noexcept
-> std::iter_value_t<Iter>
{
using ValueType = std::iter_value_t<Iter>;
using DiffType = std::iter_difference_t<Iter>;
auto const first{iter};
auto const second{++iter};

assert(std::distance(first, end) > DiffType{0});

if ((end - first) > ValueType{1})
if (iter != end)
{
auto iter{first};
auto const sort_end{first + DiffType{2}};
for (++iter; iter != end;)
for (++iter; second != end;)
{
std::partial_sort(first, sort_end, end, std::greater<>());

*first -= *iter;
*iter = *--end;
#if __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-overflow"
#endif // __GNUC__
std::partial_sort(first, iter, end, std::greater<>());
#if __GNUC__
#pragma GCC diagnostic pop
#endif // __GNUC__

*first -= *second;
*second = *--end;
}
}

Expand Down

0 comments on commit 318da3f

Please sign in to comment.