Skip to content

Commit

Permalink
Add a .clang-tidy file
Browse files Browse the repository at this point in the history
Fix some of the clang-tidy diagnostics, mute a few specific ones. Try to
consider Catch2 headers as system headers to make cang-tidy generate
fewer warnings.
  • Loading branch information
Morwenn committed Nov 5, 2023
1 parent 0ef16f2 commit a2c6b6a
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 11 deletions.
13 changes: 13 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2023 Morwenn
# SPDX-License-Identifier: MIT

# Disabled:
# -modernize-avoid-c-arrays: C arrays are cool enough
Checks: >
-*,
bugprone-*,
clang-analyzer-*,
modernize-*,
performance-*,
portability-*,
-modernize-avoid-c-arrays
4 changes: 4 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ else()
)
add_subdirectory(${Catch2_SOURCE_DIR} ${Catch2_BINARY_DIR})
list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/extras)

# Make Catch2::Catch2 a SYSTEM target
get_target_property(Catch2_INCLUDE_DIRECTORY Catch2 INTERFACE_INCLUDE_DIRECTORIES)
set_target_properties(Catch2 PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${Catch2_INCLUDE_DIRECTORY}")
endif()
include(Catch)

Expand Down
2 changes: 1 addition & 1 deletion tests/adapters/mixed_adapters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ TEST_CASE( "stable_t<hybrid_adapter>", "[stable_adapter][hybrid_adapter]" )
using stable_sorter_t = cppsort::stable_t<sorter_t>;

sorter_t sorter;
stable_sorter_t stable_sorter(std::move(sorter));
stable_sorter_t stable_sorter(sorter);
(void)stable_sorter;

CHECK( true );
Expand Down
9 changes: 8 additions & 1 deletion tests/sorters/ska_sorter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017-2022 Morwenn
* Copyright (c) 2017-2023 Morwenn
* SPDX-License-Identifier: MIT
*/
#include <algorithm>
Expand All @@ -23,6 +23,7 @@ TEST_CASE( "ska_sorter tests", "[ska_sorter]" )
SECTION( "sort with int iterable" )
{
std::vector<int> vec;
vec.reserve(100'000);
distribution(std::back_inserter(vec), 100'000);
cppsort::ska_sort(vec);
CHECK( std::is_sorted(vec.begin(), vec.end()) );
Expand All @@ -31,6 +32,7 @@ TEST_CASE( "ska_sorter tests", "[ska_sorter]" )
SECTION( "sort with unsigned int iterators" )
{
std::vector<unsigned> vec;
vec.reserve(100'000);
distribution(std::back_inserter(vec), 100'000);
cppsort::ska_sort(vec.begin(), vec.end());
CHECK( std::is_sorted(vec.begin(), vec.end()) );
Expand All @@ -40,6 +42,7 @@ TEST_CASE( "ska_sorter tests", "[ska_sorter]" )
SECTION( "sort with int128 iterable" )
{
std::vector<__int128_t> vec;
vec.reserve(100'000);
distribution(std::back_inserter(vec), 100'000, -10'000);
cppsort::ska_sort(vec);
CHECK( std::is_sorted(vec.begin(), vec.end()) );
Expand All @@ -48,6 +51,7 @@ TEST_CASE( "ska_sorter tests", "[ska_sorter]" )
SECTION( "sort with unsigned int128 iterable" )
{
std::vector<__uint128_t> vec;
vec.reserve(100'000);
distribution(std::back_inserter(vec), 100'000);
cppsort::ska_sort(vec);
CHECK( std::is_sorted(vec.begin(), vec.end()) );
Expand All @@ -57,6 +61,7 @@ TEST_CASE( "ska_sorter tests", "[ska_sorter]" )
SECTION( "sort with float iterable" )
{
std::vector<float> vec;
vec.reserve(100'000);
distribution.call<float>(std::back_inserter(vec), 100'000);
cppsort::ska_sort(vec);
CHECK( std::is_sorted(vec.begin(), vec.end()) );
Expand All @@ -65,6 +70,7 @@ TEST_CASE( "ska_sorter tests", "[ska_sorter]" )
SECTION( "sort with double iterators" )
{
std::vector<double> vec;
vec.reserve(100'000);
distribution.call<double>(std::back_inserter(vec), 100'000);
cppsort::ska_sort(vec.begin(), vec.end());
CHECK( std::is_sorted(vec.begin(), vec.end()) );
Expand All @@ -73,6 +79,7 @@ TEST_CASE( "ska_sorter tests", "[ska_sorter]" )
SECTION( "sort with std::string" )
{
std::vector<std::string> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.push_back(std::to_string(i));
}
Expand Down
7 changes: 6 additions & 1 deletion tests/sorters/ska_sorter_projection.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017-2022 Morwenn
* Copyright (c) 2017-2023 Morwenn
* SPDX-License-Identifier: MIT
*/
#include <algorithm>
Expand All @@ -19,6 +19,7 @@ TEST_CASE( "ska_sorter tests with projections",
SECTION( "sort with int iterable" )
{
std::vector<std::pair<int, float>> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.emplace_back(i, float(i));
}
Expand All @@ -31,6 +32,7 @@ TEST_CASE( "ska_sorter tests with projections",
SECTION( "sort with unsigned int iterators" )
{
std::vector<std::pair<unsigned, float>> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.emplace_back(i, float(i));
}
Expand All @@ -43,6 +45,7 @@ TEST_CASE( "ska_sorter tests with projections",
SECTION( "sort with float iterable" )
{
std::vector<std::pair<int, float>> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.emplace_back(i, float(i));
}
Expand All @@ -55,6 +58,7 @@ TEST_CASE( "ska_sorter tests with projections",
SECTION( "sort with double iterators" )
{
std::vector<std::pair<int, double>> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.emplace_back(i, double(i));
}
Expand All @@ -69,6 +73,7 @@ TEST_CASE( "ska_sorter tests with projections",
using wrapper = generic_wrapper<std::string>;

std::vector<wrapper> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.emplace_back(std::to_string(i));
}
Expand Down
8 changes: 7 additions & 1 deletion tests/sorters/spread_sorter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2022 Morwenn
* Copyright (c) 2015-2023 Morwenn
* SPDX-License-Identifier: MIT
*/
#include <algorithm>
Expand All @@ -18,6 +18,7 @@ TEST_CASE( "spread_sorter tests", "[spread_sorter]" )
SECTION( "sort with int iterable" )
{
std::vector<int> vec;
vec.reserve(100'000);
distribution(std::back_inserter(vec), 100'000);
cppsort::spread_sort(vec);
CHECK( std::is_sorted(vec.begin(), vec.end()) );
Expand All @@ -26,6 +27,7 @@ TEST_CASE( "spread_sorter tests", "[spread_sorter]" )
SECTION( "sort with unsigned int iterators" )
{
std::vector<unsigned> vec;
vec.reserve(100'000);
distribution(std::back_inserter(vec), 100'000);
cppsort::spread_sort(vec.begin(), vec.end());
CHECK( std::is_sorted(vec.begin(), vec.end()) );
Expand All @@ -34,6 +36,7 @@ TEST_CASE( "spread_sorter tests", "[spread_sorter]" )
SECTION( "sort with float iterable" )
{
std::vector<float> vec;
vec.reserve(100'000);
distribution.call<float>(std::back_inserter(vec), 100'000);
cppsort::spread_sort(vec);
CHECK( std::is_sorted(vec.begin(), vec.end()) );
Expand All @@ -42,6 +45,7 @@ TEST_CASE( "spread_sorter tests", "[spread_sorter]" )
SECTION( "sort with double iterators" )
{
std::vector<double> vec;
vec.reserve(100'000);
distribution.call<double>(std::back_inserter(vec), 100'000);
cppsort::spread_sort(vec.begin(), vec.end());
CHECK( std::is_sorted(vec.begin(), vec.end()) );
Expand All @@ -50,6 +54,7 @@ TEST_CASE( "spread_sorter tests", "[spread_sorter]" )
SECTION( "sort with std::string" )
{
std::vector<std::string> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.push_back(std::to_string(i));
}
Expand All @@ -66,6 +71,7 @@ TEST_CASE( "spread_sorter tests", "[spread_sorter]" )
SECTION( "reverse sort with std::string" )
{
std::vector<std::string> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.push_back(std::to_string(i));
}
Expand Down
8 changes: 7 additions & 1 deletion tests/sorters/spread_sorter_projection.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2022 Morwenn
* Copyright (c) 2016-2023 Morwenn
* SPDX-License-Identifier: MIT
*/
#include <algorithm>
Expand All @@ -19,6 +19,7 @@ TEST_CASE( "spread_sorter tests with projections",
SECTION( "sort with int iterable" )
{
std::vector<std::pair<int, float>> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.emplace_back(i, float(i));
}
Expand All @@ -31,6 +32,7 @@ TEST_CASE( "spread_sorter tests with projections",
SECTION( "sort with unsigned int iterators" )
{
std::vector<std::pair<unsigned, float>> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.emplace_back(i, float(i));
}
Expand All @@ -43,6 +45,7 @@ TEST_CASE( "spread_sorter tests with projections",
SECTION( "sort with float iterable" )
{
std::vector<std::pair<int, float>> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.emplace_back(i, float(i));
}
Expand All @@ -55,6 +58,7 @@ TEST_CASE( "spread_sorter tests with projections",
SECTION( "sort with double iterators" )
{
std::vector<std::pair<int, double>> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.emplace_back(i, double(i));
}
Expand All @@ -69,6 +73,7 @@ TEST_CASE( "spread_sorter tests with projections",
using wrapper = generic_wrapper<std::string>;

std::vector<wrapper> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.emplace_back(std::to_string(i));
}
Expand All @@ -83,6 +88,7 @@ TEST_CASE( "spread_sorter tests with projections",
using wrapper = generic_wrapper<std::string>;

std::vector<wrapper> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.emplace_back(std::to_string(i));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testing-tools/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ namespace hasard // Blame POSIX for picking the good name
//
// Returns a random integer in the range [low, high].
// See *Optimal Discrete Uniform Generation from Coin Flips,
// and Applications* by Jérémie Lumbroso
// and Applications* by Jérémie Lumbroso

template<typename Integer, typename URBG>
auto randint(Integer low, Integer high, URBG& generator)
Expand Down
4 changes: 2 additions & 2 deletions tests/utility/branchless_traits.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017-2022 Morwenn
* Copyright (c) 2017-2023 Morwenn
* SPDX-License-Identifier: MIT
*/
#include <functional>
Expand Down Expand Up @@ -85,7 +85,7 @@ TEST_CASE( "test that some specific projections are branchless",
struct foobar
{
int foo;
int bar() { return 0; }
auto bar() -> int { return 0; }
};

STATIC_CHECK( is_probably_branchless_projection_v<identity, std::string> );
Expand Down
8 changes: 5 additions & 3 deletions tests/utility/chainable_projections.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2022 Morwenn
* Copyright (c) 2020-2023 Morwenn
* SPDX-License-Identifier: MIT
*/
#include <algorithm>
Expand All @@ -20,7 +20,8 @@ namespace
struct proj1:
cppsort::utility::projection_base
{
int operator()(int value) const
auto operator()(int value) const
-> int
{
return -value;
}
Expand All @@ -29,7 +30,8 @@ namespace
struct proj2:
cppsort::utility::projection_base
{
int operator()(int value)
auto operator()(int value)
-> int
{
return -value;
}
Expand Down

0 comments on commit a2c6b6a

Please sign in to comment.