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

Apply some clang-tidy 18 fixes #2762

Merged
merged 40 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2e82fe8
Try out ubuntu-24.04
louwers Aug 23, 2024
e079c64
make unordered_dense SYSTEM dependency
louwers Aug 24, 2024
20528b4
remove unused variable
louwers Aug 24, 2024
9186927
remove unused variables
louwers Aug 24, 2024
96a5260
add maybe_unused
louwers Aug 24, 2024
3333e44
Use requires in EstablishedActor
louwers Aug 24, 2024
fab6ab6
Use requires in context.hpp
louwers Aug 24, 2024
1c61517
Clean up unimplemented methods
louwers Aug 24, 2024
6544f79
Use requires in shader.hpp
louwers Aug 24, 2024
18e3e7c
Use requires in shader_group.hpp
louwers Aug 24, 2024
8db5bd3
Use requires in uniform_buffer.hpp
louwers Aug 24, 2024
a042a25
use C++14 enable_if_t
louwers Aug 24, 2024
390f1e1
Use requires in minmax.hpp
louwers Aug 24, 2024
98889b4
use requires in expression.hpp
louwers Aug 24, 2024
b97048f
remove redundant override
louwers Aug 24, 2024
35c82ea
simplify ternary expression
louwers Aug 24, 2024
e14185d
use C++17 is_enum_v
louwers Aug 24, 2024
7dcc300
use requires in chrono.hpp
louwers Aug 24, 2024
6f4e391
use requires in convert.hpp
louwers Aug 24, 2024
3eaf3c5
remove redundant inline
louwers Aug 24, 2024
25ce033
update traits.hpp
louwers Aug 24, 2024
7c552dc
remove return in void function
louwers Aug 24, 2024
980f96a
use anonymous namespace instead of static
louwers Aug 24, 2024
678ff5d
use anonymous namespace instead of static
louwers Aug 24, 2024
a446fde
make move after free look less bad
louwers Aug 24, 2024
61be69b
remove redundant cast
louwers Aug 24, 2024
0d5f6df
use sqrt_2_v
louwers Aug 24, 2024
182ad90
don't unpack optional
louwers Aug 24, 2024
2d09cc3
use anonymous namespace instead of static
louwers Aug 24, 2024
83b0f51
remove unused include
louwers Aug 24, 2024
2787849
remove unused include
louwers Aug 24, 2024
e55db49
remove unused include
louwers Aug 24, 2024
ad0d360
use sqrt3_v
louwers Aug 24, 2024
4bfebd2
remove unused includes
louwers Aug 24, 2024
c321732
use C++17 is_integral_v
louwers Aug 24, 2024
0a307fb
remove redundant inlines
louwers Aug 24, 2024
7615459
remove redundant inline
louwers Aug 24, 2024
16d9e65
Revert "Try out ubuntu-24.04"
louwers Aug 24, 2024
f9323eb
revert anon namespace _normalizeAngle
louwers Aug 24, 2024
cff5a73
Fix SYSTEM with add_subdirectory CMake version
louwers Aug 24, 2024
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
12 changes: 1 addition & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1437,21 +1437,11 @@ include(${PROJECT_SOURCE_DIR}/vendor/polylabel.cmake)
include(${PROJECT_SOURCE_DIR}/vendor/protozero.cmake)
include(${PROJECT_SOURCE_DIR}/vendor/tracy.cmake)
include(${PROJECT_SOURCE_DIR}/vendor/unique_resource.cmake)
include(${PROJECT_SOURCE_DIR}/vendor/unordered_dense.cmake)
include(${PROJECT_SOURCE_DIR}/vendor/vector-tile.cmake)
include(${PROJECT_SOURCE_DIR}/vendor/wagyu.cmake)
include(${PROJECT_SOURCE_DIR}/vendor/metal-cpp.cmake)


add_subdirectory(${PROJECT_SOURCE_DIR}/vendor/unordered_dense)
set_target_properties(
unordered_dense
PROPERTIES
INTERFACE_MAPBOX_NAME "unordered_dense"
INTERFACE_MAPBOX_URL "https://github.com/martinus/unordered_dense"
INTERFACE_MAPBOX_AUTHOR "Martin Leitner-Ankerl"
INTERFACE_MAPBOX_LICENSE ${PROJECT_SOURCE_DIR}/vendor/unordered_dense/LICENSE
)

