diff --git a/.clang-tidy b/.clang-tidy index ec0be49fd..bc94a61b9 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -117,7 +117,8 @@ Checks: [ -readability-math-missing-parentheses, -readability-enum-initial-value, -boost-use-ranges, - -portability-template-virtual-member-function, + -modernize-use-constraints, + -portability-template-virtual-member-function ] WarningsAsErrors: '*' HeaderFilterRegex: '.*' diff --git a/.github/workflows/linux-ci.yml b/.github/workflows/linux-ci.yml index ad44f8892..725aa3395 100644 --- a/.github/workflows/linux-ci.yml +++ b/.github/workflows/linux-ci.yml @@ -63,7 +63,7 @@ jobs: rust: false - renderer: opengl rust: true - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v4 with: diff --git a/MODULE.bazel b/MODULE.bazel index 7443a3585..117005c8c 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -97,6 +97,17 @@ use_repo(rust, "rust_toolchains") register_toolchains("@rust_toolchains//:all") +# Configure and register shell toolchains required by rules_shell. +# Fixes: "No matching toolchains found for types: @@rules_shell+//shell:toolchain_type" +sh_configure = use_extension("@rules_shell//shell/private/extensions:sh_configure.bzl", "sh_configure") +use_repo(sh_configure, "local_config_shell") + +register_toolchains("@local_config_shell//:all") + +register_toolchains( + "//bazel/tools/shell:osx_sh_toolchain_exec", +) + crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate") crate.from_cargo( name = "crates", diff --git a/bazel/tools/shell/BUILD.bazel b/bazel/tools/shell/BUILD.bazel new file mode 100644 index 000000000..bbef3ef02 --- /dev/null +++ b/bazel/tools/shell/BUILD.bazel @@ -0,0 +1,8 @@ +package(default_visibility = ["//visibility:public"]) + +toolchain( + name = "osx_sh_toolchain_exec", + exec_compatible_with = ["@platforms//os:osx"], + toolchain = "@local_config_shell//:osx_sh", + toolchain_type = "@rules_shell//shell:toolchain_type", +) diff --git a/include/mbgl/gl/vertex_attribute_gl.hpp b/include/mbgl/gl/vertex_attribute_gl.hpp index e8216b481..c0f2f2365 100644 --- a/include/mbgl/gl/vertex_attribute_gl.hpp +++ b/include/mbgl/gl/vertex_attribute_gl.hpp @@ -22,7 +22,7 @@ public: glType(other.glType) {} VertexAttributeGL(VertexAttributeGL&& other) : VertexAttribute(std::move(other)), - glType(other.glType) {} + glType(other.glType) {} // NOLINT(bugprone-use-after-move) ~VertexAttributeGL() override = default; platform::GLenum getGLType() const { return glType; } diff --git a/include/mbgl/map/mode.hpp b/include/mbgl/map/mode.hpp index 9c5219fb7..7e21fab72 100644 --- a/include/mbgl/map/mode.hpp +++ b/include/mbgl/map/mode.hpp @@ -47,10 +47,12 @@ enum class MapDebugOptions : EnumType { }; constexpr MapDebugOptions operator|(MapDebugOptions lhs, MapDebugOptions rhs) { + // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) return MapDebugOptions(mbgl::underlying_type(lhs) | mbgl::underlying_type(rhs)); } constexpr MapDebugOptions& operator|=(MapDebugOptions& lhs, MapDebugOptions rhs) { + // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) return (lhs = MapDebugOptions(mbgl::underlying_type(lhs) | mbgl::underlying_type(rhs))); } @@ -59,10 +61,12 @@ constexpr bool operator&(MapDebugOptions lhs, MapDebugOptions rhs) { } constexpr MapDebugOptions& operator&=(MapDebugOptions& lhs, MapDebugOptions rhs) { + // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) return (lhs = MapDebugOptions(mbgl::underlying_type(lhs) & mbgl::underlying_type(rhs))); } constexpr MapDebugOptions operator~(MapDebugOptions value) { + // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) return MapDebugOptions(~mbgl::underlying_type(value)); } diff --git a/include/mbgl/shaders/vulkan/shader_group.hpp b/include/mbgl/shaders/vulkan/shader_group.hpp index 818b272ae..64e32cbc9 100644 --- a/include/mbgl/shaders/vulkan/shader_group.hpp +++ b/include/mbgl/shaders/vulkan/shader_group.hpp @@ -76,7 +76,7 @@ public: using ShaderClass = shaders::ShaderSource; for (const auto& attrib : ShaderClass::attributes) { - if (!propertiesAsUniforms.second.count(attrib.id)) { + if (!propertiesAsUniforms.second.contains(attrib.id)) { shader->initAttribute(attrib); } } diff --git a/include/mbgl/util/work_task_impl.hpp b/include/mbgl/util/work_task_impl.hpp index 289ed0a76..049ac6b3e 100644 --- a/include/mbgl/util/work_task_impl.hpp +++ b/include/mbgl/util/work_task_impl.hpp @@ -2,7 +2,11 @@ #include +#include #include +#include +#include +#include namespace mbgl { @@ -17,7 +21,7 @@ public: void operator()() override { // Lock the mutex while processing so that cancel() will block. std::lock_guard lock(mutex); - if (!*canceled) { + if (!canceled->load(std::memory_order_acquire)) { invoke(std::make_index_sequence>{}); } } @@ -32,7 +36,7 @@ public: /// do nothing. void cancel() override { std::lock_guard lock(mutex); - *canceled = true; + canceled->store(true, std::memory_order_release); } private: @@ -51,7 +55,7 @@ private: template std::shared_ptr WorkTask::make(Fn&& fn, Args&&... args) { auto flag = std::make_shared>(); - *flag = false; + flag->store(false, std::memory_order_relaxed); auto tuple = std::make_tuple(std::forward(args)...); return std::make_shared, decltype(tuple)>>( diff --git a/include/mbgl/vulkan/descriptor_set.hpp b/include/mbgl/vulkan/descriptor_set.hpp index 1e3eb3f94..2202266db 100644 --- a/include/mbgl/vulkan/descriptor_set.hpp +++ b/include/mbgl/vulkan/descriptor_set.hpp @@ -78,7 +78,7 @@ protected: class UniformDescriptorSet : public DescriptorSet { public: UniformDescriptorSet(Context& context_, DescriptorSetType type_); - virtual ~UniformDescriptorSet() = default; + ~UniformDescriptorSet() override = default; void update(const gfx::UniformBufferArray& uniforms, uint32_t descriptorStartIndex, @@ -89,7 +89,7 @@ public: class ImageDescriptorSet : public DescriptorSet { public: ImageDescriptorSet(Context& context_); - virtual ~ImageDescriptorSet() = default; + ~ImageDescriptorSet() override = default; void markDirty() override; const std::chrono::duration& getLastModified() const { return lastModified; } diff --git a/include/mbgl/vulkan/renderable_resource.hpp b/include/mbgl/vulkan/renderable_resource.hpp index b9411ff64..5657246cd 100644 --- a/include/mbgl/vulkan/renderable_resource.hpp +++ b/include/mbgl/vulkan/renderable_resource.hpp @@ -102,7 +102,7 @@ class Renderable : public gfx::Renderable { protected: Renderable(const Size size_, std::unique_ptr resource_) : gfx::Renderable(size_, std::move(resource_)) {} - virtual ~Renderable() override = default; + ~Renderable() override = default; public: void setSize(const Size& size_) { size = size_; } diff --git a/include/mbgl/vulkan/renderer_backend.hpp b/include/mbgl/vulkan/renderer_backend.hpp index f1c643eaf..0d841d3fd 100644 --- a/include/mbgl/vulkan/renderer_backend.hpp +++ b/include/mbgl/vulkan/renderer_backend.hpp @@ -54,7 +54,8 @@ public: int32_t getGraphicsQueueIndex() const { return graphicsQueueIndex; } int32_t getPresentQueueIndex() const { return presentQueueIndex; } - template ::value>> + template + requires vk::isVulkanHandleType::value void setDebugName([[maybe_unused]] const T& object, [[maybe_unused]] const std::string& name) const { #ifdef ENABLE_VULKAN_VALIDATION if (!debugUtilsEnabled) return; diff --git a/include/mbgl/vulkan/uniform_buffer.hpp b/include/mbgl/vulkan/uniform_buffer.hpp index 38c867e46..6446cbf40 100644 --- a/include/mbgl/vulkan/uniform_buffer.hpp +++ b/include/mbgl/vulkan/uniform_buffer.hpp @@ -40,11 +40,11 @@ public: UniformBufferArray(UniformBufferArray&& other) noexcept : gfx::UniformBufferArray(std::move(other)), - descriptorSetType(other.descriptorSetType), - descriptorStartIndex(other.descriptorStartIndex), - descriptorStorageCount(other.descriptorStorageCount), - descriptorUniformCount(other.descriptorUniformCount), - descriptorSet(std::move(other.descriptorSet)) {} + descriptorSetType(other.descriptorSetType), // NOLINT(bugprone-use-after-move) + descriptorStartIndex(other.descriptorStartIndex), // NOLINT(bugprone-use-after-move) + descriptorStorageCount(other.descriptorStorageCount), // NOLINT(bugprone-use-after-move) + descriptorUniformCount(other.descriptorUniformCount), // NOLINT(bugprone-use-after-move) + descriptorSet(std::move(other.descriptorSet)) {} // NOLINT(bugprone-use-after-move) UniformBufferArray(const UniformBufferArray&) = delete; @@ -58,7 +58,7 @@ public: return *this; } - ~UniformBufferArray() = default; + ~UniformBufferArray() override = default; const std::shared_ptr& set(const size_t id, std::shared_ptr uniformBuffer) override; diff --git a/platform/default/src/mbgl/storage/asset_file_source.cpp b/platform/default/src/mbgl/storage/asset_file_source.cpp index 1451880aa..b805f0e22 100644 --- a/platform/default/src/mbgl/storage/asset_file_source.cpp +++ b/platform/default/src/mbgl/storage/asset_file_source.cpp @@ -13,7 +13,7 @@ namespace { bool acceptsURL(const std::string& url) { - return 0 == url.rfind(mbgl::util::ASSET_PROTOCOL, 0); + return url.starts_with(mbgl::util::ASSET_PROTOCOL); } } // namespace diff --git a/platform/default/src/mbgl/storage/local_file_source.cpp b/platform/default/src/mbgl/storage/local_file_source.cpp index 3fef8ee78..b87645b96 100644 --- a/platform/default/src/mbgl/storage/local_file_source.cpp +++ b/platform/default/src/mbgl/storage/local_file_source.cpp @@ -13,7 +13,7 @@ namespace { bool acceptsURL(const std::string& url) { - return 0 == url.rfind(mbgl::util::FILE_PROTOCOL, 0); + return url.starts_with(mbgl::util::FILE_PROTOCOL); } } // namespace diff --git a/platform/default/src/mbgl/storage/mbtiles_file_source.cpp b/platform/default/src/mbgl/storage/mbtiles_file_source.cpp index 155eaf44c..0da19d84e 100644 --- a/platform/default/src/mbgl/storage/mbtiles_file_source.cpp +++ b/platform/default/src/mbgl/storage/mbtiles_file_source.cpp @@ -29,7 +29,7 @@ namespace { bool acceptsURL(const std::string &url) { - return 0 == url.rfind(mbgl::util::MBTILES_PROTOCOL, 0); + return url.starts_with(mbgl::util::MBTILES_PROTOCOL); } std::string url_to_path(const std::string &url) { diff --git a/platform/default/src/mbgl/storage/sqlite3.cpp b/platform/default/src/mbgl/storage/sqlite3.cpp index 526898ab9..d7a93f299 100644 --- a/platform/default/src/mbgl/storage/sqlite3.cpp +++ b/platform/default/src/mbgl/storage/sqlite3.cpp @@ -113,6 +113,7 @@ void logSqlMessage(void*, const int err, const char* msg) { } #endif +// NOLINTBEGIN(misc-use-anonymous-namespace) MBGL_CONSTRUCTOR(initialize) { if (sqlite3_libversion_number() / 1000000 != SQLITE_VERSION_NUMBER / 1000000) { char message[96]; @@ -130,6 +131,7 @@ MBGL_CONSTRUCTOR(initialize) { sqlite3_config(SQLITE_CONFIG_LOG, &logSqlMessage, nullptr); #endif } +// NOLINTEND(misc-use-anonymous-namespace) std::variant Database::tryOpen(const std::string& filename, int flags) { sqlite3* db = nullptr; @@ -490,7 +492,8 @@ Transaction::~Transaction() { try { rollback(); } catch (...) { - // Ignore failed rollbacks in destructor. + // Ignore failed rollbacks in destructor, but keep the catch non-empty for analyzers. + [[maybe_unused]] auto eptr = std::current_exception(); } } } diff --git a/platform/default/src/mbgl/util/jpeg_reader.cpp b/platform/default/src/mbgl/util/jpeg_reader.cpp index 79205d611..9dc0196c4 100644 --- a/platform/default/src/mbgl/util/jpeg_reader.cpp +++ b/platform/default/src/mbgl/util/jpeg_reader.cpp @@ -19,12 +19,13 @@ struct jpeg_stream_wrapper { std::array buffer; }; -static void init_source(j_decompress_ptr cinfo) { +namespace { +void init_source(j_decompress_ptr cinfo) { auto* wrap = reinterpret_cast(cinfo->src); wrap->stream->seekg(0, std::ios_base::beg); } -static boolean fill_input_buffer(j_decompress_ptr cinfo) { +boolean fill_input_buffer(j_decompress_ptr cinfo) { auto* wrap = reinterpret_cast(cinfo->src); wrap->stream->read(reinterpret_cast(wrap->buffer.data()), BUF_SIZE); std::streamsize size = wrap->stream->gcount(); @@ -33,7 +34,7 @@ static boolean fill_input_buffer(j_decompress_ptr cinfo) { return (size > 0) ? TRUE : FALSE; } -static void skip(j_decompress_ptr cinfo, long count) { +void skip(j_decompress_ptr cinfo, long count) { if (count <= 0) return; // A zero or negative skip count should be treated as a no-op. auto* wrap = reinterpret_cast(cinfo->src); @@ -48,9 +49,9 @@ static void skip(j_decompress_ptr cinfo, long count) { } } -static void term(j_decompress_ptr) {} +void term(j_decompress_ptr) {} -static void attach_stream(j_decompress_ptr cinfo, std::istream* in) { +void attach_stream(j_decompress_ptr cinfo, std::istream* in) { if (cinfo->src == nullptr) { cinfo->src = static_cast((*cinfo->mem->alloc_small)( reinterpret_cast(cinfo), JPOOL_PERMANENT, sizeof(jpeg_stream_wrapper))); @@ -66,13 +67,14 @@ static void attach_stream(j_decompress_ptr cinfo, std::istream* in) { src->stream = in; } -static void on_error(j_common_ptr) {} +void on_error(j_common_ptr) {} -static void on_error_message(j_common_ptr cinfo) { +void on_error_message(j_common_ptr cinfo) { char buffer[JMSG_LENGTH_MAX]; (*cinfo->err->format_message)(cinfo, buffer); throw std::runtime_error(std::string("JPEG Reader: libjpeg could not read image: ") + buffer); } +} // namespace struct jpeg_info_guard { explicit jpeg_info_guard(jpeg_decompress_struct* cinfo) diff --git a/platform/default/src/mbgl/util/logging_stderr.cpp b/platform/default/src/mbgl/util/logging_stderr.cpp index 41585fb7b..6b5439044 100644 --- a/platform/default/src/mbgl/util/logging_stderr.cpp +++ b/platform/default/src/mbgl/util/logging_stderr.cpp @@ -6,7 +6,7 @@ namespace mbgl { void Log::platformRecord(EventSeverity severity, const std::string &msg) { - std::cerr << "[" << Enum::toString(severity) << "] " << msg << std::endl; + std::cerr << "[" << Enum::toString(severity) << "] " << msg << '\n'; } } // namespace mbgl diff --git a/platform/default/src/mbgl/util/monotonic_timer.cpp b/platform/default/src/mbgl/util/monotonic_timer.cpp index 55184f446..70af59cf9 100644 --- a/platform/default/src/mbgl/util/monotonic_timer.cpp +++ b/platform/default/src/mbgl/util/monotonic_timer.cpp @@ -7,15 +7,17 @@ namespace mbgl { namespace util { // Prefer high resolution timer if it is monotonic +namespace { template * = nullptr> -static T sample() { +T sample() { return std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()); } template * = nullptr> -static T sample() { +T sample() { return std::chrono::duration_cast(std::chrono::steady_clock::now().time_since_epoch()); } +} // namespace std::chrono::duration MonotonicTimer::now() { return sample>(); diff --git a/platform/default/src/mbgl/util/png_reader.cpp b/platform/default/src/mbgl/util/png_reader.cpp index d66373b96..7218e56b1 100644 --- a/platform/default/src/mbgl/util/png_reader.cpp +++ b/platform/default/src/mbgl/util/png_reader.cpp @@ -10,12 +10,14 @@ extern "C" { #include } +namespace { template -static std::string sprintf(const char* msg, Args... args) { +std::string sprintf(const char* msg, Args... args) { char res[max]; int len = snprintf(res, sizeof(res), msg, args...); return std::string(res, len); } +} // namespace const static bool png_version_check [[maybe_unused]] = []() { const png_uint_32 version = png_access_version_number(); @@ -35,15 +37,16 @@ const static bool png_version_check [[maybe_unused]] = []() { namespace mbgl { -static void user_error_fn(png_structp, png_const_charp error_msg) { +namespace { +void user_error_fn(png_structp, png_const_charp error_msg) { throw std::runtime_error(std::string("failed to read invalid png: '") + error_msg + "'"); } -static void user_warning_fn(png_structp, png_const_charp warning_msg) { +void user_warning_fn(png_structp, png_const_charp warning_msg) { Log::Warning(Event::Image, std::string("ImageReader (PNG): ") + warning_msg); } -static void png_read_data(png_structp png_ptr, png_bytep data, png_size_t length) { +void png_read_data(png_structp png_ptr, png_bytep data, png_size_t length) { auto* fin = reinterpret_cast(png_get_io_ptr(png_ptr)); fin->read(reinterpret_cast(data), length); std::streamsize read_count = fin->gcount(); @@ -51,6 +54,7 @@ static void png_read_data(png_structp png_ptr, png_bytep data, png_size_t length png_error(png_ptr, "Read Error"); } } +} // namespace struct png_struct_guard { png_struct_guard(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr) diff --git a/platform/default/src/mbgl/util/run_loop.cpp b/platform/default/src/mbgl/util/run_loop.cpp index 0076299c6..0735e56cc 100644 --- a/platform/default/src/mbgl/util/run_loop.cpp +++ b/platform/default/src/mbgl/util/run_loop.cpp @@ -35,6 +35,8 @@ struct Watch { case UV_READABLE | UV_WRITABLE: watchEvent = RunLoop::Event::ReadWrite; break; + default: + break; } watch->eventCallback(watch->fd, watchEvent); diff --git a/src/mbgl/gl/attribute.hpp b/src/mbgl/gl/attribute.hpp index d39e8789f..9dbd96343 100644 --- a/src/mbgl/gl/attribute.hpp +++ b/src/mbgl/gl/attribute.hpp @@ -8,6 +8,7 @@ #include #include #include +#include namespace mbgl { namespace gl { @@ -41,9 +42,9 @@ public: static constexpr const char* getFirstAttribName() { // Static assert that attribute list starts with position: we bind it on location 0. using TypeOfFirst = typename std::tuple_element_t<0, std::tuple>; - static_assert(std::is_same::value || - std::is_same::value || - std::is_same::value, + static_assert(std::is_same_v || + std::is_same_v || + std::is_same_v, "Program must start with position related attribute."); return concat_literals<&string_literal<'a', '_'>::value, TypeOfFirst::name>::value(); } diff --git a/src/mbgl/gl/enum.cpp b/src/mbgl/gl/enum.cpp index 23443da45..a9adb0ac6 100644 --- a/src/mbgl/gl/enum.cpp +++ b/src/mbgl/gl/enum.cpp @@ -35,8 +35,9 @@ gfx::ColorBlendEquationType Enum::from(const platfo return gfx::ColorBlendEquationType::Subtract; case GL_FUNC_REVERSE_SUBTRACT: return gfx::ColorBlendEquationType::ReverseSubtract; + default: + return {}; } - return {}; } template <> @@ -85,8 +86,9 @@ gfx::ColorBlendFactorType Enum::from(const platform:: return gfx::ColorBlendFactorType::OneMinusConstantAlpha; case GL_SRC_ALPHA_SATURATE: return gfx::ColorBlendFactorType::SrcAlphaSaturate; + default: + return {}; } - return {}; } template <> @@ -145,8 +147,9 @@ gfx::DepthFunctionType Enum::from(const platform::GLint return gfx::DepthFunctionType::GreaterEqual; case GL_ALWAYS: return gfx::DepthFunctionType::Always; + default: + return {}; } - return {}; } template <> @@ -201,8 +204,9 @@ gfx::StencilFunctionType Enum::from(const platform::GL return gfx::StencilFunctionType::GreaterEqual; case GL_ALWAYS: return gfx::StencilFunctionType::Always; + default: + return {}; } - return {}; } template <> @@ -247,8 +251,9 @@ gfx::StencilOpType Enum::from(const platform::GLint value) { return gfx::StencilOpType::DecrementWrap; case GL_INVERT: return gfx::StencilOpType::Invert; + default: + return {}; } - return {}; } template <> @@ -283,8 +288,9 @@ gfx::CullFaceSideType Enum::from(const platform::GLint va return gfx::CullFaceSideType::Back; case GL_FRONT_AND_BACK: return gfx::CullFaceSideType::FrontAndBack; + default: + return {}; } - return {}; } template <> @@ -307,8 +313,9 @@ gfx::CullFaceWindingType Enum::from(const platform::GL return gfx::CullFaceWindingType::Clockwise; case GL_CCW: return gfx::CullFaceWindingType::CounterClockwise; + default: + return {}; } - return {}; } template <> @@ -331,8 +338,9 @@ gfx::BufferUsageType Enum::from(const platform::GLint valu return gfx::BufferUsageType::StaticDraw; case GL_DYNAMIC_DRAW: return gfx::BufferUsageType::DynamicDraw; + default: + return {}; } - return {}; } template <> @@ -361,8 +369,9 @@ gfx::TexturePixelType Enum::from(const platform::GLint va return gfx::TexturePixelType::Depth; case GL_LUMINANCE: return gfx::TexturePixelType::Luminance; + default: + return {}; } - return {}; } template <> @@ -422,8 +431,9 @@ gfx::TextureChannelDataType Enum::from(const platfo return gfx::TextureChannelDataType::HalfFloat; case GL_FLOAT: return gfx::TextureChannelDataType::Float; + default: + return {}; } - return {}; } template <> @@ -448,8 +458,9 @@ gfx::RenderbufferPixelType Enum::from(const platform return gfx::RenderbufferPixelType::Depth; case GL_DEPTH24_STENCIL8: return gfx::RenderbufferPixelType::DepthStencil; + default: + return {}; } - return {}; } template <> diff --git a/src/mbgl/gl/timestamp_query_extension.cpp b/src/mbgl/gl/timestamp_query_extension.cpp index f52125d83..a986870ce 100644 --- a/src/mbgl/gl/timestamp_query_extension.cpp +++ b/src/mbgl/gl/timestamp_query_extension.cpp @@ -54,12 +54,12 @@ std::unique_ptr &singleton() { void glGenQueries(GLsizei n, GLuint *ids) { assert(singleton() && singleton()->glGenQueries); - return singleton()->glGenQueries(n, ids); + singleton()->glGenQueries(n, ids); } void glDeleteQueries(GLsizei n, const GLuint *ids) { assert(singleton() && singleton()->glDeleteQueries); - return singleton()->glDeleteQueries(n, ids); + singleton()->glDeleteQueries(n, ids); } GLboolean glIsQuery(GLuint id) { @@ -69,47 +69,47 @@ GLboolean glIsQuery(GLuint id) { void glBeginQuery(GLenum target, GLuint id) { assert(singleton() && singleton()->glBeginQuery); - return singleton()->glBeginQuery(target, id); + singleton()->glBeginQuery(target, id); } void glEndQuery(GLenum target) { assert(singleton() && singleton()->glEndQuery); - return singleton()->glEndQuery(target); + singleton()->glEndQuery(target); } void glQueryCounter(GLuint id, GLenum target) { assert(singleton() && singleton()->glQueryCounter); - return singleton()->glQueryCounter(id, target); + singleton()->glQueryCounter(id, target); } void glGetQueryiv(GLenum target, GLenum pname, GLint *params) { assert(singleton() && singleton()->glGetQueryiv); - return singleton()->glGetQueryiv(target, pname, params); + singleton()->glGetQueryiv(target, pname, params); } void glGetQueryObjectiv(GLuint id, GLenum pname, GLint *params) { assert(singleton() && singleton()->glGetQueryObjectiv); - return singleton()->glGetQueryObjectiv(id, pname, params); + singleton()->glGetQueryObjectiv(id, pname, params); } void glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint *params) { assert(singleton() && singleton()->glGetQueryObjectuiv); - return singleton()->glGetQueryObjectuiv(id, pname, params); + singleton()->glGetQueryObjectuiv(id, pname, params); } void glGetQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params) { assert(singleton() && singleton()->glGetQueryObjecti64v); - return singleton()->glGetQueryObjecti64v(id, pname, params); + singleton()->glGetQueryObjecti64v(id, pname, params); } void glGetQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params) { assert(singleton() && singleton()->glGetQueryObjectui64v); - return singleton()->glGetQueryObjectui64v(id, pname, params); + singleton()->glGetQueryObjectui64v(id, pname, params); } void glGetInteger64v(GLenum pname, GLint64 *data) { assert(singleton() && singleton()->glGetInteger64v); - return singleton()->glGetInteger64v(pname, data); + singleton()->glGetInteger64v(pname, data); } void loadTimeStampQueryExtension(const GlContexsLoader &loadExtension) { diff --git a/src/mbgl/gl/uniform.cpp b/src/mbgl/gl/uniform.cpp index 648905150..484bf7b7f 100644 --- a/src/mbgl/gl/uniform.cpp +++ b/src/mbgl/gl/uniform.cpp @@ -63,7 +63,7 @@ void bindUniform>(UniformLocation location, const std::ar template <> void bindUniform(UniformLocation location, const bool& t) { - return bindUniform(location, int32_t(t)); + bindUniform(location, int32_t(t)); } template <> diff --git a/src/mbgl/gl/upload_pass.cpp b/src/mbgl/gl/upload_pass.cpp index 1a1cec168..7f4ad62e9 100644 --- a/src/mbgl/gl/upload_pass.cpp +++ b/src/mbgl/gl/upload_pass.cpp @@ -117,15 +117,17 @@ const gfx::UniqueVertexBufferResource& UploadPass::getBuffer(const gfx::VertexVe return noBuffer; } -static std::size_t padSize(std::size_t size, std::size_t padding) { +namespace { +[[maybe_unused]] std::size_t padSize(std::size_t size, std::size_t padding) { return (padding - (size % padding)) % padding; } template -static std::size_t pad(std::vector& vector, std::size_t size, T value) { +std::size_t pad(std::vector& vector, std::size_t size, T value) { const auto count = padSize(vector.size(), size); vector.insert(vector.end(), count, value); return count; } +} // namespace gfx::AttributeBindingArray UploadPass::buildAttributeBindings( const std::size_t vertexCount, diff --git a/src/mbgl/gl/vertex_array.cpp b/src/mbgl/gl/vertex_array.cpp index 4705b8bb2..014fbbb96 100644 --- a/src/mbgl/gl/vertex_array.cpp +++ b/src/mbgl/gl/vertex_array.cpp @@ -14,7 +14,8 @@ void VertexArray::bind(Context& context, const gfx::IndexBuffer& indexBuffer, co // NOLINTNEXTLINE(bugprone-too-small-loop-variable) for (AttributeLocation location = 0; location < bindings.size(); ++location) { if (state->bindings.size() <= location) { - state->bindings.emplace_back(context, std::move(AttributeLocation(location))); + AttributeLocation loc = location; + state->bindings.emplace_back(context, std::move(loc)); } state->bindings[location] = bindings[location]; } diff --git a/src/mbgl/gl/vertex_attribute_gl.cpp b/src/mbgl/gl/vertex_attribute_gl.cpp index 4ffc2aa9c..f99d19543 100644 --- a/src/mbgl/gl/vertex_attribute_gl.cpp +++ b/src/mbgl/gl/vertex_attribute_gl.cpp @@ -72,9 +72,10 @@ int VertexAttributeGL::getStride(GLenum glType) { } } +namespace detail { // Copy the transformed type into the buffer, returning true if it works. template -static bool get(const gfx::VertexAttribute::ElementType& element, uint8_t* buffer, Func func) { +bool get(const gfx::VertexAttribute::ElementType& element, uint8_t* buffer, Func func) { if (auto* p = std::get_if(&element)) { *reinterpret_cast(buffer) = func(*p); return true; @@ -84,15 +85,16 @@ static bool get(const gfx::VertexAttribute::ElementType& element, uint8_t* buffe // Copy the value into the buffer with a simple cast, returning true if it works. template -static bool get(const gfx::VertexAttribute::ElementType& element, uint8_t* buffer) { +bool get(const gfx::VertexAttribute::ElementType& element, uint8_t* buffer) { return get(element, buffer, [](T x) -> R { return static_cast(x); }); } // Copy a particular type from the variant into the specified buffer, returning true if it works. template -static bool get(const gfx::VertexAttribute::ElementType& element, uint8_t* buffer) { +bool get(const gfx::VertexAttribute::ElementType& element, uint8_t* buffer) { return get(element, buffer, [](T x) -> T { return x; }); } +} // namespace detail template R cast(T x) { @@ -104,39 +106,39 @@ bool VertexAttributeGL::get(const gfx::VertexAttribute::ElementType& element, GL // TODO: do we need to handle unsigned inputs? switch (glType) { case GL_FLOAT: - return gl::get(element, buffer) || gl::get(element, buffer); + return detail::get(element, buffer) || detail::get(element, buffer); case GL_FLOAT_VEC2: - return gl::get(element, buffer) || - gl::get(element, buffer, [](int2 x) { return float2{(float)x[0], (float)x[1]}; }); + return detail::get(element, buffer) || + detail::get(element, buffer, [](int2 x) { return float2{(float)x[0], (float)x[1]}; }); case GL_FLOAT_VEC3: - return gl::get(element, buffer); + return detail::get(element, buffer); case GL_FLOAT_VEC4: case GL_FLOAT_MAT2: - return gl::get(element, buffer) || - gl::get( + return detail::get(element, buffer) || + detail::get( element, buffer, [](int4 x) { return float4{(float)x[0], (float)x[1], (float)x[2], (float)x[3]}; }) || - gl::get(element, buffer, [](ushort8 x) { + detail::get(element, buffer, [](ushort8 x) { return float4{(float)x[0], (float)x[1], (float)x[2], (float)x[3]}; }); case GL_INT: - return gl::get(element, buffer) || gl::get(element, buffer); + return detail::get(element, buffer) || detail::get(element, buffer); case GL_UNSIGNED_INT: - return gl::get(element, buffer) || - gl::get(element, buffer); + return detail::get(element, buffer) || + detail::get(element, buffer); case GL_INT_VEC2: - return gl::get(element, buffer) || gl::get(element, buffer, [](float2 x) { + return detail::get(element, buffer) || detail::get(element, buffer, [](float2 x) { return int2{(std::int32_t)x[0], (std::int32_t)x[1]}; }); case GL_UNSIGNED_INT_VEC2: return false; // TODO case GL_INT_VEC3: - return gl::get(element, buffer); + return detail::get(element, buffer); case GL_UNSIGNED_INT_VEC3: return false; // TODO case GL_INT_VEC4: - return gl::get(element, buffer); + return detail::get(element, buffer); case GL_UNSIGNED_INT_VEC4: return false; // TODO default: diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp index b2168a22d..219cb4641 100644 --- a/src/mbgl/layout/symbol_layout.cpp +++ b/src/mbgl/layout/symbol_layout.cpp @@ -28,11 +28,13 @@ namespace mbgl { using namespace style; namespace { + template bool has(const style::SymbolLayoutProperties::PossiblyEvaluated& layout) { return layout.get().match([](const typename Property::Type& t) { return !t.empty(); }, [](const auto&) { return true; }); } +} // namespace expression::Value sectionOptionsToValue(const SectionOptions& options) { std::unordered_map result; @@ -108,7 +110,9 @@ GlyphIDType getCharGlyphIDType(char16_t ch, return GlyphIDType::FontPBF; } -} // namespace +} // namespace mbgl + +namespace mbgl { SymbolLayout::SymbolLayout(const BucketParameters& parameters, const std::vector>& layers, diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index 72408bb6e..a16870706 100644 --- a/src/mbgl/map/transform.cpp +++ b/src/mbgl/map/transform.cpp @@ -22,7 +22,8 @@ namespace mbgl { /** Converts the given angle (in radians) to be numerically close to the anchor * angle, allowing it to be interpolated properly without sudden jumps. */ -static double _normalizeAngle(double angle, double anchorAngle) { +namespace { +double _normalizeAngle(double angle, double anchorAngle) { if (std::isnan(angle) || std::isnan(anchorAngle)) { return 0; } @@ -39,6 +40,7 @@ static double _normalizeAngle(double angle, double anchorAngle) { return angle; } +} // namespace Transform::Transform(TransformObserver& observer_, ConstrainMode constrainMode, ViewportMode viewportMode) : observer(observer_), @@ -109,7 +111,8 @@ void Transform::easeTo(const CameraOptions& inputCamera, const AnimationOptions& Duration duration = animation.duration.value_or(Duration::zero()); if (state.getLatLngBounds() == LatLngBounds() && !isGestureInProgress() && duration != Duration::zero()) { // reuse flyTo, without exaggerated animation, to achieve constant ground speed. - return flyTo(camera, animation, true); + flyTo(camera, animation, true); + return; } double zoom = camera.zoom.value_or(getZoom()); diff --git a/src/mbgl/plugin/plugin_layer_factory.cpp b/src/mbgl/plugin/plugin_layer_factory.cpp index f33fb701f..00173f0c1 100644 --- a/src/mbgl/plugin/plugin_layer_factory.cpp +++ b/src/mbgl/plugin/plugin_layer_factory.cpp @@ -5,7 +5,6 @@ #include #include -#include #include namespace mbgl { @@ -126,7 +125,7 @@ void jsonStringFromConvertible(const style::conversion::Convertible& value, std: } else if (auto s = v.value().getString()) { output.append("\""); - output.append(s->c_str()); + output.append(*s); output.append("\""); } else if (auto d = v.value().getDouble()) { diff --git a/src/mbgl/plugin/plugin_layer_impl.cpp b/src/mbgl/plugin/plugin_layer_impl.cpp index d642d4809..e52886520 100644 --- a/src/mbgl/plugin/plugin_layer_impl.cpp +++ b/src/mbgl/plugin/plugin_layer_impl.cpp @@ -46,7 +46,7 @@ void PluginLayerProperty::setCurrentSingleFloatValue(float value) { } PluginLayerProperty* PluginLayerPropertyManager::getProperty(const std::string& propertyName) { - if (_properties.count(propertyName) > 0) { + if (_properties.contains(propertyName)) { return _properties[propertyName]; } return nullptr; diff --git a/src/mbgl/plugin/plugin_layer_render.cpp b/src/mbgl/plugin/plugin_layer_render.cpp index 5021fa33f..4881529aa 100644 --- a/src/mbgl/plugin/plugin_layer_render.cpp +++ b/src/mbgl/plugin/plugin_layer_render.cpp @@ -10,12 +10,9 @@ #include #endif #include -#include #include #include -#include - using namespace mbgl; namespace mbgl { diff --git a/src/mbgl/renderer/buckets/circle_bucket.cpp b/src/mbgl/renderer/buckets/circle_bucket.cpp index 8fbb4e955..eb20face6 100644 --- a/src/mbgl/renderer/buckets/circle_bucket.cpp +++ b/src/mbgl/renderer/buckets/circle_bucket.cpp @@ -32,10 +32,11 @@ bool CircleBucket::hasData() const { return !segments.empty(); } +namespace { template -static float get(const CirclePaintProperties::PossiblyEvaluated& evaluated, - const std::string& id, - const std::map& paintPropertyBinders) { +float get(const CirclePaintProperties::PossiblyEvaluated& evaluated, + const std::string& id, + const std::map& paintPropertyBinders) { auto it = paintPropertyBinders.find(id); if (it == paintPropertyBinders.end() || !it->second.statistics().max()) { return evaluated.get().constantOr(Property::defaultValue()); @@ -43,6 +44,7 @@ static float get(const CirclePaintProperties::PossiblyEvaluated& evaluated, return *it->second.statistics().max(); } } +} // namespace float CircleBucket::getQueryRadius(const RenderLayer& layer) const { const auto& evaluated = getEvaluated(layer.evaluatedProperties); diff --git a/src/mbgl/renderer/buckets/line_bucket.cpp b/src/mbgl/renderer/buckets/line_bucket.cpp index 2ae782ea7..6777c77a8 100644 --- a/src/mbgl/renderer/buckets/line_bucket.cpp +++ b/src/mbgl/renderer/buckets/line_bucket.cpp @@ -134,10 +134,11 @@ bool LineBucket::hasData() const { return !segments.empty(); } +namespace { template -static float get(const LinePaintProperties::PossiblyEvaluated& evaluated, - const std::string& id, - const std::map& paintPropertyBinders) { +float get(const LinePaintProperties::PossiblyEvaluated& evaluated, + const std::string& id, + const std::map& paintPropertyBinders) { auto it = paintPropertyBinders.find(id); if (it == paintPropertyBinders.end() || !it->second.statistics().max()) { return evaluated.get().constantOr(Property::defaultValue()); @@ -145,6 +146,7 @@ static float get(const LinePaintProperties::PossiblyEvaluated& evaluated, return *it->second.statistics().max(); } } +} // namespace float LineBucket::getQueryRadius(const RenderLayer& layer) const { const auto& evaluated = getEvaluated(layer.evaluatedProperties); diff --git a/src/mbgl/renderer/layers/render_symbol_layer.cpp b/src/mbgl/renderer/layers/render_symbol_layer.cpp index 965b852b5..1c309f2bf 100644 --- a/src/mbgl/renderer/layers/render_symbol_layer.cpp +++ b/src/mbgl/renderer/layers/render_symbol_layer.cpp @@ -459,8 +459,9 @@ void RenderSymbolLayer::update(gfx::ShaderRegistry& shaders, const auto& getCollisionTileLayerGroup = [&] { if (!collisionTileLayerGroup) { - if ((collisionTileLayerGroup = context.createTileLayerGroup( - layerIndex, /*initialCapacity=*/64, getID() + "-collision"))) { + collisionTileLayerGroup = context.createTileLayerGroup( + layerIndex, /*initialCapacity=*/64, getID() + "-collision"); + if (collisionTileLayerGroup) { activateLayerGroup(collisionTileLayerGroup, true, changes); } } diff --git a/src/mbgl/renderer/render_layer.cpp b/src/mbgl/renderer/render_layer.cpp index a3ebff97a..e90054e01 100644 --- a/src/mbgl/renderer/render_layer.cpp +++ b/src/mbgl/renderer/render_layer.cpp @@ -131,7 +131,7 @@ void RenderLayer::addRenderPassesFromTiles() { const LayerRenderData* RenderLayer::getRenderDataForPass(const RenderTile& tile, RenderPass pass) const { if (const LayerRenderData* renderData = tile.getLayerRenderData(*baseImpl)) { - return bool(RenderPass(renderData->layerProperties->renderPasses) & pass) ? renderData : nullptr; + return (RenderPass(renderData->layerProperties->renderPasses) & pass) ? renderData : nullptr; } return nullptr; } diff --git a/src/mbgl/renderer/render_source.cpp b/src/mbgl/renderer/render_source.cpp index 2188caf41..7e2aa3011 100644 --- a/src/mbgl/renderer/render_source.cpp +++ b/src/mbgl/renderer/render_source.cpp @@ -58,7 +58,9 @@ std::unique_ptr RenderSource::create(const Immutable return nullptr; } -static RenderSourceObserver nullObserver; +namespace { +RenderSourceObserver nullObserver; +} RenderSource::RenderSource(Immutable impl) : baseImpl(std::move(impl)), diff --git a/src/mbgl/renderer/sources/render_tile_source.cpp b/src/mbgl/renderer/sources/render_tile_source.cpp index 37bbae8b0..408bcf220 100644 --- a/src/mbgl/renderer/sources/render_tile_source.cpp +++ b/src/mbgl/renderer/sources/render_tile_source.cpp @@ -348,7 +348,7 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr for (auto& lg : {outlineLayerGroup, textLayerGroup}) { lg->removeDrawablesIf([&](gfx::Drawable& drawable) { return drawable.getName() == drawableName && - !(drawable.getTileID().has_value() && newTiles.count(*drawable.getTileID()) > 0); + !(drawable.getTileID().has_value() && newTiles.contains(*drawable.getTileID())); }); } @@ -404,7 +404,7 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr // erase drawables that are not in the current tile set tileLayerGroup->removeDrawablesIf([&](gfx::Drawable& drawable) { return drawable.getName() == drawableName && - !(drawable.getTileID().has_value() && newTiles.count(*drawable.getTileID()) > 0); + !(drawable.getTileID().has_value() && newTiles.contains(*drawable.getTileID())); }); // add new drawables and update existing ones diff --git a/src/mbgl/renderer/tile_pyramid.cpp b/src/mbgl/renderer/tile_pyramid.cpp index 2c62ec348..3028d2e1f 100644 --- a/src/mbgl/renderer/tile_pyramid.cpp +++ b/src/mbgl/renderer/tile_pyramid.cpp @@ -22,8 +22,10 @@ namespace mbgl { using namespace style; -static TileObserver nullObserver; -static const std::map> emptyPrefetchedTiles; +namespace { +TileObserver nullObserver; +const std::map> emptyPrefetchedTiles; +} // namespace TilePyramid::TilePyramid(const TaggedScheduler& threadPool_) : cache(threadPool_), diff --git a/src/mbgl/sprite/sprite_loader.cpp b/src/mbgl/sprite/sprite_loader.cpp index 85178810b..b19d2bba6 100644 --- a/src/mbgl/sprite/sprite_loader.cpp +++ b/src/mbgl/sprite/sprite_loader.cpp @@ -17,7 +17,9 @@ namespace mbgl { -static SpriteLoaderObserver nullObserver; +namespace { +SpriteLoaderObserver nullObserver; +} struct SpriteLoader::Data { std::shared_ptr image; @@ -50,7 +52,7 @@ void SpriteLoader::load(const std::optional sprite, FileSource& f std::lock_guard lock(dataMapMutex); Data* data = dataMap[sprite->id].get(); if (res.error) { - observer->onSpriteError(*sprite, std::make_exception_ptr(std::runtime_error(res.error->message))); + observer->onSpriteError(sprite, std::make_exception_ptr(std::runtime_error(res.error->message))); } else if (res.notModified) { return; } else if (res.noContent) { @@ -69,7 +71,7 @@ void SpriteLoader::load(const std::optional sprite, FileSource& f std::lock_guard lock(dataMapMutex); Data* data = dataMap[sprite->id].get(); if (res.error) { - observer->onSpriteError(*sprite, std::make_exception_ptr(std::runtime_error(res.error->message))); + observer->onSpriteError(sprite, std::make_exception_ptr(std::runtime_error(res.error->message))); } else if (res.notModified) { return; } else if (res.noContent) { diff --git a/src/mbgl/storage/resource.cpp b/src/mbgl/storage/resource.cpp index 6c25fb0fa..b32e38255 100644 --- a/src/mbgl/storage/resource.cpp +++ b/src/mbgl/storage/resource.cpp @@ -9,7 +9,8 @@ namespace mbgl { -static std::string getQuadKey(int32_t x, int32_t y, int8_t z) { +namespace { +std::string getQuadKey(int32_t x, int32_t y, int8_t z) { std::string quadKey; quadKey.reserve(z); int32_t mask; @@ -20,7 +21,7 @@ static std::string getQuadKey(int32_t x, int32_t y, int8_t z) { return quadKey; } -static mapbox::geometry::point getMercCoord(int32_t x, int32_t y, int8_t z) { +mapbox::geometry::point getMercCoord(int32_t x, int32_t y, int8_t z) { double resolution = (util::M2PI * util::EARTH_RADIUS_M / 256) / std::pow(2, z); return { x * resolution - util::M2PI * util::EARTH_RADIUS_M / 2, @@ -28,7 +29,7 @@ static mapbox::geometry::point getMercCoord(int32_t x, int32_t y, int8_t }; } -static std::string getTileBBox(int32_t x, int32_t y, int8_t z) { +std::string getTileBBox(int32_t x, int32_t y, int8_t z) { // Alter the y for the Google/OSM tile scheme. y = static_cast(std::pow(2, z)) - y - 1; @@ -38,6 +39,7 @@ static std::string getTileBBox(int32_t x, int32_t y, int8_t z) { return (util::toString(min.x) + "," + util::toString(min.y) + "," + util::toString(max.x) + "," + util::toString(max.y)); } +} // namespace Resource Resource::style(const std::string& url) { return Resource{Resource::Kind::Style, url}; diff --git a/src/mbgl/style/conversion/constant.cpp b/src/mbgl/style/conversion/constant.cpp index 4f1f0f976..88f44edb8 100644 --- a/src/mbgl/style/conversion/constant.cpp +++ b/src/mbgl/style/conversion/constant.cpp @@ -11,7 +11,7 @@ std::optional Converter::operator()(const Convertible& value, Error& error.message = "value must be a boolean"; return std::nullopt; } - return *converted; + return converted; } std::optional Converter::operator()(const Convertible& value, Error& error) const { @@ -20,7 +20,7 @@ std::optional Converter::operator()(const Convertible& value, Erro error.message = "value must be a number"; return std::nullopt; } - return *converted; + return converted; } std::optional Converter::operator()(const Convertible& value, Error& error) const { @@ -29,7 +29,7 @@ std::optional Converter::operator()(const Convertible& error.message = "value must be a string"; return std::nullopt; } - return *converted; + return converted; } template @@ -47,7 +47,7 @@ std::optional Converter>>::ope return std::nullopt; } - return *result; + return result; } template @@ -111,7 +111,7 @@ std::optional Converter::operator()(const Convertible& value, Erro return std::nullopt; } - return *color; + return color; } std::optional Converter::operator()(const Convertible& value, Error& error) const { diff --git a/src/mbgl/style/conversion/filter.cpp b/src/mbgl/style/conversion/filter.cpp index 4649e4f92..447ec6e19 100644 --- a/src/mbgl/style/conversion/filter.cpp +++ b/src/mbgl/style/conversion/filter.cpp @@ -14,7 +14,9 @@ namespace conversion { using namespace mbgl::style::expression; -static bool isExpression(const Convertible& filter); +namespace { +bool isExpression(const Convertible& filter); +} ParseResult convertLegacyFilter(const Convertible& values, Error& error); std::optional serializeLegacyFilter(const Convertible& values); @@ -34,12 +36,13 @@ std::optional Converter::operator()(const Convertible& value, Er assert(error.message.size() > 0); return std::nullopt; } - return Filter(std::optional>(std::move(*expression)), serializeLegacyFilter(value)); + return Filter(std::optional>(std::move(expression)), serializeLegacyFilter(value)); } } // This is a port from // https://github.com/mapbox/mapbox-gl-js/blob/master/src/style-spec/feature_filter/index.js +namespace { bool isExpression(const Convertible& filter) { if (!isArray(filter) || arrayLength(filter) == 0) { return false; @@ -79,6 +82,7 @@ bool isExpression(const Convertible& filter) { return true; } } +} // namespace ParseResult createExpression(const std::string& op, std::optional>> args, diff --git a/src/mbgl/style/conversion/source.cpp b/src/mbgl/style/conversion/source.cpp index 0ef4cbbf2..e04ff6d44 100644 --- a/src/mbgl/style/conversion/source.cpp +++ b/src/mbgl/style/conversion/source.cpp @@ -17,7 +17,8 @@ namespace style { namespace conversion { // A tile source can either specify a URL to TileJSON, or inline TileJSON. -static std::optional> convertURLOrTileset(const Convertible& value, Error& error) { +namespace { +std::optional> convertURLOrTileset(const Convertible& value, Error& error) { auto urlVal = objectMember(value, "url"); if (!urlVal) { std::optional tileset = convert(value, error); @@ -36,9 +37,9 @@ static std::optional> convertURLOrTileset(const Co return {*url}; } -static std::optional> convertRasterSource(const std::string& id, - const Convertible& value, - Error& error) { +std::optional> convertRasterSource(const std::string& id, + const Convertible& value, + Error& error) { std::optional> urlOrTileset = convertURLOrTileset(value, error); if (!urlOrTileset) { return std::nullopt; @@ -58,9 +59,9 @@ static std::optional> convertRasterSource(const std::str return {std::make_unique(id, std::move(*urlOrTileset), tileSize)}; } -static std::optional> convertRasterDEMSource(const std::string& id, - const Convertible& value, - Error& error) { +std::optional> convertRasterDEMSource(const std::string& id, + const Convertible& value, + Error& error) { std::optional> urlOrTileset = convertURLOrTileset(value, error); if (!urlOrTileset) { return std::nullopt; @@ -87,9 +88,9 @@ static std::optional> convertRasterDEMSource(const std:: return {std::make_unique(id, std::move(*urlOrTileset), tileSize, options)}; } -static std::optional> convertVectorSource(const std::string& id, - const Convertible& value, - Error& error) { +std::optional> convertVectorSource(const std::string& id, + const Convertible& value, + Error& error) { std::optional> urlOrTileset = convertURLOrTileset(value, error); if (!urlOrTileset) { return std::nullopt; @@ -115,9 +116,9 @@ static std::optional> convertVectorSource(const std::str return {std::make_unique(id, std::move(*urlOrTileset), std::move(maxzoom), std::move(minzoom))}; } -static std::optional> convertGeoJSONSource(const std::string& id, - const Convertible& value, - Error& error) { +std::optional> convertGeoJSONSource(const std::string& id, + const Convertible& value, + Error& error) { auto dataValue = objectMember(value, "data"); if (!dataValue) { error.message = "GeoJSON source must have a data value"; @@ -147,9 +148,9 @@ static std::optional> convertGeoJSONSource(const std::st return {std::move(result)}; } -static std::optional> convertImageSource(const std::string& id, - const Convertible& value, - Error& error) { +std::optional> convertImageSource(const std::string& id, + const Convertible& value, + Error& error) { auto urlValue = objectMember(value, "url"); if (!urlValue) { error.message = "Image source must have a url value"; @@ -188,6 +189,7 @@ static std::optional> convertImageSource(const std::stri return {std::move(result)}; } +} // namespace std::optional> Converter>::operator()(const Convertible& value, Error& error, diff --git a/src/mbgl/style/conversion/sprite.cpp b/src/mbgl/style/conversion/sprite.cpp index 60ae104b3..161e0c19a 100644 --- a/src/mbgl/style/conversion/sprite.cpp +++ b/src/mbgl/style/conversion/sprite.cpp @@ -25,8 +25,7 @@ std::optional Converter::operator()(const Convertible& value, Er } spriteURL = toString(*urlValue); - const Sprite sprite(*id, *spriteURL); - return sprite; + return Sprite(*id, *spriteURL); } } // namespace conversion diff --git a/src/mbgl/style/expression/comparison.cpp b/src/mbgl/style/expression/comparison.cpp index 027e69b40..7f19c7a11 100644 --- a/src/mbgl/style/expression/comparison.cpp +++ b/src/mbgl/style/expression/comparison.cpp @@ -7,8 +7,8 @@ namespace mbgl { namespace style { namespace expression { - -static bool isComparableType(const std::string& op, const type::Type& type) noexcept { +namespace { +bool isComparableType(const std::string& op, const type::Type& type) noexcept { if (op == "==" || op == "!=") { return type == type::String || type == type::Number || type == type::Boolean || type == type::Null || type == type::Value; @@ -75,7 +75,7 @@ bool gteqCollate(const std::string& a, const std::string& b, const Collator& c) return c.compare(a, b) >= 0; } -static BasicComparison::CompareFunctionType getBasicCompareFunction(const std::string& op) noexcept { +BasicComparison::CompareFunctionType getBasicCompareFunction(const std::string& op) noexcept { if (op == "==") return eq; else if (op == "!=") @@ -92,7 +92,7 @@ static BasicComparison::CompareFunctionType getBasicCompareFunction(const std::s return nullptr; } -static CollatorComparison::CompareFunctionType getCollatorComparisonFunction(const std::string& op) noexcept { +CollatorComparison::CompareFunctionType getCollatorComparisonFunction(const std::string& op) noexcept { if (op == "==") return eqCollate; else if (op == "!=") @@ -108,6 +108,7 @@ static CollatorComparison::CompareFunctionType getCollatorComparisonFunction(con assert(false); return nullptr; } +} // namespace BasicComparison::BasicComparison(std::string op_, std::unique_ptr lhs_, std::unique_ptr rhs_) : Expression(Kind::Comparison, type::Boolean, depsOf(lhs_) | depsOf(rhs_)), diff --git a/src/mbgl/style/expression/compound_expression.cpp b/src/mbgl/style/expression/compound_expression.cpp index 1a2c1a4bf..36211667c 100644 --- a/src/mbgl/style/expression/compound_expression.cpp +++ b/src/mbgl/style/expression/compound_expression.cpp @@ -237,6 +237,7 @@ std::unique_ptr makeSignature(std::string name, } } // namespace } // namespace detail + namespace { Value featureIdAsExpressionValue(const EvaluationContext& params) { assert(params.feature); @@ -299,6 +300,8 @@ std::optional featureIdAsString(const EvaluationContext& params) { return id.match([](std::string value) { return value; }, [](const auto&) { return std::optional(); }); }; +} // unnamed namespace + const auto& eCompoundExpression() { static auto signature = detail::makeSignature("e", []() -> Result { return std::numbers::e; }); return signature; @@ -990,6 +993,8 @@ const auto& filterInCompoundExpression() { return signature; } +namespace { + using ParseCompoundFunction = const std::unique_ptr& (*)(); constexpr const auto compoundExpressionRegistry = mapbox::eternal::hash_map({ @@ -1069,11 +1074,15 @@ constexpr const auto compoundExpressionRegistry = {"filter-in", filterInCompoundExpression}, }); +} // unnamed namespace + using namespace mbgl::style::conversion; using DefinitionIterator = decltype(compoundExpressionRegistry)::const_iterator; using Definitions = std::pair; +namespace { + std::string expectedTypesError(const Definitions& definitions, const std::vector>& args) { std::vector availableOverloads; // Only used if there are no overloads // with matching number of args diff --git a/src/mbgl/style/expression/distance.cpp b/src/mbgl/style/expression/distance.cpp index 811db39bb..e19e5cd2c 100644 --- a/src/mbgl/style/expression/distance.cpp +++ b/src/mbgl/style/expression/distance.cpp @@ -839,7 +839,7 @@ std::optional parseValue(const style::conversion::Convertible& value, s style::conversion::Error error; auto geojson = toGeoJSON(argument, error); if (geojson && error.message.empty()) { - return *geojson; + return geojson; } ctx.error(error.message); } diff --git a/src/mbgl/style/expression/formatted.cpp b/src/mbgl/style/expression/formatted.cpp index 43efbebe7..2131ab600 100644 --- a/src/mbgl/style/expression/formatted.cpp +++ b/src/mbgl/style/expression/formatted.cpp @@ -57,7 +57,6 @@ mbgl::Value Formatted::toObject() const { serializedSection.emplace("scale", NullValue()); } if (section.fontStack) { - std::string fontStackString; serializedSection.emplace("fontStack", fontStackToString(*section.fontStack)); } else { serializedSection.emplace("fontStack", NullValue()); diff --git a/src/mbgl/style/expression/is_constant.cpp b/src/mbgl/style/expression/is_constant.cpp index 574a08a74..986670884 100644 --- a/src/mbgl/style/expression/is_constant.cpp +++ b/src/mbgl/style/expression/is_constant.cpp @@ -18,7 +18,7 @@ bool isFeatureConstant(const Expression& expression) { return false; } else if (name == "properties" || name == "geometry-type" || name == "id" || name == "feature-state") { return false; - } else if (0u == name.rfind(filter, 0u)) { + } else if (name.starts_with(filter)) { // Legacy filters begin with "filter-" and are never constant. return false; } diff --git a/src/mbgl/style/expression/match.cpp b/src/mbgl/style/expression/match.cpp index ac497257a..e2881f7b2 100644 --- a/src/mbgl/style/expression/match.cpp +++ b/src/mbgl/style/expression/match.cpp @@ -196,12 +196,14 @@ std::optional parseInputValue(const Convertible& input, return result; } +namespace { + template -static ParseResult create(type::Type outputType, - std::unique_ptr input, - std::vector, std::unique_ptr>> branches, - std::unique_ptr otherwise, - ParsingContext& ctx) { +ParseResult create(type::Type outputType, + std::unique_ptr input, + std::vector, std::unique_ptr>> branches, + std::unique_ptr otherwise, + ParsingContext& ctx) { typename Match::Branches typedBranches; std::size_t index = 2; @@ -224,6 +226,8 @@ static ParseResult create(type::Type outputType, std::move(outputType), std::move(input), std::move(typedBranches), std::move(otherwise))); } +} // namespace + ParseResult parseMatch(const Convertible& value, ParsingContext& ctx) { assert(isArray(value)); auto length = arrayLength(value); diff --git a/src/mbgl/style/layer.cpp b/src/mbgl/style/layer.cpp index 121a637bc..eb263a14f 100644 --- a/src/mbgl/style/layer.cpp +++ b/src/mbgl/style/layer.cpp @@ -27,7 +27,9 @@ static_assert(mbgl::underlying_type(Tile::Kind::Raster) == mbgl::underlying_type static_assert(mbgl::underlying_type(Tile::Kind::RasterDEM) == mbgl::underlying_type(LayerTypeInfo::TileKind::RasterDEM), "tile kind error"); -static LayerObserver nullObserver; +namespace { +LayerObserver nullObserver; +} Layer::Layer(Immutable impl) : baseImpl(std::move(impl)), diff --git a/src/mbgl/style/light.cpp b/src/mbgl/style/light.cpp index 4d5189697..f3a4c7f88 100644 --- a/src/mbgl/style/light.cpp +++ b/src/mbgl/style/light.cpp @@ -17,7 +17,9 @@ namespace mbgl { namespace style { -static LightObserver nullObserver; +namespace { +LightObserver nullObserver; +} Light::Light(Immutable impl_) : impl(std::move(impl_)), diff --git a/src/mbgl/style/source.cpp b/src/mbgl/style/source.cpp index 0574125a4..7f8ec0684 100644 --- a/src/mbgl/style/source.cpp +++ b/src/mbgl/style/source.cpp @@ -6,7 +6,9 @@ namespace mbgl { namespace style { -static SourceObserver nullObserver; +namespace { +SourceObserver nullObserver; +} Source::Source(Immutable impl) : baseImpl(std::move(impl)), diff --git a/src/mbgl/text/get_anchors.cpp b/src/mbgl/text/get_anchors.cpp index 38b168165..5694098a9 100644 --- a/src/mbgl/text/get_anchors.cpp +++ b/src/mbgl/text/get_anchors.cpp @@ -20,14 +20,16 @@ float getLineLength(const GeometryCoordinates& line) { return lineLength; } -static Anchors resample(const GeometryCoordinates& line, - const float offset, - const float spacing, - const float angleWindowSize, - const float maxAngle, - const float labelLength, - const bool continuedLine, - const bool placeAtMiddle) { +namespace { + +Anchors resample(const GeometryCoordinates& line, + const float offset, + const float spacing, + const float angleWindowSize, + const float maxAngle, + const float labelLength, + const bool continuedLine, + const bool placeAtMiddle) { const float halfLabelLength = labelLength / 2.0f; const float lineLength = getLineLength(line); @@ -82,6 +84,8 @@ static Anchors resample(const GeometryCoordinates& line, return anchors; } +} // unnamed namespace + Anchors getAnchors(const GeometryCoordinates& line, float spacing, const float maxAngle, diff --git a/src/mbgl/text/glyph.cpp b/src/mbgl/text/glyph.cpp index eb2f52244..89325d4e4 100644 --- a/src/mbgl/text/glyph.cpp +++ b/src/mbgl/text/glyph.cpp @@ -26,6 +26,8 @@ GlyphIDType genNewGlyphIDType() { static short glyphType = GlyphIDType::FontPBF; ++glyphType; if (glyphType == GlyphIDType::FontPBF) ++glyphType; + // Intentionally casting to extend the enum's value space for runtime-generated IDs. + // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) return static_cast(glyphType); } diff --git a/src/mbgl/text/glyph_manager.cpp b/src/mbgl/text/glyph_manager.cpp index 5d872963f..b74e69184 100644 --- a/src/mbgl/text/glyph_manager.cpp +++ b/src/mbgl/text/glyph_manager.cpp @@ -14,7 +14,9 @@ namespace mbgl { -static GlyphManagerObserver nullObserver; +namespace { +GlyphManagerObserver nullObserver; +} GlyphManager::GlyphManager(std::unique_ptr localGlyphRasterizer_) : observer(&nullObserver), diff --git a/src/mbgl/text/harfbuzz.cpp b/src/mbgl/text/harfbuzz.cpp index cb3767c86..1bdef906f 100644 --- a/src/mbgl/text/harfbuzz.cpp +++ b/src/mbgl/text/harfbuzz.cpp @@ -38,7 +38,7 @@ HBShaper::~HBShaper() { void HBShaper::createComplexGlyphIDs(const std::u16string &text, std::vector &glyphIDs, std::vector &adjusts) { - return impl->createComplexGlyphIDs(text, glyphIDs, adjusts); + impl->createComplexGlyphIDs(text, glyphIDs, adjusts); } Glyph HBShaper::rasterizeGlyph(const GlyphID &glyph) { diff --git a/src/mbgl/text/harfbuzz_impl.cpp b/src/mbgl/text/harfbuzz_impl.cpp index 0347febab..4fda36f48 100644 --- a/src/mbgl/text/harfbuzz_impl.cpp +++ b/src/mbgl/text/harfbuzz_impl.cpp @@ -4,12 +4,13 @@ namespace mbgl { -static hb_language_t getDefaultLanguage() { +namespace { +hb_language_t getDefaultLanguage() { static hb_language_t language = hb_language_get_default(); return language; } -static hb_script_t getUnicodeScript(hb_codepoint_t u) { +hb_script_t getUnicodeScript(hb_codepoint_t u) { static hb_unicode_funcs_t *unicode_funcs; unicode_funcs = hb_unicode_funcs_get_default(); @@ -23,6 +24,8 @@ static hb_script_t getUnicodeScript(hb_codepoint_t u) { return hb_unicode_script(unicode_funcs, u); } +} // namespace + HBShaper::Impl::Impl(GlyphIDType type_, const std::string &fontFileData, const FreeTypeLibrary &lib) : type(type_), face(fontFileData.data(), fontFileData.size(), lib) { diff --git a/src/mbgl/tile/geometry_tile_data.cpp b/src/mbgl/tile/geometry_tile_data.cpp index d10a1938f..59e7c0fe4 100644 --- a/src/mbgl/tile/geometry_tile_data.cpp +++ b/src/mbgl/tile/geometry_tile_data.cpp @@ -19,8 +19,8 @@ using namespace std::numbers; namespace mbgl { - namespace { + double signedArea(const GeometryCoordinates& ring) { double sum = 0; diff --git a/src/mbgl/tile/tile.cpp b/src/mbgl/tile/tile.cpp index 64c722903..a55181cb2 100644 --- a/src/mbgl/tile/tile.cpp +++ b/src/mbgl/tile/tile.cpp @@ -6,7 +6,9 @@ namespace mbgl { -static TileObserver nullObserver; +namespace { +TileObserver nullObserver; +} Tile::Tile(Kind kind_, OverscaledTileID id_, std::string sourceID_, TileObserver* observer_) : kind(kind_), diff --git a/src/mbgl/util/action_journal_impl.hpp b/src/mbgl/util/action_journal_impl.hpp index 152c95028..44e0d06ef 100644 --- a/src/mbgl/util/action_journal_impl.hpp +++ b/src/mbgl/util/action_journal_impl.hpp @@ -18,7 +18,7 @@ class ActionJournalEvent; class ActionJournal::Impl : public MapObserver { public: Impl(const Map& map, const ActionJournalOptions& options); - ~Impl(); + ~Impl() override; const Map& getMap() const { return map; } std::string getLogDirectory() const; diff --git a/src/mbgl/util/camera.cpp b/src/mbgl/util/camera.cpp index e25c5004c..587be3fc6 100644 --- a/src/mbgl/util/camera.cpp +++ b/src/mbgl/util/camera.cpp @@ -29,34 +29,35 @@ vec2 vec2Scale(const vec2& v, double s) noexcept { } // namespace namespace util { +namespace { -static double mercatorXfromLng(double lng) noexcept { +double mercatorXfromLng(double lng) noexcept { return (180.0 + lng) / 360.0; } -static double mercatorYfromLat(double lat) noexcept { +double mercatorYfromLat(double lat) noexcept { return (180.0 - (180.0 / pi * std::log(std::tan((pi / 4) + lat * pi / 360.0)))) / 360.0; } -static double latFromMercatorY(double y) noexcept { +double latFromMercatorY(double y) noexcept { return util::rad2deg(2.0 * std::atan(std::exp(pi - y * util::M2PI)) - (pi / 2)); } -static double lngFromMercatorX(double x) noexcept { +double lngFromMercatorX(double x) noexcept { return x * 360.0 - 180.0; } -static double* getColumn(mat4& matrix, int col) noexcept { +double* getColumn(mat4& matrix, int col) noexcept { assert(col >= 0 && col < 4); return &matrix[col * 4]; } -static const double* getColumn(const mat4& matrix, int col) noexcept { +const double* getColumn(const mat4& matrix, int col) noexcept { assert(col >= 0 && col < 4); return &matrix[col * 4]; } -static vec3 toMercator(const LatLng& location, double altitudeMeters) noexcept { +vec3 toMercator(const LatLng& location, double altitudeMeters) noexcept { const double pixelsPerMeter = 1.0 / Projection::getMetersPerPixelAtLatitude(location.latitude(), 0.0); const double worldSize = Projection::worldSize(std::pow(2.0, 0.0)); @@ -65,7 +66,7 @@ static vec3 toMercator(const LatLng& location, double altitudeMeters) noexcept { altitudeMeters * pixelsPerMeter / worldSize}}; } -static Quaternion orientationFromPitchBearing(double pitch, double bearing) noexcept { +Quaternion orientationFromPitchBearing(double pitch, double bearing) noexcept { // Both angles have to be negated to achieve CW rotation around the axis of rotation const Quaternion rotBearing = Quaternion::fromAxisAngle({{0.0, 0.0, 1.0}}, -bearing); const Quaternion rotPitch = Quaternion::fromAxisAngle({{1.0, 0.0, 0.0}}, -pitch); @@ -73,7 +74,7 @@ static Quaternion orientationFromPitchBearing(double pitch, double bearing) noex return rotBearing.multiply(rotPitch); } -static void updateTransform(mat4& transform, const Quaternion& orientation) noexcept { +void updateTransform(mat4& transform, const Quaternion& orientation) noexcept { // Construct rotation matrix from orientation mat4 m = orientation.toRotationMatrix(); @@ -87,12 +88,14 @@ static void updateTransform(mat4& transform, const Quaternion& orientation) noex transform = m; } -static void updateTransform(mat4& transform, const vec3& position) { +void updateTransform(mat4& transform, const vec3& position) { getColumn(transform, 3)[0] = position[0]; getColumn(transform, 3)[1] = position[1]; getColumn(transform, 3)[2] = position[2]; } +} // namespace + Camera::Camera() noexcept : orientation(Quaternion::identity) { matrix::identity(transform); diff --git a/src/mbgl/util/chrono.cpp b/src/mbgl/util/chrono.cpp index a4b8e60df..97fd04f82 100644 --- a/src/mbgl/util/chrono.cpp +++ b/src/mbgl/util/chrono.cpp @@ -14,8 +14,10 @@ namespace mbgl { namespace util { -static const char *week[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; -static const char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; +namespace { +const char* week[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; +const char* months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; +} // namespace std::string rfc1123(Timestamp timestamp) { std::time_t time = std::chrono::system_clock::to_time_t(timestamp); @@ -67,7 +69,7 @@ std::string iso8601(std::chrono::time_point(std::chrono::system_clock::from_time_t(parse_date(timestamp))); } diff --git a/src/mbgl/util/io.cpp b/src/mbgl/util/io.cpp index 6b3d17fc6..af445660d 100644 --- a/src/mbgl/util/io.cpp +++ b/src/mbgl/util/io.cpp @@ -56,7 +56,7 @@ std::optional readFile(const std::string &filename, size_t size = static_cast(dataRange->second - dataRange->first + 1); std::string data(size, '\0'); file.seekg(static_cast(dataRange->first)); - file.read(&data[0], static_cast(size)); + file.read(data.data(), static_cast(size)); return data; } else { std::stringstream data; diff --git a/src/mbgl/util/logging.cpp b/src/mbgl/util/logging.cpp index c86b881f8..c70cd88d3 100644 --- a/src/mbgl/util/logging.cpp +++ b/src/mbgl/util/logging.cpp @@ -33,9 +33,9 @@ public: } else { Log::record(severity, event, code, msg, {}); } - } catch (...) { - // ignore exceptions during logging - // What would we do, log them? + } catch (...) { // NOLINT(bugprone-empty-catch) + // ignore exceptions during logging + // What would we do, log them? #if !defined(NDEBUG) [[maybe_unused]] auto ex = std::current_exception(); assert(!"unhandled exception while logging"); diff --git a/src/mbgl/util/mapbox.cpp b/src/mbgl/util/mapbox.cpp index 7793f1b19..daa0338aa 100644 --- a/src/mbgl/util/mapbox.cpp +++ b/src/mbgl/util/mapbox.cpp @@ -155,9 +155,11 @@ std::string makeQueryString(const TileServerOptions& tileServerOptions, const st return queryString; } -static bool equals(const std::string& str, const URL::Segment& segment, std::string& ref) { +namespace { +bool equals(const std::string& str, const URL::Segment& segment, std::string& ref) { return str.compare(segment.first, segment.second, ref) == 0; } +} // unnamed namespace std::string normalizeSourceURL(const TileServerOptions& tileServerOptions, const std::string& str, diff --git a/src/mbgl/vulkan/context.cpp b/src/mbgl/vulkan/context.cpp index df44808f8..485be150b 100644 --- a/src/mbgl/vulkan/context.cpp +++ b/src/mbgl/vulkan/context.cpp @@ -41,7 +41,9 @@ constexpr uint32_t layerDescriptorPoolSize = 3 * 256; constexpr uint32_t drawableUniformDescriptorPoolSize = 3 * 1024; constexpr uint32_t drawableImageDescriptorPoolSize = drawableUniformDescriptorPoolSize / 2; -static uint32_t glslangRefCount = 0; +namespace { +uint32_t glslangRefCount = 0; +} class RenderbufferResource : public gfx::RenderbufferResource { public: @@ -568,7 +570,8 @@ bool Context::renderTileClippingMasks(gfx::RenderPass& renderPass, auto& renderableResource = renderPassImpl.getDescriptor().renderable.getResource(); const float rad = renderableResource.getRotation(); - const mat4 rotationMat = {cos(rad), -sin(rad), 0, 0, sin(rad), cos(rad), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; + const mat4 rotationMat = { + std::cos(rad), -std::sin(rad), 0, 0, std::sin(rad), std::cos(rad), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; for (const auto& tileInfo : tileUBOs) { commandBuffer->setStencilReference(vk::StencilFaceFlagBits::eFrontAndBack, tileInfo.stencil_ref, dispatcher); diff --git a/src/mbgl/vulkan/descriptor_set.cpp b/src/mbgl/vulkan/descriptor_set.cpp index 1cfcbe727..5c375c6e9 100644 --- a/src/mbgl/vulkan/descriptor_set.cpp +++ b/src/mbgl/vulkan/descriptor_set.cpp @@ -8,7 +8,7 @@ #include #include -#include +#include #define USE_DESCRIPTOR_POOL_RESET diff --git a/src/mbgl/vulkan/offscreen_texture.cpp b/src/mbgl/vulkan/offscreen_texture.cpp index de0f405fd..fc8a26240 100644 --- a/src/mbgl/vulkan/offscreen_texture.cpp +++ b/src/mbgl/vulkan/offscreen_texture.cpp @@ -143,7 +143,7 @@ bool OffscreenTexture::isRenderable() { } PremultipliedImage OffscreenTexture::readStillImage() { - return getResource().readStillImage(); + return getResource().readStillImage(); // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks) } const gfx::Texture2DPtr& OffscreenTexture::getTexture() { diff --git a/src/mbgl/vulkan/renderer_backend.cpp b/src/mbgl/vulkan/renderer_backend.cpp index a17444273..ec1a7d5b1 100644 --- a/src/mbgl/vulkan/renderer_backend.cpp +++ b/src/mbgl/vulkan/renderer_backend.cpp @@ -72,10 +72,12 @@ static struct { namespace mbgl { namespace vulkan { +namespace { + template -static bool checkAvailability(const std::vector& availableValues, - const std::vector& requiredValues, - const F& getter) { +bool checkAvailability(const std::vector& availableValues, + const std::vector& requiredValues, + const F& getter) { for (const auto& requiredValue : requiredValues) { bool found = false; for (const auto& availableValue : availableValues) { @@ -91,12 +93,14 @@ static bool checkAvailability(const std::vector& availableValues, return true; } +} // namespace + RendererBackend::RendererBackend(const gfx::ContextMode contextMode_) : gfx::RendererBackend(contextMode_), allocator(nullptr) {} RendererBackend::~RendererBackend() { - destroyResources(); + destroyResources(); // NOLINT(clang-analyzer-optin.cplusplus.VirtualCall) } std::unique_ptr RendererBackend::createContext() { diff --git a/src/mbgl/vulkan/texture2d.cpp b/src/mbgl/vulkan/texture2d.cpp index 7a6f9d798..48a43c077 100644 --- a/src/mbgl/vulkan/texture2d.cpp +++ b/src/mbgl/vulkan/texture2d.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include namespace mbgl { namespace vulkan { diff --git a/src/mbgl/vulkan/uniform_buffer.cpp b/src/mbgl/vulkan/uniform_buffer.cpp index 615fc4130..9b5ce6ec8 100644 --- a/src/mbgl/vulkan/uniform_buffer.cpp +++ b/src/mbgl/vulkan/uniform_buffer.cpp @@ -19,7 +19,7 @@ UniformBuffer::UniformBuffer(BufferResource&& buffer_) UniformBuffer::UniformBuffer(UniformBuffer&& other) : gfx::UniformBuffer(std::move(other)), - buffer(std::move(other.buffer)) {} + buffer(std::move(other.buffer)) {} // NOLINT(bugprone-use-after-move) UniformBuffer::~UniformBuffer() { buffer.getContext().renderingStats().numUniformBuffers--; diff --git a/test/.clang-tidy b/test/.clang-tidy index f7d842e54..5af264d27 100644 --- a/test/.clang-tidy +++ b/test/.clang-tidy @@ -15,6 +15,7 @@ Checks: > -modernize-use-nodiscard, -modernize-use-nullptr, -modernize-use-override, + -modernize-use-constraints, -modernize-use-trailing-return-type, misc-static-assert, -clang-analyzer-security.insecureAPI.rand, diff --git a/test/gl/enum.test.cpp b/test/gl/enum.test.cpp index 2ba162121..043f1ebd4 100644 --- a/test/gl/enum.test.cpp +++ b/test/gl/enum.test.cpp @@ -18,7 +18,9 @@ TEST(GL, DrawModeType) { ASSERT_EQ(GL_TRIANGLES, Enum::to(DrawModeType::Triangles)); ASSERT_EQ(GL_TRIANGLE_STRIP, Enum::to(DrawModeType::TriangleStrip)); ASSERT_EQ(GL_TRIANGLE_FAN, Enum::to(DrawModeType::TriangleFan)); - ASSERT_EQ(GL_INVALID_ENUM, Enum::to(static_cast(-1))); + ASSERT_EQ( + GL_INVALID_ENUM, + Enum::to(static_cast(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) } namespace { @@ -35,7 +37,9 @@ TEST(GL, ColorBlendEquationType) { ASSERT_EQ(ColorBlendEquationType::Subtract, enumIdentity(ColorBlendEquationType::Subtract)); ASSERT_EQ(ColorBlendEquationType::ReverseSubtract, enumIdentity(ColorBlendEquationType::ReverseSubtract)); - ASSERT_EQ(GL_INVALID_ENUM, Enum::to(static_cast(-1))); + ASSERT_EQ(GL_INVALID_ENUM, + Enum::to( + static_cast(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) ASSERT_EQ(ColorBlendEquationType{}, Enum::from(GL_RGBA8)); } @@ -56,7 +60,9 @@ TEST(GL, ColorBlendFactorType) { ASSERT_EQ(ColorBlendFactorType::OneMinusConstantAlpha, enumIdentity(ColorBlendFactorType::OneMinusConstantAlpha)); ASSERT_EQ(ColorBlendFactorType::SrcAlphaSaturate, enumIdentity(ColorBlendFactorType::SrcAlphaSaturate)); - ASSERT_EQ(GL_INVALID_ENUM, Enum::to(static_cast(-1))); + ASSERT_EQ(GL_INVALID_ENUM, + Enum::to( + static_cast(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) ASSERT_EQ(ColorBlendFactorType{}, Enum::from(GL_RGBA8)); } @@ -70,7 +76,9 @@ TEST(GL, DepthFunctionType) { ASSERT_EQ(DepthFunctionType::GreaterEqual, enumIdentity(DepthFunctionType::GreaterEqual)); ASSERT_EQ(DepthFunctionType::Always, enumIdentity(DepthFunctionType::Always)); - ASSERT_EQ(GL_INVALID_ENUM, Enum::to(static_cast(-1))); + ASSERT_EQ(GL_INVALID_ENUM, + Enum::to( + static_cast(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) ASSERT_EQ(DepthFunctionType{}, Enum::from(GL_RGBA8)); } @@ -92,7 +100,9 @@ TEST(GL, StencilFunctionType) { ASSERT_EQ(StencilFunctionType::GreaterEqual, enumIdentity(StencilFunctionType::GreaterEqual)); ASSERT_EQ(StencilFunctionType::Always, enumIdentity(StencilFunctionType::Always)); - ASSERT_EQ(GL_INVALID_ENUM, Enum::to(static_cast(-1))); + ASSERT_EQ(GL_INVALID_ENUM, + Enum::to( + static_cast(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) ASSERT_EQ(StencilFunctionType{}, Enum::from(GL_RGBA8)); } @@ -106,7 +116,9 @@ TEST(GL, StencilOpType) { ASSERT_EQ(StencilOpType::DecrementWrap, enumIdentity(StencilOpType::DecrementWrap)); ASSERT_EQ(StencilOpType::Invert, enumIdentity(StencilOpType::Invert)); - ASSERT_EQ(GL_INVALID_ENUM, Enum::to(static_cast(-1))); + ASSERT_EQ(GL_INVALID_ENUM, + Enum::to( + static_cast(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) ASSERT_EQ(StencilOpType{}, Enum::from(GL_RGBA8)); } @@ -115,7 +127,9 @@ TEST(GL, CullFaceSideType) { ASSERT_EQ(CullFaceSideType::Back, enumIdentity(CullFaceSideType::Back)); ASSERT_EQ(CullFaceSideType::FrontAndBack, enumIdentity(CullFaceSideType::FrontAndBack)); - ASSERT_EQ(GL_INVALID_ENUM, Enum::to(static_cast(-1))); + ASSERT_EQ(GL_INVALID_ENUM, + Enum::to( + static_cast(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) ASSERT_EQ(CullFaceSideType{}, Enum::from(GL_RGBA8)); } @@ -123,7 +137,9 @@ TEST(GL, CullFaceWindingType) { ASSERT_EQ(CullFaceWindingType::Clockwise, enumIdentity(CullFaceWindingType::Clockwise)); ASSERT_EQ(CullFaceWindingType::CounterClockwise, enumIdentity(CullFaceWindingType::CounterClockwise)); - ASSERT_EQ(GL_INVALID_ENUM, Enum::to(static_cast(-1))); + ASSERT_EQ(GL_INVALID_ENUM, + Enum::to( + static_cast(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) ASSERT_EQ(CullFaceWindingType{}, Enum::from(GL_RGBA8)); } @@ -132,7 +148,9 @@ TEST(GL, BufferUsageType) { ASSERT_EQ(BufferUsageType::StaticDraw, enumIdentity(BufferUsageType::StaticDraw)); ASSERT_EQ(BufferUsageType::DynamicDraw, enumIdentity(BufferUsageType::DynamicDraw)); - ASSERT_EQ(GL_INVALID_ENUM, Enum::to(static_cast(-1))); + ASSERT_EQ(GL_INVALID_ENUM, + Enum::to( + static_cast(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) ASSERT_EQ(BufferUsageType{}, Enum::from(GL_RGBA8)); } @@ -143,7 +161,9 @@ TEST(GL, TexturePixelType) { ASSERT_EQ(TexturePixelType::Depth, enumIdentity(TexturePixelType::Depth)); ASSERT_EQ(TexturePixelType::Luminance, enumIdentity(TexturePixelType::Luminance)); - ASSERT_EQ(GL_INVALID_ENUM, Enum::to(static_cast(-1))); + ASSERT_EQ(GL_INVALID_ENUM, + Enum::to( + static_cast(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) ASSERT_EQ(TexturePixelType{}, Enum::from(GL_RGBA8)); } @@ -152,7 +172,9 @@ TEST(GL, TextureChannelDataType) { ASSERT_EQ(TextureChannelDataType::HalfFloat, enumIdentity(TextureChannelDataType::HalfFloat)); ASSERT_EQ(TextureChannelDataType::Float, enumIdentity(TextureChannelDataType::Float)); - ASSERT_EQ(GL_INVALID_ENUM, Enum::to(static_cast(-1))); + ASSERT_EQ(GL_INVALID_ENUM, + Enum::to( + static_cast(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) ASSERT_EQ(TextureChannelDataType{}, Enum::from(GL_RGBA8)); } @@ -161,7 +183,9 @@ TEST(GL, RenderbufferPixelType) { ASSERT_EQ(RenderbufferPixelType::Depth, enumIdentity(RenderbufferPixelType::Depth)); ASSERT_EQ(RenderbufferPixelType::DepthStencil, enumIdentity(RenderbufferPixelType::DepthStencil)); - ASSERT_EQ(GL_INVALID_ENUM, Enum::to(static_cast(-1))); + ASSERT_EQ(GL_INVALID_ENUM, + Enum::to( + static_cast(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) ASSERT_EQ(RenderbufferPixelType{}, Enum::from(GL_RGBA8)); } @@ -176,7 +200,9 @@ TEST(GL, sizedFor) { ASSERT_EQ(GL_INVALID_ENUM, Enum::sizedFor(TexturePixelType::Alpha, TextureChannelDataType::Float)); ASSERT_EQ(GL_INVALID_ENUM, - Enum::sizedFor(TexturePixelType::RGBA, static_cast(-1))); + Enum::sizedFor( + TexturePixelType::RGBA, + static_cast(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) } #endif diff --git a/test/util/camera.test.cpp b/test/util/camera.test.cpp index de93f297a..205e5c337 100644 --- a/test/util/camera.test.cpp +++ b/test/util/camera.test.cpp @@ -122,7 +122,7 @@ static std::tuple rotatedFrame(const std::array& qu TEST(FreeCameraOptions, LookAtPoint) { FreeCameraOptions options; vec3 right, up, forward; - const double cosPi4 = 1.0 / std::sqrt(2.0); + const double cosPi4 = 1.0 / std::numbers::sqrt2; // Pitch: 45, bearing: 0 options.position = vec3{{0.5, 0.5, 0.5}};