Skip to content

Commit

Permalink
clean up clang tidy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
KRM7 committed Sep 5, 2023
1 parent d989028 commit 74c6516
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 20 deletions.
7 changes: 5 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
-cppcoreguidelines-special-member-functions,
-misc-unconventional-assign-operator,
-misc-non-private-member-variables-in-classes,
-misc-no-recursion
-misc-no-recursion,
-misc-const-correctness,
-misc-use-anonymous-namespace
# Also check the header files
Expand All @@ -44,7 +46,6 @@ HeaderFilterRegex: ".*"

# List of warnings to treat as errors during the build
WarningsAsErrors: >
*,
clang-analyzer-*,
portability-*,
bugprone-assignment-in-if-condition,
Expand Down Expand Up @@ -76,3 +77,5 @@ CheckOptions:
- { key: bugprone-narrowing-conversions.IgnoreConversionFromTypes, value: difference_type;ptrdiff_t;size_type;size_t;bool }
- { key: readability-braces-around-statements.ShortStatementLines, value: 2 }
- { key: bugprone-easily-swappable-parameters.ModelImplicitConversions, value: false }
- { key: performance-unnecessary-value-param.AllowedTypes, value: iterator* }
- { key: readability-simplify-boolean-expr.SimplifyDeMorgan, value: false }
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Compiler / linker setup
if(MSVC) # MSVC style compiler interface
set(GAPP_WARN_FLAGS "-permissive- -W4 -w44263 -w44265 -w44388 -w44471 -w44820 -w44986 -w45024 -w45025 -w45038 -w45204 -w45233 -w45258 -w45262 -w45263 -w45264 -external:W0")
set(GAPP_WARN_FLAGS "-permissive- -W4 -w44263 -w44265 -w44388 -w44471 -w44986 -w45024 -w45025 -w45038 -w45204 -w45233 -w45258 -w45262 -w45263 -w45264 -external:W0")
if(GAPP_USE_WERROR)
set(GAPP_WARN_FLAGS "${GAPP_WARN_FLAGS} -WX")
endif()
Expand Down Expand Up @@ -184,6 +184,7 @@ if(GAPP_BUILD_TESTS AND BUILD_TESTING AND PROJECT_IS_TOP_LEVEL)
enable_testing()
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/test/unit")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/test/integration")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/test/misc")
endif()

