Fix clang-tidy 18.1.8 issues (#3800)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Bart Louwers
2025-09-12 14:35:44 +00:00
committed by GitHub
parent 77b4756454
commit ed1f4b3269
77 changed files with 359 additions and 206 deletions

View File

@@ -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: '.*'

View File

@@ -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:

View File

@@ -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",

View File

@@ -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",
)

View File

@@ -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; }

View File

@@ -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));
}

View File

@@ -76,7 +76,7 @@ public:
using ShaderClass = shaders::ShaderSource<ShaderID, gfx::Backend::Type::Vulkan>;
for (const auto& attrib : ShaderClass::attributes) {
if (!propertiesAsUniforms.second.count(attrib.id)) {
if (!propertiesAsUniforms.second.contains(attrib.id)) {
shader->initAttribute(attrib);
}
}

View File

@@ -2,7 +2,11 @@
#include <mbgl/util/work_task.hpp>
#include <atomic>
#include <mutex>
#include <tuple>
#include <type_traits>
#include <utility>
namespace mbgl {
@@ -17,7 +21,7 @@ public:
void operator()() override {
// Lock the mutex while processing so that cancel() will block.
std::lock_guard<std::recursive_mutex> lock(mutex);
if (!*canceled) {
if (!canceled->load(std::memory_order_acquire)) {
invoke(std::make_index_sequence<std::tuple_size_v<P>>{});
}
}
@@ -32,7 +36,7 @@ public:
/// do nothing.
void cancel() override {
std::lock_guard<std::recursive_mutex> lock(mutex);
*canceled = true;
canceled->store(true, std::memory_order_release);
}
private:
@@ -51,7 +55,7 @@ private:
template <class Fn, class... Args>
std::shared_ptr<WorkTask> WorkTask::make(Fn&& fn, Args&&... args) {
auto flag = std::make_shared<std::atomic<bool>>();
*flag = false;
flag->store(false, std::memory_order_relaxed);
auto tuple = std::make_tuple(std::forward<Args>(args)...);
return std::make_shared<WorkTaskImpl<std::decay_t<Fn>, decltype(tuple)>>(

View File

@@ -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<double>& getLastModified() const { return lastModified; }

View File

@@ -102,7 +102,7 @@ class Renderable : public gfx::Renderable {
protected:
Renderable(const Size size_, std::unique_ptr<gfx::RenderableResource> resource_)
: gfx::Renderable(size_, std::move(resource_)) {}
virtual ~Renderable() override = default;
~Renderable() override = default;
public:
void setSize(const Size& size_) { size = size_; }

View File

@@ -54,7 +54,8 @@ public:
int32_t getGraphicsQueueIndex() const { return graphicsQueueIndex; }
int32_t getPresentQueueIndex() const { return presentQueueIndex; }
template <typename T, typename = typename std::enable_if<vk::isVulkanHandleType<T>::value>>
template <typename T>
requires vk::isVulkanHandleType<T>::value
void setDebugName([[maybe_unused]] const T& object, [[maybe_unused]] const std::string& name) const {
#ifdef ENABLE_VULKAN_VALIDATION
if (!debugUtilsEnabled) return;

View File

@@ -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<gfx::UniformBuffer>& set(const size_t id,
std::shared_ptr<gfx::UniformBuffer> uniformBuffer) override;

View File

@@ -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

View File

@@ -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

View File

@@ -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) {

View File

@@ -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, Exception> 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();
}
}
}

View File

@@ -19,12 +19,13 @@ struct jpeg_stream_wrapper {
std::array<JOCTET, BUF_SIZE> buffer;
};
static void init_source(j_decompress_ptr cinfo) {
namespace {
void init_source(j_decompress_ptr cinfo) {
auto* wrap = reinterpret_cast<jpeg_stream_wrapper*>(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<jpeg_stream_wrapper*>(cinfo->src);
wrap->stream->read(reinterpret_cast<char*>(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<jpeg_stream_wrapper*>(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<struct jpeg_source_mgr*>((*cinfo->mem->alloc_small)(
reinterpret_cast<j_common_ptr>(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)

View File

@@ -6,7 +6,7 @@
namespace mbgl {
void Log::platformRecord(EventSeverity severity, const std::string &msg) {
std::cerr << "[" << Enum<EventSeverity>::toString(severity) << "] " << msg << std::endl;
std::cerr << "[" << Enum<EventSeverity>::toString(severity) << "] " << msg << '\n';
}
} // namespace mbgl

View File

@@ -7,15 +7,17 @@ namespace mbgl {
namespace util {
// Prefer high resolution timer if it is monotonic
namespace {
template <typename T, std::enable_if_t<std::chrono::high_resolution_clock::is_steady, T>* = nullptr>
static T sample() {
T sample() {
return std::chrono::duration_cast<T>(std::chrono::high_resolution_clock::now().time_since_epoch());
}
template <typename T, std::enable_if_t<!std::chrono::high_resolution_clock::is_steady, T>* = nullptr>
static T sample() {
T sample() {
return std::chrono::duration_cast<T>(std::chrono::steady_clock::now().time_since_epoch());
}
} // namespace
std::chrono::duration<double> MonotonicTimer::now() {
return sample<std::chrono::duration<double>>();

View File

@@ -10,12 +10,14 @@ extern "C" {
#include <png.h>
}
namespace {
template <size_t max, typename... Args>
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<std::istream*>(png_get_io_ptr(png_ptr));
fin->read(reinterpret_cast<char*>(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)

View File

@@ -35,6 +35,8 @@ struct Watch {
case UV_READABLE | UV_WRITABLE:
watchEvent = RunLoop::Event::ReadWrite;
break;
default:
break;
}
watch->eventCallback(watch->fd, watchEvent);

View File

@@ -8,6 +8,7 @@
#include <vector>
#include <string>
#include <optional>
#include <type_traits>
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<As...>>;
static_assert(std::is_same<attributes::pos, TypeOfFirst>::value ||
std::is_same<attributes::pos_offset, TypeOfFirst>::value ||
std::is_same<attributes::pos_normal, TypeOfFirst>::value,
static_assert(std::is_same_v<attributes::pos, TypeOfFirst> ||
std::is_same_v<attributes::pos_offset, TypeOfFirst> ||
std::is_same_v<attributes::pos_normal, TypeOfFirst>,
"Program must start with position related attribute.");
return concat_literals<&string_literal<'a', '_'>::value, TypeOfFirst::name>::value();
}

View File

@@ -35,8 +35,9 @@ gfx::ColorBlendEquationType Enum<gfx::ColorBlendEquationType>::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<gfx::ColorBlendFactorType>::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<gfx::DepthFunctionType>::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<gfx::StencilFunctionType>::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<gfx::StencilOpType>::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<gfx::CullFaceSideType>::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<gfx::CullFaceWindingType>::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<gfx::BufferUsageType>::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<gfx::TexturePixelType>::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<gfx::TextureChannelDataType>::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<gfx::RenderbufferPixelType>::from(const platform
return gfx::RenderbufferPixelType::Depth;
case GL_DEPTH24_STENCIL8:
return gfx::RenderbufferPixelType::DepthStencil;
default:
return {};
}
return {};
}
template <>

View File

@@ -54,12 +54,12 @@ std::unique_ptr<TimestampQueryLoader> &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) {

View File

@@ -63,7 +63,7 @@ void bindUniform<std::array<double, 16>>(UniformLocation location, const std::ar
template <>
void bindUniform<bool>(UniformLocation location, const bool& t) {
return bindUniform(location, int32_t(t));
bindUniform(location, int32_t(t));
}
template <>

View File

@@ -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 <typename T>
static std::size_t pad(std::vector<T>& vector, std::size_t size, T value) {
std::size_t pad(std::vector<T>& 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,

View File

@@ -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];
}

View File

@@ -72,9 +72,10 @@ int VertexAttributeGL::getStride(GLenum glType) {
}
}
namespace detail {
// Copy the transformed type into the buffer, returning true if it works.
template <typename T, typename R, typename Func /* R(T) */>
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<T>(&element)) {
*reinterpret_cast<R*>(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 <typename T, typename R>
static bool get(const gfx::VertexAttribute::ElementType& element, uint8_t* buffer) {
bool get(const gfx::VertexAttribute::ElementType& element, uint8_t* buffer) {
return get<T, R>(element, buffer, [](T x) -> R { return static_cast<R>(x); });
}
// Copy a particular type from the variant into the specified buffer, returning true if it works.
template <typename T>
static bool get(const gfx::VertexAttribute::ElementType& element, uint8_t* buffer) {
bool get(const gfx::VertexAttribute::ElementType& element, uint8_t* buffer) {
return get<T, T>(element, buffer, [](T x) -> T { return x; });
}
} // namespace detail
template <typename T, typename R>
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<float>(element, buffer) || gl::get<float, std::int32_t>(element, buffer);
return detail::get<float>(element, buffer) || detail::get<float, std::int32_t>(element, buffer);
case GL_FLOAT_VEC2:
return gl::get<float2>(element, buffer) ||
gl::get<int2, float2>(element, buffer, [](int2 x) { return float2{(float)x[0], (float)x[1]}; });
return detail::get<float2>(element, buffer) ||
detail::get<int2, float2>(element, buffer, [](int2 x) { return float2{(float)x[0], (float)x[1]}; });
case GL_FLOAT_VEC3:
return gl::get<float3>(element, buffer);
return detail::get<float3>(element, buffer);
case GL_FLOAT_VEC4:
case GL_FLOAT_MAT2:
return gl::get<float4>(element, buffer) ||
gl::get<int4, float4>(
return detail::get<float4>(element, buffer) ||
detail::get<int4, float4>(
element,
buffer,
[](int4 x) { return float4{(float)x[0], (float)x[1], (float)x[2], (float)x[3]}; }) ||
gl::get<ushort8, float4>(element, buffer, [](ushort8 x) {
detail::get<ushort8, float4>(element, buffer, [](ushort8 x) {
return float4{(float)x[0], (float)x[1], (float)x[2], (float)x[3]};
});
case GL_INT:
return gl::get<std::int32_t>(element, buffer) || gl::get<float, std::int32_t>(element, buffer);
return detail::get<std::int32_t>(element, buffer) || detail::get<float, std::int32_t>(element, buffer);
case GL_UNSIGNED_INT:
return gl::get<std::int32_t, std::uint32_t>(element, buffer) ||
gl::get<float, std::uint32_t>(element, buffer);
return detail::get<std::int32_t, std::uint32_t>(element, buffer) ||
detail::get<float, std::uint32_t>(element, buffer);
case GL_INT_VEC2:
return gl::get<int2>(element, buffer) || gl::get<float2, int2>(element, buffer, [](float2 x) {
return detail::get<int2>(element, buffer) || detail::get<float2, int2>(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<int3>(element, buffer);
return detail::get<int3>(element, buffer);
case GL_UNSIGNED_INT_VEC3:
return false; // TODO
case GL_INT_VEC4:
return gl::get<int4>(element, buffer);
return detail::get<int4>(element, buffer);
case GL_UNSIGNED_INT_VEC4:
return false; // TODO
default:

View File

@@ -28,11 +28,13 @@ namespace mbgl {
using namespace style;
namespace {
template <class Property>
bool has(const style::SymbolLayoutProperties::PossiblyEvaluated& layout) {
return layout.get<Property>().match([](const typename Property::Type& t) { return !t.empty(); },
[](const auto&) { return true; });
}
} // namespace
expression::Value sectionOptionsToValue(const SectionOptions& options) {
std::unordered_map<std::string, expression::Value> 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<Immutable<style::LayerProperties>>& layers,

View File

@@ -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());

View File

@@ -5,7 +5,6 @@
#include <mbgl/style/conversion_impl.hpp>
#include <mbgl/renderer/bucket.hpp>
#include <iostream>
#include <string>
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()) {

View File

@@ -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;

View File

@@ -10,12 +10,9 @@
#include <mbgl/style/layers/custom_layer_render_parameters.hpp>
#endif
#include <mbgl/gfx/drawable.hpp>
#include <mbgl/gfx/context.hpp>
#include <mbgl/gfx/renderer_backend.hpp>
#include <mbgl/style/properties.hpp>
#include <iostream>
using namespace mbgl;
namespace mbgl {

View File

@@ -32,10 +32,11 @@ bool CircleBucket::hasData() const {
return !segments.empty();
}
namespace {
template <class Property>
static float get(const CirclePaintProperties::PossiblyEvaluated& evaluated,
const std::string& id,
const std::map<std::string, CircleBinders>& paintPropertyBinders) {
float get(const CirclePaintProperties::PossiblyEvaluated& evaluated,
const std::string& id,
const std::map<std::string, CircleBinders>& paintPropertyBinders) {
auto it = paintPropertyBinders.find(id);
if (it == paintPropertyBinders.end() || !it->second.statistics<Property>().max()) {
return evaluated.get<Property>().constantOr(Property::defaultValue());
@@ -43,6 +44,7 @@ static float get(const CirclePaintProperties::PossiblyEvaluated& evaluated,
return *it->second.statistics<Property>().max();
}
}
} // namespace
float CircleBucket::getQueryRadius(const RenderLayer& layer) const {
const auto& evaluated = getEvaluated<CircleLayerProperties>(layer.evaluatedProperties);

View File

@@ -134,10 +134,11 @@ bool LineBucket::hasData() const {
return !segments.empty();
}
namespace {
template <class Property>
static float get(const LinePaintProperties::PossiblyEvaluated& evaluated,
const std::string& id,
const std::map<std::string, LineBinders>& paintPropertyBinders) {
float get(const LinePaintProperties::PossiblyEvaluated& evaluated,
const std::string& id,
const std::map<std::string, LineBinders>& paintPropertyBinders) {
auto it = paintPropertyBinders.find(id);
if (it == paintPropertyBinders.end() || !it->second.statistics<Property>().max()) {
return evaluated.get<Property>().constantOr(Property::defaultValue());
@@ -145,6 +146,7 @@ static float get(const LinePaintProperties::PossiblyEvaluated& evaluated,
return *it->second.statistics<Property>().max();
}
}
} // namespace
float LineBucket::getQueryRadius(const RenderLayer& layer) const {
const auto& evaluated = getEvaluated<LineLayerProperties>(layer.evaluatedProperties);

View File

@@ -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);
}
}

View File

@@ -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;
}

View File

@@ -58,7 +58,9 @@ std::unique_ptr<RenderSource> RenderSource::create(const Immutable<Source::Impl>
return nullptr;
}
static RenderSourceObserver nullObserver;
namespace {
RenderSourceObserver nullObserver;
}
RenderSource::RenderSource(Immutable<style::Source::Impl> impl)
: baseImpl(std::move(impl)),

View File

@@ -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

View File

@@ -22,8 +22,10 @@ namespace mbgl {
using namespace style;
static TileObserver nullObserver;
static const std::map<OverscaledTileID, std::unique_ptr<Tile>> emptyPrefetchedTiles;
namespace {
TileObserver nullObserver;
const std::map<OverscaledTileID, std::unique_ptr<Tile>> emptyPrefetchedTiles;
} // namespace
TilePyramid::TilePyramid(const TaggedScheduler& threadPool_)
: cache(threadPool_),

View File

@@ -17,7 +17,9 @@
namespace mbgl {
static SpriteLoaderObserver nullObserver;
namespace {
SpriteLoaderObserver nullObserver;
}
struct SpriteLoader::Data {
std::shared_ptr<const std::string> image;
@@ -50,7 +52,7 @@ void SpriteLoader::load(const std::optional<style::Sprite> sprite, FileSource& f
std::lock_guard<std::mutex> 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<style::Sprite> sprite, FileSource& f
std::lock_guard<std::mutex> 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) {

View File

@@ -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<double> getMercCoord(int32_t x, int32_t y, int8_t z) {
mapbox::geometry::point<double> 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<double> 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<int32_t>(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};

View File

@@ -11,7 +11,7 @@ std::optional<bool> Converter<bool>::operator()(const Convertible& value, Error&
error.message = "value must be a boolean";
return std::nullopt;
}
return *converted;
return converted;
}
std::optional<float> Converter<float>::operator()(const Convertible& value, Error& error) const {
@@ -20,7 +20,7 @@ std::optional<float> Converter<float>::operator()(const Convertible& value, Erro
error.message = "value must be a number";
return std::nullopt;
}
return *converted;
return converted;
}
std::optional<std::string> Converter<std::string>::operator()(const Convertible& value, Error& error) const {
@@ -29,7 +29,7 @@ std::optional<std::string> Converter<std::string>::operator()(const Convertible&
error.message = "value must be a string";
return std::nullopt;
}
return *converted;
return converted;
}
template <class T>
@@ -47,7 +47,7 @@ std::optional<T> Converter<T, typename std::enable_if_t<std::is_enum_v<T>>>::ope
return std::nullopt;
}
return *result;
return result;
}
template <class T>
@@ -111,7 +111,7 @@ std::optional<Color> Converter<Color>::operator()(const Convertible& value, Erro
return std::nullopt;
}
return *color;
return color;
}
std::optional<Padding> Converter<Padding>::operator()(const Convertible& value, Error& error) const {

View File

@@ -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<mbgl::Value> serializeLegacyFilter(const Convertible& values);
@@ -34,12 +36,13 @@ std::optional<Filter> Converter<Filter>::operator()(const Convertible& value, Er
assert(error.message.size() > 0);
return std::nullopt;
}
return Filter(std::optional<std::unique_ptr<Expression>>(std::move(*expression)), serializeLegacyFilter(value));
return Filter(std::optional<std::unique_ptr<Expression>>(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<std::vector<std::unique_ptr<Expression>>> args,

View File

@@ -17,7 +17,8 @@ namespace style {
namespace conversion {
// A tile source can either specify a URL to TileJSON, or inline TileJSON.
static std::optional<variant<std::string, Tileset>> convertURLOrTileset(const Convertible& value, Error& error) {
namespace {
std::optional<variant<std::string, Tileset>> convertURLOrTileset(const Convertible& value, Error& error) {
auto urlVal = objectMember(value, "url");
if (!urlVal) {
std::optional<Tileset> tileset = convert<Tileset>(value, error);
@@ -36,9 +37,9 @@ static std::optional<variant<std::string, Tileset>> convertURLOrTileset(const Co
return {*url};
}
static std::optional<std::unique_ptr<Source>> convertRasterSource(const std::string& id,
const Convertible& value,
Error& error) {
std::optional<std::unique_ptr<Source>> convertRasterSource(const std::string& id,
const Convertible& value,
Error& error) {
std::optional<variant<std::string, Tileset>> urlOrTileset = convertURLOrTileset(value, error);
if (!urlOrTileset) {
return std::nullopt;
@@ -58,9 +59,9 @@ static std::optional<std::unique_ptr<Source>> convertRasterSource(const std::str
return {std::make_unique<RasterSource>(id, std::move(*urlOrTileset), tileSize)};
}
static std::optional<std::unique_ptr<Source>> convertRasterDEMSource(const std::string& id,
const Convertible& value,
Error& error) {
std::optional<std::unique_ptr<Source>> convertRasterDEMSource(const std::string& id,
const Convertible& value,
Error& error) {
std::optional<variant<std::string, Tileset>> urlOrTileset = convertURLOrTileset(value, error);
if (!urlOrTileset) {
return std::nullopt;
@@ -87,9 +88,9 @@ static std::optional<std::unique_ptr<Source>> convertRasterDEMSource(const std::
return {std::make_unique<RasterDEMSource>(id, std::move(*urlOrTileset), tileSize, options)};
}
static std::optional<std::unique_ptr<Source>> convertVectorSource(const std::string& id,
const Convertible& value,
Error& error) {
std::optional<std::unique_ptr<Source>> convertVectorSource(const std::string& id,
const Convertible& value,
Error& error) {
std::optional<variant<std::string, Tileset>> urlOrTileset = convertURLOrTileset(value, error);
if (!urlOrTileset) {
return std::nullopt;
@@ -115,9 +116,9 @@ static std::optional<std::unique_ptr<Source>> convertVectorSource(const std::str
return {std::make_unique<VectorSource>(id, std::move(*urlOrTileset), std::move(maxzoom), std::move(minzoom))};
}
static std::optional<std::unique_ptr<Source>> convertGeoJSONSource(const std::string& id,
const Convertible& value,
Error& error) {
std::optional<std::unique_ptr<Source>> 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<std::unique_ptr<Source>> convertGeoJSONSource(const std::st
return {std::move(result)};
}
static std::optional<std::unique_ptr<Source>> convertImageSource(const std::string& id,
const Convertible& value,
Error& error) {
std::optional<std::unique_ptr<Source>> 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<std::unique_ptr<Source>> convertImageSource(const std::stri
return {std::move(result)};
}
} // namespace
std::optional<std::unique_ptr<Source>> Converter<std::unique_ptr<Source>>::operator()(const Convertible& value,
Error& error,

View File

@@ -25,8 +25,7 @@ std::optional<Sprite> Converter<Sprite>::operator()(const Convertible& value, Er
}
spriteURL = toString(*urlValue);
const Sprite sprite(*id, *spriteURL);
return sprite;
return Sprite(*id, *spriteURL);
}
} // namespace conversion

View File

@@ -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<Expression> lhs_, std::unique_ptr<Expression> rhs_)
: Expression(Kind::Comparison, type::Boolean, depsOf(lhs_) | depsOf(rhs_)),

View File

@@ -237,6 +237,7 @@ std::unique_ptr<detail::SignatureBase> makeSignature(std::string name,
}
} // namespace
} // namespace detail
namespace {
Value featureIdAsExpressionValue(const EvaluationContext& params) {
assert(params.feature);
@@ -299,6 +300,8 @@ std::optional<std::string> featureIdAsString(const EvaluationContext& params) {
return id.match([](std::string value) { return value; }, [](const auto&) { return std::optional<std::string>(); });
};
} // unnamed namespace
const auto& eCompoundExpression() {
static auto signature = detail::makeSignature("e", []() -> Result<double> { return std::numbers::e; });
return signature;
@@ -990,6 +993,8 @@ const auto& filterInCompoundExpression() {
return signature;
}
namespace {
using ParseCompoundFunction = const std::unique_ptr<detail::SignatureBase>& (*)();
constexpr const auto compoundExpressionRegistry =
mapbox::eternal::hash_map<mapbox::eternal::string, ParseCompoundFunction>({
@@ -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<DefinitionIterator, DefinitionIterator>;
namespace {
std::string expectedTypesError(const Definitions& definitions, const std::vector<std::unique_ptr<Expression>>& args) {
std::vector<std::string> availableOverloads; // Only used if there are no overloads
// with matching number of args

View File

@@ -839,7 +839,7 @@ std::optional<GeoJSON> 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);
}

View File

@@ -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());

View File

@@ -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;
}

View File

@@ -196,12 +196,14 @@ std::optional<InputType> parseInputValue(const Convertible& input,
return result;
}
namespace {
template <typename T>
static ParseResult create(type::Type outputType,
std::unique_ptr<Expression> input,
std::vector<std::pair<std::vector<InputType>, std::unique_ptr<Expression>>> branches,
std::unique_ptr<Expression> otherwise,
ParsingContext& ctx) {
ParseResult create(type::Type outputType,
std::unique_ptr<Expression> input,
std::vector<std::pair<std::vector<InputType>, std::unique_ptr<Expression>>> branches,
std::unique_ptr<Expression> otherwise,
ParsingContext& ctx) {
typename Match<T>::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);

View File

@@ -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> impl)
: baseImpl(std::move(impl)),

View File

@@ -17,7 +17,9 @@
namespace mbgl {
namespace style {
static LightObserver nullObserver;
namespace {
LightObserver nullObserver;
}
Light::Light(Immutable<Light::Impl> impl_)
: impl(std::move(impl_)),

View File

@@ -6,7 +6,9 @@
namespace mbgl {
namespace style {
static SourceObserver nullObserver;
namespace {
SourceObserver nullObserver;
}
Source::Source(Immutable<Impl> impl)
: baseImpl(std::move(impl)),

View File

@@ -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,

View File

@@ -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<GlyphIDType>(glyphType);
}

View File

@@ -14,7 +14,9 @@
namespace mbgl {
static GlyphManagerObserver nullObserver;
namespace {
GlyphManagerObserver nullObserver;
}
GlyphManager::GlyphManager(std::unique_ptr<LocalGlyphRasterizer> localGlyphRasterizer_)
: observer(&nullObserver),

View File

@@ -38,7 +38,7 @@ HBShaper::~HBShaper() {
void HBShaper::createComplexGlyphIDs(const std::u16string &text,
std::vector<GlyphID> &glyphIDs,
std::vector<HBShapeAdjust> &adjusts) {
return impl->createComplexGlyphIDs(text, glyphIDs, adjusts);
impl->createComplexGlyphIDs(text, glyphIDs, adjusts);
}
Glyph HBShaper::rasterizeGlyph(const GlyphID &glyph) {

View File

@@ -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) {

View File

@@ -19,8 +19,8 @@
using namespace std::numbers;
namespace mbgl {
namespace {
double signedArea(const GeometryCoordinates& ring) {
double sum = 0;

View File

@@ -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_),

View File

@@ -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;

View File

@@ -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);

View File

@@ -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, Milliseco
return buffer;
}
Timestamp parseTimestamp(const char *timestamp) {
Timestamp parseTimestamp(const char* timestamp) {
return std::chrono::time_point_cast<Seconds>(std::chrono::system_clock::from_time_t(parse_date(timestamp)));
}

View File

@@ -56,7 +56,7 @@ std::optional<std::string> readFile(const std::string &filename,
size_t size = static_cast<size_t>(dataRange->second - dataRange->first + 1);
std::string data(size, '\0');
file.seekg(static_cast<std::streampos>(dataRange->first));
file.read(&data[0], static_cast<std::streamsize>(size));
file.read(data.data(), static_cast<std::streamsize>(size));
return data;
} else {
std::stringstream data;

View File

@@ -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");

View File

@@ -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,

View File

@@ -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<SurfaceRenderableResource>();
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);

View File

@@ -8,7 +8,7 @@
#include <mbgl/util/monotonic_timer.hpp>
#include <cassert>
#include <math.h>
#include <cmath>
#define USE_DESCRIPTOR_POOL_RESET

View File

@@ -143,7 +143,7 @@ bool OffscreenTexture::isRenderable() {
}
PremultipliedImage OffscreenTexture::readStillImage() {
return getResource<OffscreenTextureResource>().readStillImage();
return getResource<OffscreenTextureResource>().readStillImage(); // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks)
}
const gfx::Texture2DPtr& OffscreenTexture::getTexture() {

View File

@@ -72,10 +72,12 @@ static struct {
namespace mbgl {
namespace vulkan {
namespace {
template <typename T, typename F>
static bool checkAvailability(const std::vector<T>& availableValues,
const std::vector<const char*>& requiredValues,
const F& getter) {
bool checkAvailability(const std::vector<T>& availableValues,
const std::vector<const char*>& 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<T>& 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<gfx::Context> RendererBackend::createContext() {

View File

@@ -6,7 +6,7 @@
#include <mbgl/vulkan/command_encoder.hpp>
#include <mbgl/util/logging.hpp>
#include <math.h>
#include <cmath>
namespace mbgl {
namespace vulkan {

View File

@@ -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--;

View File

@@ -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,

View File

@@ -18,7 +18,9 @@ TEST(GL, DrawModeType) {
ASSERT_EQ(GL_TRIANGLES, Enum<DrawModeType>::to(DrawModeType::Triangles));
ASSERT_EQ(GL_TRIANGLE_STRIP, Enum<DrawModeType>::to(DrawModeType::TriangleStrip));
ASSERT_EQ(GL_TRIANGLE_FAN, Enum<DrawModeType>::to(DrawModeType::TriangleFan));
ASSERT_EQ(GL_INVALID_ENUM, Enum<DrawModeType>::to(static_cast<DrawModeType>(-1)));
ASSERT_EQ(
GL_INVALID_ENUM,
Enum<DrawModeType>::to(static_cast<DrawModeType>(-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<ColorBlendEquationType>::to(static_cast<ColorBlendEquationType>(-1)));
ASSERT_EQ(GL_INVALID_ENUM,
Enum<ColorBlendEquationType>::to(
static_cast<ColorBlendEquationType>(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange)
ASSERT_EQ(ColorBlendEquationType{}, Enum<ColorBlendEquationType>::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<ColorBlendFactorType>::to(static_cast<ColorBlendFactorType>(-1)));
ASSERT_EQ(GL_INVALID_ENUM,
Enum<ColorBlendFactorType>::to(
static_cast<ColorBlendFactorType>(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange)
ASSERT_EQ(ColorBlendFactorType{}, Enum<ColorBlendFactorType>::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<DepthFunctionType>::to(static_cast<DepthFunctionType>(-1)));
ASSERT_EQ(GL_INVALID_ENUM,
Enum<DepthFunctionType>::to(
static_cast<DepthFunctionType>(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange)
ASSERT_EQ(DepthFunctionType{}, Enum<DepthFunctionType>::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<StencilFunctionType>::to(static_cast<StencilFunctionType>(-1)));
ASSERT_EQ(GL_INVALID_ENUM,
Enum<StencilFunctionType>::to(
static_cast<StencilFunctionType>(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange)
ASSERT_EQ(StencilFunctionType{}, Enum<StencilFunctionType>::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<StencilOpType>::to(static_cast<StencilOpType>(-1)));
ASSERT_EQ(GL_INVALID_ENUM,
Enum<StencilOpType>::to(
static_cast<StencilOpType>(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange)
ASSERT_EQ(StencilOpType{}, Enum<StencilOpType>::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<CullFaceSideType>::to(static_cast<CullFaceSideType>(-1)));
ASSERT_EQ(GL_INVALID_ENUM,
Enum<CullFaceSideType>::to(
static_cast<CullFaceSideType>(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange)
ASSERT_EQ(CullFaceSideType{}, Enum<CullFaceSideType>::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<CullFaceWindingType>::to(static_cast<CullFaceWindingType>(-1)));
ASSERT_EQ(GL_INVALID_ENUM,
Enum<CullFaceWindingType>::to(
static_cast<CullFaceWindingType>(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange)
ASSERT_EQ(CullFaceWindingType{}, Enum<CullFaceWindingType>::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<BufferUsageType>::to(static_cast<BufferUsageType>(-1)));
ASSERT_EQ(GL_INVALID_ENUM,
Enum<BufferUsageType>::to(
static_cast<BufferUsageType>(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange)
ASSERT_EQ(BufferUsageType{}, Enum<BufferUsageType>::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<TexturePixelType>::to(static_cast<TexturePixelType>(-1)));
ASSERT_EQ(GL_INVALID_ENUM,
Enum<TexturePixelType>::to(
static_cast<TexturePixelType>(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange)
ASSERT_EQ(TexturePixelType{}, Enum<TexturePixelType>::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<TextureChannelDataType>::to(static_cast<TextureChannelDataType>(-1)));
ASSERT_EQ(GL_INVALID_ENUM,
Enum<TextureChannelDataType>::to(
static_cast<TextureChannelDataType>(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange)
ASSERT_EQ(TextureChannelDataType{}, Enum<TextureChannelDataType>::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<RenderbufferPixelType>::to(static_cast<RenderbufferPixelType>(-1)));
ASSERT_EQ(GL_INVALID_ENUM,
Enum<RenderbufferPixelType>::to(
static_cast<RenderbufferPixelType>(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange)
ASSERT_EQ(RenderbufferPixelType{}, Enum<RenderbufferPixelType>::from(GL_RGBA8));
}
@@ -176,7 +200,9 @@ TEST(GL, sizedFor) {
ASSERT_EQ(GL_INVALID_ENUM,
Enum<gfx::TexturePixelType>::sizedFor(TexturePixelType::Alpha, TextureChannelDataType::Float));
ASSERT_EQ(GL_INVALID_ENUM,
Enum<gfx::TexturePixelType>::sizedFor(TexturePixelType::RGBA, static_cast<TextureChannelDataType>(-1)));
Enum<gfx::TexturePixelType>::sizedFor(
TexturePixelType::RGBA,
static_cast<TextureChannelDataType>(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange)
}
#endif

View File

@@ -122,7 +122,7 @@ static std::tuple<vec3, vec3, vec3> rotatedFrame(const std::array<double, 4>& 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}};