target_link_libraries(
mbgl-core
PRIVATE
Expand Down
6 changes: 2 additions & 4 deletions include/mbgl/actor/established_actor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ template <class Object>
class EstablishedActor {
public:
// Construct the Object from a parameter pack `args` (i.e. `Object(args...)`)
template <typename U = Object,
class... Args,
typename std::enable_if_t<std::is_constructible_v<U, Args...> ||
std::is_constructible_v<U, ActorRef<U>, Args...>>* = nullptr>
template <typename U = Object, class... Args>
EstablishedActor(Scheduler& scheduler, AspiringActor<Object>& parent_, Args&&... args)
requires(std::is_constructible_v<U, Args...> || std::is_constructible_v<U, ActorRef<U>, Args...>)
: parent(parent_) {
emplaceObject(std::forward<Args>(args)...);
parent.mailbox->open(scheduler);
Expand Down
6 changes: 3 additions & 3 deletions include/mbgl/gfx/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ class Context {

/// `emplaceOrUpdateUniformBuffer` with type inference
template <typename T>
std::enable_if_t<!std::is_pointer_v<T>, bool> emplaceOrUpdateUniformBuffer(gfx::UniformBufferPtr& ptr,
const T* data,
bool persistent = false) {
bool emplaceOrUpdateUniformBuffer(gfx::UniformBufferPtr& ptr, const T* data, bool persistent = false)
requires(!std::is_pointer_v<T>)
{
return emplaceOrUpdateUniformBuffer(ptr, data, sizeof(T), persistent);
}

Expand Down
6 changes: 4 additions & 2 deletions include/mbgl/gfx/shader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ class Shader {
/// @brief Downcast to a type
/// @tparam T Derived type
/// @return Type or nullptr if type info was not a match
template <typename T, typename std::enable_if_t<is_shader_v<T>, bool>* = nullptr>
T* to() noexcept {
template <typename T>
T* to() noexcept
requires(is_shader_v<T>)
{
if (typeName() != T::Name) {
return nullptr;
}
Expand Down
6 changes: 4 additions & 2 deletions include/mbgl/gfx/shader_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ class ShaderGroup {
/// This variant looks up shaders only by type name.
/// @tparam T Derived type, inheriting `gfx::Shader`
/// @return T or nullptr if not found in the group
template <typename T, typename std::enable_if_t<is_shader_v<T>, bool>* = nullptr>
std::shared_ptr<T> get() noexcept {
template <typename T>
std::shared_ptr<T> get() noexcept
requires(is_shader_v<T>)
{
auto shader = getShader(std::string(T::Name));
if (!shader || shader->typeName() != T::Name) {
return nullptr;
Expand Down
7 changes: 3 additions & 4 deletions include/mbgl/gfx/uniform_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ class UniformBufferArray {
void createOrUpdate(const size_t id, const std::vector<uint8_t>& data, gfx::Context&, bool persistent = false);
void createOrUpdate(const size_t id, const void* data, std::size_t size, gfx::Context&, bool persistent = false);
template <typename T>
std::enable_if_t<!std::is_pointer_v<T>> createOrUpdate(const size_t id,
const T* data,
gfx::Context& context,
bool persistent = false) {
void createOrUpdate(const size_t id, const T* data, gfx::Context& context, bool persistent = false)
requires(!std::is_pointer_v<T>)
{
createOrUpdate(id, data, sizeof(T), context, persistent);
}

Expand Down
6 changes: 3 additions & 3 deletions include/mbgl/gfx/vertex_attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,12 @@ class VertexAttribute {
}

template <std::size_t I = 0, typename... Tp>
inline typename std::enable_if<I == sizeof...(Tp), void>::type set(std::size_t, std::tuple<Tp...>, std::size_t) {}
inline typename std::enable_if_t<I == sizeof...(Tp), void> set(std::size_t, std::tuple<Tp...>, std::size_t) {}

/// Set item value
template <std::size_t I = 0, typename... Tp>
inline typename std::enable_if <
I<sizeof...(Tp), void>::type set(std::size_t i, std::tuple<Tp...> tuple, std::size_t tupleIndex) {
inline typename std::enable_if_t <
I<sizeof...(Tp), void> set(std::size_t i, std::tuple<Tp...> tuple, std::size_t tupleIndex) {
if (tupleIndex == 0) {
set(i, std::get<I>(tuple).a1);
} else {
Expand Down
24 changes: 18 additions & 6 deletions include/mbgl/math/minmax.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,44 @@ namespace mbgl {
namespace util {

template <typename T>
typename std::enable_if_t<std::is_integral_v<T>, T> max(T a, T b) {
T max(T a, T b)
requires(std::is_integral_v<T>)
{
return std::max(a, b);
}

template <typename T>
typename std::enable_if_t<std::is_floating_point_v<T>, T> max(T a, T b) {
T max(T a, T b)
requires(std::is_floating_point_v<T>)
{
return ::fmax(a, b);
}

template <typename T, typename... Ts>
typename std::enable_if_t<std::is_arithmetic_v<T>, T> max(T a, T b, Ts... args) {
T max(T a, T b, Ts... args)
requires(std::is_arithmetic_v<T>)
{
return max(a, max(b, args...));
}

template <typename T>
typename std::enable_if_t<std::is_integral_v<T>, T> min(T a, T b) {
T min(T a, T b)
requires(std::is_integral_v<T>)
{
return std::min(a, b);
}

template <typename T>
typename std::enable_if_t<std::is_floating_point_v<T>, T> min(T a, T b) {
T min(T a, T b)
requires(std::is_floating_point_v<T>)
{
return ::fmin(a, b);
}

template <typename T, typename... Ts>
typename std::enable_if_t<std::is_arithmetic_v<T>, T> min(T a, T b, Ts... args) {
T min(T a, T b, Ts... args)
requires(std::is_arithmetic_v<T>)
{
return min(a, min(b, args...));
}

Expand Down
12 changes: 8 additions & 4 deletions include/mbgl/style/expression/expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,11 @@ class Expression {
return *lhs == *rhs;
}

template <typename T, typename = std::enable_if_t<std::is_scalar_v<T>>>
template <typename T>
static bool childEqual(const std::pair<T, std::unique_ptr<Expression>>& lhs,
const std::pair<T, std::unique_ptr<Expression>>& rhs) noexcept {
const std::pair<T, std::unique_ptr<Expression>>& rhs) noexcept
requires(std::is_scalar_v<T>)
{
return lhs.first == rhs.first && *(lhs.second) == *(rhs.second);
}

Expand All @@ -294,9 +296,11 @@ class Expression {
return lhs.first == rhs.first && *(lhs.second) == *(rhs.second);
}

template <typename T, typename = std::enable_if_t<!std::is_scalar_v<T>>>
template <typename T>
static bool childEqual(const std::pair<T, std::shared_ptr<Expression>>& lhs,
const std::pair<T, std::shared_ptr<Expression>>& rhs) noexcept {
const std::pair<T, std::shared_ptr<Expression>>& rhs) noexcept
requires(!std::is_scalar_v<T>)
{
#if __clang_major__ > 16
// On older compilers, this assignment doesn't do overload resolution
// in the same way that `lhs==rhs` does and produces ambiguity errors.
Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/style/expression/format_section_override.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class FormatSectionOverride final : public Expression {
defaultValue.match([&fn](const style::PropertyExpression<T>& e) { fn(e.getExpression()); }, [](const T&) {});
}

bool operator==(const Expression& e) const final override {
bool operator==(const Expression& e) const final {
if (e.getKind() == Kind::FormatSectionOverride) {
const auto* other = static_cast<const FormatSectionOverride*>(&e);

Expand Down
4 changes: 3 additions & 1 deletion include/mbgl/style/property_expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ class PropertyExpression final : public PropertyExpressionBase {
const expression::EvaluationResult result = expression->evaluate(context);
if (result) {
const std::optional<T> typed = expression::fromExpressionValue<T>(*result);
return typed ? *typed : defaultValue ? *defaultValue : finalDefaultValue;
if (typed) {
return *typed;
}
}
return defaultValue ? *defaultValue : finalDefaultValue;
}
Expand Down
8 changes: 4 additions & 4 deletions include/mbgl/util/bitmask_operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ namespace mbgl {

template <typename Enum>
constexpr Enum operator|(Enum a, Enum b) {
static_assert(std::is_enum<Enum>::value, "Enum must be an enum type");
static_assert(std::is_enum_v<Enum>, "Enum must be an enum type");
return Enum(mbgl::underlying_type(a) | mbgl::underlying_type(b));
}

template <typename Enum>
constexpr Enum& operator|=(Enum& a, Enum b) {
static_assert(std::is_enum<Enum>::value, "Enum must be an enum type");
static_assert(std::is_enum_v<Enum>, "Enum must be an enum type");
return (a = a | b);
}

template <typename Enum>
constexpr bool operator&(Enum a, Enum b) {
static_assert(std::is_enum<Enum>::value, "Enum must be an enum type");
static_assert(std::is_enum_v<Enum>, "Enum must be an enum type");
return bool(mbgl::underlying_type(a) & mbgl::underlying_type(b));
}

template <typename Enum>
constexpr Enum operator~(Enum value) {
static_assert(std::is_enum<Enum>::value, "Enum must be an enum type");
static_assert(std::is_enum_v<Enum>, "Enum must be an enum type");
return Enum(~mbgl::underlying_type(value));
}

Expand Down
9 changes: 4 additions & 5 deletions include/mbgl/util/chrono.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ _NODISCARD constexpr std::chrono::duration<_Rep, _Period> abs(const std::chrono:
: _Dur;
}
#else
template <
class Rep,
class Period,
class = std::enable_if_t<std::chrono::duration<Rep, Period>::min() < std::chrono::duration<Rep, Period>::zero()>>
constexpr std::chrono::duration<Rep, Period> abs(std::chrono::duration<Rep, Period> d) {
template <class Rep, class Period>
constexpr std::chrono::duration<Rep, Period> abs(std::chrono::duration<Rep, Period> d)
requires(std::chrono::duration<Rep, Period>::min() < std::chrono::duration<Rep, Period>::zero())
{
return d >= d.zero() ? d : -d;
}
#endif
Expand Down
12 changes: 8 additions & 4 deletions include/mbgl/util/convert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@
namespace mbgl {
namespace util {

template <typename To, typename From, std::size_t Size, typename = std::enable_if_t<std::is_convertible_v<From, To>>>
constexpr std::array<To, Size> convert(const std::array<From, Size>& from) {
template <typename To, typename From, std::size_t Size>
constexpr std::array<To, Size> convert(const std::array<From, Size>& from)
requires(std::is_convertible_v<From, To>)
{
std::array<To, Size> to{{}};
std::copy(std::begin(from), std::end(from), std::begin(to));
return to;
}

template <typename To, typename From, std::size_t Size, typename = std::enable_if_t<std::is_assignable_v<To&, From>>>
constexpr std::array<To, Size> cast(const std::array<From, Size>& from) {
template <typename To, typename From, std::size_t Size>
constexpr std::array<To, Size> cast(const std::array<From, Size>& from)
requires(std::is_assignable_v<To&, From>)
{
std::array<To, Size> to{{}};
std::transform(std::begin(from), std::end(from), std::begin(to), [](From x) { return static_cast<To>(x); });
return to;
Expand Down
4 changes: 2 additions & 2 deletions include/mbgl/util/size.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class Size {
uint32_t height = 0;
};

constexpr inline bool operator==(const Size& a, const Size& b) noexcept {
constexpr bool operator==(const Size& a, const Size& b) noexcept {
return a.width == b.width && a.height == b.height;
}

constexpr inline bool operator!=(const Size& a, const Size& b) noexcept {
constexpr bool operator!=(const Size& a, const Size& b) noexcept {
return !(a == b);
}

Expand Down
9 changes: 4 additions & 5 deletions include/mbgl/util/traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ struct is_utf16char_like<uint16_t> : std::true_type {};

template <typename T>
using is_utf16char_like_pointer =
std::integral_constant<bool,
std::is_pointer_v<T> && is_utf16char_like<typename std::remove_pointer<T>::type>::value>;
std::integral_constant<bool, std::is_pointer_v<T> && is_utf16char_like<std::remove_pointer_t<T>>::value>;

template <class OutPointer, class InChar>
typename std::enable_if<is_utf16char_like<InChar>::value && is_utf16char_like_pointer<OutPointer>::value,
OutPointer>::type
utf16char_cast(InChar *in) {
OutPointer utf16char_cast(InChar *in)
requires(is_utf16char_like<InChar>::value && is_utf16char_like_pointer<OutPointer>::value)
{
return reinterpret_cast<OutPointer>(in);
}

Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/actor/mailbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Mailbox::Mailbox(const TaggedScheduler& scheduler_)
void Mailbox::open(const TaggedScheduler& scheduler_) {
assert(!weakScheduler);
schedulerTag = scheduler_.tag;
return open(*scheduler_.get());
open(*scheduler_.get());
}

void Mailbox::open(Scheduler& scheduler_) {
Expand Down
4 changes: 3 additions & 1 deletion src/mbgl/actor/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ std::function<void()> Scheduler::bindOnce(std::function<void()> fn) {
};
}

static auto& current() {
namespace {
auto& current() {
static util::ThreadLocal<Scheduler> scheduler;
return scheduler;
}
} // namespace

void Scheduler::SetCurrent(Scheduler* scheduler) {
current().set(scheduler);
Expand Down
6 changes: 5 additions & 1 deletion src/mbgl/annotation/annotation_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,16 @@ void AnnotationManager::removeTile(AnnotationTile& tile) {
tiles.erase(&tile);
}

namespace {

// To ensure that annotation images do not collide with images from the style,
// we prefix input image IDs with "org.maplibre.annotations".
static std::string prefixedImageID(const std::string& id) {
std::string prefixedImageID(const std::string& id) {
return AnnotationManager::SourceID + "." + id;
}

} // namespace

void AnnotationManager::addImage(std::unique_ptr<style::Image> image) {
CHECK_ANNOTATIONS_ENABLED_AND_RETURN_NOARG();
std::lock_guard<std::mutex> lock(mutex);
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/gfx/vertex_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class VertexVector final : public VertexVectorBase {
: VertexVectorBase(other),
v(other.v) {}
VertexVector(VertexVector<V>&& other)
: VertexVectorBase(std::move(other)),
: VertexVectorBase(static_cast<VertexVectorBase&&>(other)),
v(std::move(other.v)) {}
~VertexVector() override = default;

Expand Down
6 changes: 3 additions & 3 deletions src/mbgl/layout/symbol_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,15 @@ const std::optional<SymbolQuads>& SymbolInstance::iconQuads() const {
}

bool SymbolInstance::hasText() const {
return static_cast<bool>(symbolContent & SymbolContent::Text);
return symbolContent & SymbolContent::Text;
}

bool SymbolInstance::hasIcon() const {
return static_cast<bool>(symbolContent & SymbolContent::IconRGBA) || hasSdfIcon();
return symbolContent & SymbolContent::IconRGBA || hasSdfIcon();
}

bool SymbolInstance::hasSdfIcon() const {
return static_cast<bool>(symbolContent & SymbolContent::IconSDF);
return symbolContent & SymbolContent::IconSDF;
}

const std::optional<SymbolQuads>& SymbolInstance::verticalIconQuads() const {
Expand Down
3 changes: 1 addition & 2 deletions src/mbgl/layout/symbol_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,7 @@ std::array<float, 2> evaluateRadialOffset(style::SymbolAnchorType anchor, float
std::array<float, 2> result{{0.0f, 0.0f}};
if (radialOffset < 0.0f) radialOffset = 0.0f; // Ignore negative offset.
// solve for r where r^2 + r^2 = radialOffset^2
const float sqrt2 = 1.41421356237f;
const float hypotenuse = radialOffset / sqrt2;
const float hypotenuse = radialOffset / std::numbers::sqrt2_v<float>;

switch (anchor) {
case SymbolAnchorType::TopRight:
Expand Down
Loading
Loading