if(GAPP_BUILD_BENCHMARKS AND BUILD_TESTING AND PROJECT_IS_TOP_LEVEL)
Expand Down
34 changes: 33 additions & 1 deletion CMakeSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"cmakeCommandArgs": "-DGAPP_CXX_FLAGS=/analyze:WX- -DGAPP_BUILD_TESTS=ON -DGAPP_BUILD_BENCHMARKS=ON -DGAPP_BUILD_EXAMPLES=ON",
"ctestCommandArgs": "--output-on-failure --schedule-random",
"codeAnalysisRuleset": "${projectDir}\\core-guidelines.ruleset",
"enableMicrosoftCodeAnalysis": true,
"enableMicrosoftCodeAnalysis": false,
"inheritEnvironments": [ "msvc_x64_x64" ]
},
{
Expand Down Expand Up @@ -44,6 +44,7 @@
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "-DGAPP_BUILD_TESTS=ON -DGAPP_BUILD_BENCHMARKS=ON -DGAPP_BUILD_EXAMPLES=ON",
"ctestCommandArgs": "--output-on-failure --schedule-random",
"enableClangTidyCodeAnalysis": false,
"inheritEnvironments": [ "clang_cl_x64_x64" ]
},
{
Expand Down Expand Up @@ -77,6 +78,37 @@
"codeAnalysisRuleset": "${projectDir}\\core-guidelines.ruleset",
"enableMicrosoftCodeAnalysis": false,
"inheritEnvironments": [ "msvc_x64_x64" ]
},
{
"name": "clang-tidy",
"generator": "Ninja",
"configurationType": "Debug",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "-DGAPP_BUILD_TESTS=ON",
"ctestCommandArgs": "--output-on-failure --schedule-random",
"disableExternalAnalysis": true,
"inheritEnvironments": [ "clang_cl_x64_x64" ],
"variables": [
{
"name": "CMAKE_CXX_CLANG_TIDY",
"value": "clang-tidy"
}
]
},
{
"name": "core-guidelines-check",
"generator": "Ninja",
"configurationType": "Debug",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "-DGAPP_CXX_FLAGS=/analyze:WX- -DGAPP_BUILD_TESTS=ON",
"ctestCommandArgs": "--output-on-failure --schedule-random",
"codeAnalysisRuleset": "${projectDir}\\core-guidelines.ruleset",
"enableMicrosoftCodeAnalysis": true,
"disableExternalAnalysis": true,
"inheritEnvironments": [ "msvc_x64_x64" ],
"environments": [ { "CAExcludePath": "${projectDir}\\src\\algorithm\\reference_lines.cpp" } ]
}
]
}
2 changes: 1 addition & 1 deletion src/core/ga_base.impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ namespace gapp
inline bool GA<T>::fitnessMatrixIsSynced() const
{
return std::equal(fitness_matrix_.begin(), fitness_matrix_.end(), population_.begin(), population_.end(),
[this](const auto& fvec, const auto& sol)
[](const auto& fvec, const auto& sol)
{
return fvec == sol.fitness;
});
Expand Down
4 changes: 2 additions & 2 deletions test/misc/rcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ using namespace gapp::detail;
using namespace std::chrono_literals;


rcu_obj<size_t> number = 0;
rcu_obj<int> number = 0;

static const auto reader_func = []
{
while (true)
{
std::scoped_lock _{ number };
const size_t& n = number.get();
[[maybe_unused]] const int& n = number.get();
std::this_thread::sleep_for(2ms);
assert(0 <= n && n <= 100);
}
Expand Down
4 changes: 2 additions & 2 deletions test/unit/algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ TEST_CASE("find_all", "[algorithm]")
const auto big_nums = detail::find_all(nums.begin(), nums.end(), is_big);
REQUIRE(big_nums.empty());

REQUIRE(detail::find_all(nums.begin(), nums.end(), always_true).size() == nums.size());
REQUIRE(detail::find_all(nums.begin(), nums.end(), always_false).size() == 0);
REQUIRE(detail::find_all(nums.begin(), nums.end(), always_true).size() == nums.size());
REQUIRE(detail::find_all(nums.begin(), nums.end(), always_false).empty());
}

TEST_CASE("find_indices", "[algorithm]")
Expand Down
12 changes: 3 additions & 9 deletions test/unit/functional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,15 @@ TEST_CASE("map", "[functional]")
const auto res = map(nums, [](double n) { return n + 1.5; });
REQUIRE(res == std::vector{ 1.5, 2.7, 6.5, 4.0 });

REQUIRE(map(std::vector<int>{}, std::identity{}) == std::vector<int>{});
REQUIRE(map(std::vector<int>{}, std::identity{}).empty());
}

TEST_CASE("flatten", "[functional]")
{
std::vector<std::pair<int, int>> num_pairs = { { 0, 1 }, { 1, 3 }, { 5, 2 }};

SECTION("lvalue")
{
REQUIRE(flatten(num_pairs) == std::vector{ 0, 1, 1, 3, 5, 2 });
}
SECTION("rvalue")
{
REQUIRE(flatten(std::move(num_pairs)) == std::vector{ 0, 1, 1, 3, 5, 2 });
}
REQUIRE(flatten(num_pairs) == std::vector{ 0, 1, 1, 3, 5, 2 });
REQUIRE(flatten(std::move(num_pairs)) == std::vector{ 0, 1, 1, 3, 5, 2 });
}

TEST_CASE("arithmetic_funcs", "[functional]")
Expand Down
2 changes: 1 addition & 1 deletion test/unit/math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ TEST_CASE("normalize", "[math]")
REQUIRE_THAT(normalizeVector(vec), Matchers::Approx(normalized_vec).margin(0.01));
REQUIRE_THAT(normalizeVector(normalized_vec), Matchers::Approx(normalized_vec).margin(0.01));

REQUIRE(normalizeVector({}) == std::vector<double>{});
REQUIRE(normalizeVector({}).empty());
}

TEST_CASE("euclidean_distance", "[math]")
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class DummyFitnessFunction final : public FitnessFunctionBase<T>
explicit DummyFitnessFunction(size_t chrom_len, size_t nobj = 1, bool var_len = false, bool dynamic = false) :
FitnessFunctionBase<T>(chrom_len, var_len, dynamic), nobj_(nobj) {}
private:
FitnessVector invoke(const Chromosome<T>&) const override { return std::vector(nobj_, 0.0); }
FitnessVector invoke(const Chromosome<T>&) const override { return FitnessVector(nobj_, 0.0); }
size_t nobj_;
};

Expand Down

0 comments on commit 74c6516

Please sign in to comment.