summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.clang-tidy1
-rw-r--r--src/buildtool/build_engine/expression/evaluator.hpp14
-rw-r--r--src/buildtool/storage/garbage_collector.cpp5
-rw-r--r--src/other_tools/just_mr/launch.cpp4
-rw-r--r--src/utils/cpp/atomic.hpp13
-rw-r--r--src/utils/cpp/type_safe_arithmetic.hpp2
-rw-r--r--test/utils/container_matchers.hpp2
7 files changed, 25 insertions, 16 deletions
diff --git a/.clang-tidy b/.clang-tidy
index 984745a8..9f13baa6 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -7,6 +7,7 @@ WarningsAsErrors: >-
clang-diagnostic-*,-clang-diagnostic-unused-command-line-argument,
concurrency-*, -concurrency-mt-unsafe,
hicpp-*,
+ modernize-*,-modernize-return-braced-init-list,
performance-*,-performance-avoid-endl,
portability-*,
CheckOptions:
diff --git a/src/buildtool/build_engine/expression/evaluator.hpp b/src/buildtool/build_engine/expression/evaluator.hpp
index 726df568..ba9bd2ef 100644
--- a/src/buildtool/build_engine/expression/evaluator.hpp
+++ b/src/buildtool/build_engine/expression/evaluator.hpp
@@ -44,18 +44,20 @@ class Evaluator {
class EvaluationError : public std::exception {
public:
- explicit EvaluationError(std::string const& msg,
+ explicit EvaluationError(std::string msg,
bool while_eval = false,
bool user_context = false,
std::vector<ExpressionPtr> involved_objetcs =
std::vector<ExpressionPtr>{}) noexcept
- : msg_{(while_eval ? ""
- : (user_context ? "UserError: "
- : "EvaluationError: ")) +
- msg},
+ : msg_{std::move(msg)},
while_eval_{while_eval},
user_context_{user_context},
- involved_objects_{std::move(std::move(involved_objetcs))} {}
+ involved_objects_{std::move(std::move(involved_objetcs))} {
+ if (not while_eval_) {
+ msg_ = (user_context_ ? "UserError: " : "EvaluationError: ") +
+ msg_;
+ }
+ }
[[nodiscard]] auto what() const noexcept -> char const* final {
return msg_.c_str();
}
diff --git a/src/buildtool/storage/garbage_collector.cpp b/src/buildtool/storage/garbage_collector.cpp
index 817e5240..6f41dcd8 100644
--- a/src/buildtool/storage/garbage_collector.cpp
+++ b/src/buildtool/storage/garbage_collector.cpp
@@ -89,7 +89,8 @@ auto GarbageCollector::TriggerGarbageCollection(
for (auto const& entry :
std::filesystem::directory_iterator(storage_config.CacheRoot())) {
- if (entry.path().filename().string().find(remove_me_prefix) == 0) {
+ if (entry.path().filename().string().starts_with(
+ remove_me_prefix)) {
to_remove.emplace_back(entry.path());
}
}
@@ -120,7 +121,7 @@ auto GarbageCollector::TriggerGarbageCollection(
std::vector<std::filesystem::path> left_over{};
for (auto const& entry :
std::filesystem::directory_iterator(storage_config.CacheRoot())) {
- if (entry.path().filename().string().find(kRemoveMe) == 0) {
+ if (entry.path().filename().string().starts_with(kRemoveMe)) {
left_over.emplace_back(entry.path());
}
}
diff --git a/src/other_tools/just_mr/launch.cpp b/src/other_tools/just_mr/launch.cpp
index ccebd966..16429864 100644
--- a/src/other_tools/just_mr/launch.cpp
+++ b/src/other_tools/just_mr/launch.cpp
@@ -138,13 +138,13 @@ auto CallJust(std::optional<std::filesystem::path> const& config_file,
if (log_args.log_limit and *log_args.log_limit != kDefaultLogLevel) {
cmd.emplace_back("--log-limit");
cmd.emplace_back(
- std::to_string(static_cast<std::underlying_type<LogLevel>::type>(
+ std::to_string(static_cast<std::underlying_type_t<LogLevel>>(
*log_args.log_limit)));
}
if (log_args.restrict_stderr_log_limit) {
cmd.emplace_back("--restrict-stderr-log-limit");
cmd.emplace_back(
- std::to_string(static_cast<std::underlying_type<LogLevel>::type>(
+ std::to_string(static_cast<std::underlying_type_t<LogLevel>>(
*log_args.restrict_stderr_log_limit)));
}
if (log_args.plain_log) {
diff --git a/src/utils/cpp/atomic.hpp b/src/utils/cpp/atomic.hpp
index 4ef7e40c..b610a350 100644
--- a/src/utils/cpp/atomic.hpp
+++ b/src/utils/cpp/atomic.hpp
@@ -18,6 +18,7 @@
#include <atomic>
#include <condition_variable>
#include <shared_mutex>
+#include <type_traits>
#include <utility> // std::move
// Atomic wrapper with notify/wait capabilities.
@@ -51,22 +52,26 @@ class atomic {
return value_.load(order);
}
- template <class U = T, class = std::enable_if_t<std::is_integral_v<U>>>
+ template <class U = T>
+ requires(std::is_integral_v<U>)
auto operator++() -> T {
std::shared_lock lock(mutex_);
return ++value_;
}
- template <class U = T, class = std::enable_if_t<std::is_integral_v<U>>>
+ template <class U = T>
+ requires(std::is_integral_v<U>)
[[nodiscard]] auto operator++(int) -> T {
std::shared_lock lock(mutex_);
return value_++;
}
- template <class U = T, class = std::enable_if_t<std::is_integral_v<U>>>
+ template <class U = T>
+ requires(std::is_integral_v<U>)
auto operator--() -> T {
std::shared_lock lock(mutex_);
return --value_;
}
- template <class U = T, class = std::enable_if_t<std::is_integral_v<U>>>
+ template <class U = T>
+ requires(std::is_integral_v<U>)
[[nodiscard]] auto operator--(int) -> T {
std::shared_lock lock(mutex_);
return value_--;
diff --git a/src/utils/cpp/type_safe_arithmetic.hpp b/src/utils/cpp/type_safe_arithmetic.hpp
index be2ca405..690e9a86 100644
--- a/src/utils/cpp/type_safe_arithmetic.hpp
+++ b/src/utils/cpp/type_safe_arithmetic.hpp
@@ -30,7 +30,7 @@ template <typename T,
T MAX_VALUE = std::numeric_limits<T>::max(),
T SMALLEST_VALUE = std::numeric_limits<T>::min()>
struct type_safe_arithmetic_tag {
- static_assert(std::is_arithmetic<T>::value,
+ static_assert(std::is_arithmetic_v<T>,
"T must be an arithmetic type (integer or floating-point)");
using value_t = T;
diff --git a/test/utils/container_matchers.hpp b/test/utils/container_matchers.hpp
index 35a334e3..7def6d57 100644
--- a/test/utils/container_matchers.hpp
+++ b/test/utils/container_matchers.hpp
@@ -43,7 +43,7 @@ class UniqueElementsUnorderedMatcher
using value_type = typename LeftContainer::value_type;
using T = value_type;
static_assert(
- std::is_constructible<T, typename RightContainer::value_type>::value,
+ std::is_constructible_v<T, typename RightContainer::value_type>,
"Value type of container in the left hand side must be constructible "
"from that of the right hand side.");