From 544f918c17ca20b1830fff71a0cb84b137db9840 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Sun, 11 Aug 2024 15:04:14 +0200 Subject: [PATCH] Use C++20 (#2659) --- .clang-format | 2 +- .clang-tidy | 6 ++-- CMakeLists.txt | 12 +++++++- bazel/flags.bzl | 6 ++-- docker/Dockerfile | 1 + include/mbgl/style/expression/expression.hpp | 2 +- .../expression/format_section_override.hpp | 4 ++- .../MapLibreAndroid/src/cpp/CMakeLists.txt | 2 +- platform/darwin/src/image.mm | 9 +++--- platform/darwin/src/local_glyph_rasterizer.mm | 4 +-- .../src/mbgl/storage/main_resource_loader.cpp | 8 ++--- .../src/mbgl/storage/offline_download.cpp | 6 ++-- .../src/mbgl/storage/online_file_source.cpp | 2 +- src/mbgl/gl/vertex_attribute_gl.cpp | 3 -- src/mbgl/map/transform.cpp | 4 +-- src/mbgl/map/zoom_history.hpp | 6 ++-- src/mbgl/renderer/image_manager.hpp | 2 +- .../renderer/layers/render_symbol_layer.cpp | 6 ++-- src/mbgl/renderer/render_orchestrator.cpp | 5 ++-- src/mbgl/renderer/source_state.cpp | 7 ++--- src/mbgl/renderer/style_diff.cpp | 2 +- .../style/expression/compound_expression.cpp | 1 + .../style/sources/geojson_source_impl.cpp | 2 +- src/mbgl/style/style_impl.cpp | 2 -- src/mbgl/text/cross_tile_symbol_index.cpp | 2 +- src/mbgl/text/placement.cpp | 6 ++-- src/mbgl/util/grid_index.hpp | 8 ++--- test/api/annotations.test.cpp | 4 +-- test/api/query.test.cpp | 10 +++---- test/storage/http_file_source.test.cpp | 4 +-- test/storage/main_resource_loader.test.cpp | 30 +++++++++---------- test/storage/offline_database.test.cpp | 4 +-- test/storage/online_file_source.test.cpp | 12 ++++---- test/util/tiny_map.test.cpp | 2 +- 34 files changed, 97 insertions(+), 89 deletions(-) diff --git a/.clang-format b/.clang-format index 36240a832..d0489a0ee 100644 --- a/.clang-format +++ b/.clang-format @@ -13,7 +13,7 @@ PackConstructorInitializers: Never PenaltyBreakAssignment: 80 SortIncludes: false SpacesBeforeTrailingComments: 1 -Standard: c++17 +Standard: c++20 --- Language: Cpp --- diff --git a/.clang-tidy b/.clang-tidy index 5006e2e62..1494fa877 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,5 +1,5 @@ --- -Checks: > +Checks: [ android-*, boost-*, bugprone-*, @@ -108,7 +108,9 @@ Checks: > -readability-static-definition-in-anonymous-namespace, -readability-suspicious-call-argument, -readability-uppercase-literal-suffix, - -readability-use-anyofallof + -readability-use-anyofallof, + -modernize-loop-convert # since C++20 this complains about reverse loops with iterators, but good ranges support only landed in clang 15 +] WarningsAsErrors: '*' HeaderFilterRegex: '.*' CheckOptions: diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a79cfcb1..cc87d95c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,7 +120,7 @@ target_link_libraries( cmake_policy(SET CMP0063 NEW) set(CMAKE_CXX_EXTENSIONS OFF) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_C_EXTENSIONS OFF) @@ -1382,6 +1382,16 @@ set_source_files_properties( $<$,$>:-Wno-deprecated-declarations> ) +# gcc 12 compiler bug, remove when fixed +# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105651 +set_source_files_properties( + ${PROJECT_SOURCE_DIR}/src/mbgl/style/expression/compound_expression.cpp + ${PROJECT_SOURCE_DIR}/src/mbgl/util/font_stack.cpp + PROPERTIES + COMPILE_FLAGS + $<$,$,12.0.0>,$,13.0.0>>:-Wno-restrict> +) + source_group(TREE ${PROJECT_SOURCE_DIR}/include FILES ${INCLUDE_FILES}) source_group(TREE ${PROJECT_SOURCE_DIR}/src FILES ${SRC_FILES}) diff --git a/bazel/flags.bzl b/bazel/flags.bzl index 6855a35cb..32acdc7a2 100644 --- a/bazel/flags.bzl +++ b/bazel/flags.bzl @@ -53,7 +53,7 @@ MSVC_FLAGS = [ "/wd4435", # (boost) Object layout under /vd2 will change due to virtual base "/wd4702", # Unreachable code "/wd4710", # Function not inlined - "/wd5041", # out-of-line definition for constexpr static data member is not needed and is deprecated in C++17 + "/wd5041", # out-of-line definition for constexpr static data member is not needed and is deprecated since C++17 "/wd4946", # reinterpret_cast used between related classes "/wd4459", # declaration of 'x' hides global declaration "/wd4373", # virtual function overrides 'x', previous versions of the compiler did not override when parameters only differed by const/volatile qualifiers @@ -86,12 +86,12 @@ GCC_CLANG_CPP_FLAGS = [ "-fexceptions", "-fno-rtti", "-ftemplate-depth=1024", - "-std=c++17", + "-std=c++20", ] MSVC_CPP_FLAGS = [ "/EHsc", - "/std:c++17", + "/std:c++20", "/GR-", "/permissive-", "/utf-8", diff --git a/docker/Dockerfile b/docker/Dockerfile index 9f545066c..0e55ad471 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -23,6 +23,7 @@ RUN apt-get update \ ccache \ ninja-build \ pkg-config \ + clang-tidy \ && : # end of the RUN cmd - easier to keep a colon at the end of the list, than to keep the backslashes in check # This could also be `.../releases/latest/download/bazelisk-linux-amd64` for the latest version, but for predictability better hardcode it diff --git a/include/mbgl/style/expression/expression.hpp b/include/mbgl/style/expression/expression.hpp index 268fdb980..3ff25e720 100644 --- a/include/mbgl/style/expression/expression.hpp +++ b/include/mbgl/style/expression/expression.hpp @@ -224,7 +224,7 @@ public: virtual void eachChild(const std::function&) const = 0; virtual bool operator==(const Expression&) const = 0; - bool operator!=(const Expression& rhs) const noexcept { return !operator==(rhs); } + bool operator!=(const Expression&) const = default; Kind getKind() const noexcept { return kind; }; const type::Type& getType() const noexcept { return type; }; diff --git a/include/mbgl/style/expression/format_section_override.hpp b/include/mbgl/style/expression/format_section_override.hpp index 214fb3f49..abdc042cd 100644 --- a/include/mbgl/style/expression/format_section_override.hpp +++ b/include/mbgl/style/expression/format_section_override.hpp @@ -35,7 +35,7 @@ public: defaultValue.match([&fn](const style::PropertyExpression& e) { fn(e.getExpression()); }, [](const T&) {}); } - bool operator==(const Expression& e) const final { + bool operator==(const Expression& e) const final override { if (e.getKind() == Kind::FormatSectionOverride) { const auto* other = static_cast(&e); @@ -60,6 +60,8 @@ public: return false; } + bool operator==(const FormatSectionOverride& other) const { return *this == static_cast(other); } + std::vector> possibleOutputs() const final { return {std::nullopt}; } std::string getOperator() const final { return "format-section-override"; } diff --git a/platform/android/MapLibreAndroid/src/cpp/CMakeLists.txt b/platform/android/MapLibreAndroid/src/cpp/CMakeLists.txt index 6890c2451..8ca6e97b8 100644 --- a/platform/android/MapLibreAndroid/src/cpp/CMakeLists.txt +++ b/platform/android/MapLibreAndroid/src/cpp/CMakeLists.txt @@ -5,7 +5,7 @@ project(MapLibreAndroid) add_subdirectory(../../../../../ ../../../../../${ANDROID_ABI}) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) target_compile_options(mbgl-compiler-options INTERFACE -frtti) diff --git a/platform/darwin/src/image.mm b/platform/darwin/src/image.mm index 5b1f83e37..6b3ce3e33 100644 --- a/platform/darwin/src/image.mm +++ b/platform/darwin/src/image.mm @@ -34,11 +34,11 @@ CGImageRef CGImageCreateWithMLNPremultipliedImage(mbgl::PremultipliedImage&& src constexpr const size_t bytesPerPixel = 4; constexpr const size_t bitsPerPixel = bitsPerComponent * bytesPerPixel; const size_t bytesPerRow = bytesPerPixel * src.size.width; + const auto bitmapInfo = static_cast(kCGBitmapByteOrderDefault) | static_cast(kCGImageAlphaPremultipliedLast); return CGImageCreate(src.size.width, src.size.height, bitsPerComponent, bitsPerPixel, bytesPerRow, *colorSpace, - // NOLINTNEXTLINE(bugprone-suspicious-enum-usage) - kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedLast, *provider, + bitmapInfo, *provider, NULL, false, kCGRenderingIntentDefault); } @@ -56,11 +56,10 @@ mbgl::PremultipliedImage MLNPremultipliedImageFromCGImage(CGImageRef src) { constexpr const size_t bitsPerComponent = 8; constexpr const size_t bytesPerPixel = 4; const size_t bytesPerRow = bytesPerPixel * width; + const auto bitmapInfo = static_cast(kCGBitmapByteOrderDefault) | static_cast(kCGImageAlphaPremultipliedLast); CGContextHandle context(CGBitmapContextCreate( - image.data.get(), width, height, bitsPerComponent, bytesPerRow, *colorSpace, - // NOLINTNEXTLINE(bugprone-suspicious-enum-usage) - kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedLast)); + image.data.get(), width, height, bitsPerComponent, bytesPerRow, *colorSpace, bitmapInfo)); if (!context) { throw std::runtime_error("CGBitmapContextCreate failed"); } diff --git a/platform/darwin/src/local_glyph_rasterizer.mm b/platform/darwin/src/local_glyph_rasterizer.mm index f5cded7c1..889b1daaa 100644 --- a/platform/darwin/src/local_glyph_rasterizer.mm +++ b/platform/darwin/src/local_glyph_rasterizer.mm @@ -234,6 +234,7 @@ PremultipliedImage drawGlyphBitmap(GlyphID glyphID, CTFontRef font, GlyphMetrics constexpr const size_t bitsPerComponent = 8; constexpr const size_t bytesPerPixel = 4; const size_t bytesPerRow = bytesPerPixel * size.width; + const auto bitmapInfo = static_cast(kCGBitmapByteOrderDefault) | static_cast(kCGImageAlphaPremultipliedLast); CGContextHandle context(CGBitmapContextCreate( rgbaBitmap.data.get(), @@ -242,8 +243,7 @@ PremultipliedImage drawGlyphBitmap(GlyphID glyphID, CTFontRef font, GlyphMetrics bitsPerComponent, bytesPerRow, *colorSpace, - // NOLINTNEXTLINE(bugprone-suspicious-enum-usage) - kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedLast)); + bitmapInfo)); if (!context) { throw std::runtime_error("CGBitmapContextCreate failed"); } diff --git a/platform/default/src/mbgl/storage/main_resource_loader.cpp b/platform/default/src/mbgl/storage/main_resource_loader.cpp index 2ffff3d7f..66699128f 100644 --- a/platform/default/src/mbgl/storage/main_resource_loader.cpp +++ b/platform/default/src/mbgl/storage/main_resource_loader.cpp @@ -33,8 +33,8 @@ public: ref.invoke(&FileSourceRequest::setResponse, res); }; - auto requestFromNetwork = [=](const Resource& res, - std::unique_ptr parent) -> std::unique_ptr { + auto requestFromNetwork = [=, this](const Resource& res, + std::unique_ptr parent) -> std::unique_ptr { if (!onlineFileSource || !onlineFileSource->canRequest(resource)) { return parent; } @@ -43,7 +43,7 @@ public: std::shared_ptr parentKeepAlive = std::move(parent); MBGL_TIMING_START(watch); - return onlineFileSource->request(res, [=, ptr = parentKeepAlive](const Response& response) { + return onlineFileSource->request(res, [=, ptr = parentKeepAlive, this](const Response& response) { if (databaseFileSource) { databaseFileSource->forward(res, response, nullptr); } @@ -79,7 +79,7 @@ public: tasks[req] = databaseFileSource->request(resource, callback); } else { // Cache request with fallback to network with cache control - tasks[req] = databaseFileSource->request(resource, [=](const Response& response) { + tasks[req] = databaseFileSource->request(resource, [=, this](const Response& response) { Resource res = resource; // Resource is in the cache diff --git a/platform/default/src/mbgl/storage/offline_download.cpp b/platform/default/src/mbgl/storage/offline_download.cpp index dcd4deef3..f9f4bb018 100644 --- a/platform/default/src/mbgl/storage/offline_download.cpp +++ b/platform/default/src/mbgl/storage/offline_download.cpp @@ -273,7 +273,7 @@ void OfflineDownload::activateDownload() { sourceResource.setPriority(Resource::Priority::Low); sourceResource.setUsage(Resource::Usage::Offline); - ensureResource(std::move(sourceResource), [=](const Response& sourceResponse) { + ensureResource(std::move(sourceResource), [=, this](const Response& sourceResponse) { style::conversion::Error error; std::optional tileset = style::conversion::convertJSON(*sourceResponse.data, error); @@ -467,7 +467,7 @@ void OfflineDownload::ensureResource(Resource&& resource, std::functioninvokeCancellable([=]() { + *workRequestsIt = util::RunLoop::Get()->invokeCancellable([=, this]() { requests.erase(workRequestsIt); const auto resourceKind = resource.kind; auto getResourceSizeInDatabase = [&]() -> std::optional { @@ -507,7 +507,7 @@ void OfflineDownload::ensureResource(Resource&& resource, std::functionresponseError(*onlineResponse.error); if (onlineResponse.error->reason == Response::Error::Reason::NotFound) { diff --git a/platform/default/src/mbgl/storage/online_file_source.cpp b/platform/default/src/mbgl/storage/online_file_source.cpp index 3c93075e2..077fc915f 100644 --- a/platform/default/src/mbgl/storage/online_file_source.cpp +++ b/platform/default/src/mbgl/storage/online_file_source.cpp @@ -138,7 +138,7 @@ public: void queueRequest(OnlineFileRequest* req) { pendingRequests.insert(req); } void activateRequest(OnlineFileRequest* req) { - auto callback = [=](const Response& response) { + auto callback = [=, this](const Response& response) { activeRequests.erase(req); req->request.reset(); req->completed(response); diff --git a/src/mbgl/gl/vertex_attribute_gl.cpp b/src/mbgl/gl/vertex_attribute_gl.cpp index 1063405d4..02fa811d7 100644 --- a/src/mbgl/gl/vertex_attribute_gl.cpp +++ b/src/mbgl/gl/vertex_attribute_gl.cpp @@ -153,9 +153,6 @@ std::size_t VertexAttributeGL::getStride() const { return getStride(getGLType()); } -namespace { -const std::vector noData; -} const std::vector& VertexAttributeGL::getRaw(gfx::VertexAttribute& attr, platform::GLenum type) { const auto count = attr.getCount(); const auto stride_ = getStride(type); diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index 93ac496cc..f099c8201 100644 --- a/src/mbgl/map/transform.cpp +++ b/src/mbgl/map/transform.cpp @@ -142,7 +142,7 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim startTransition( camera, animation, - [=](double t) { + [=, this](double t) { Point framePoint = util::interpolate(startPoint, endPoint, t); LatLng frameLatLng = Projection::unproject(framePoint, state.zoomScale(startZoom)); double frameZoom = util::interpolate(startZoom, zoom, t); @@ -299,7 +299,7 @@ void Transform::flyTo(const CameraOptions& camera, const AnimationOptions& anima startTransition( camera, animation, - [=](double k) { + [=, this](double k) { /// s: The distance traveled along the flight path, measured in /// ρ-screenfuls. double s = k * S; diff --git a/src/mbgl/map/zoom_history.hpp b/src/mbgl/map/zoom_history.hpp index 7821499d7..675f6a021 100644 --- a/src/mbgl/map/zoom_history.hpp +++ b/src/mbgl/map/zoom_history.hpp @@ -7,9 +7,9 @@ namespace mbgl { struct ZoomHistory { - float lastZoom; - float lastFloorZoom; - float lastIntegerZoom; + float lastZoom = 0; + float lastFloorZoom = 0; + float lastIntegerZoom = 0; TimePoint lastIntegerZoomTime; bool first = true; diff --git a/src/mbgl/renderer/image_manager.hpp b/src/mbgl/renderer/image_manager.hpp index 8906d9725..465fcd8aa 100644 --- a/src/mbgl/renderer/image_manager.hpp +++ b/src/mbgl/renderer/image_manager.hpp @@ -85,7 +85,7 @@ public: uint64_t imageCorrelationID) = 0; void addPendingRequest(const std::string& imageId) { pendingRequests.insert(imageId); } - bool hasPendingRequest(const std::string& imageId) const { return pendingRequests.count(imageId); } + bool hasPendingRequest(const std::string& imageId) const { return pendingRequests.contains(imageId); } bool hasPendingRequests() const { return !pendingRequests.empty(); } void removePendingRequest(const std::string& imageId) { pendingRequests.erase(imageId); } diff --git a/src/mbgl/renderer/layers/render_symbol_layer.cpp b/src/mbgl/renderer/layers/render_symbol_layer.cpp index 1e3a9db03..f969588da 100644 --- a/src/mbgl/renderer/layers/render_symbol_layer.cpp +++ b/src/mbgl/renderer/layers/render_symbol_layer.cpp @@ -137,10 +137,6 @@ struct SegmentGroup { bool operator<(const SegmentGroup& other) const { return renderable < other.renderable; } }; -namespace { -const SegmentVector emptySegmentVector; -} - #if MLN_LEGACY_RENDERER template @@ -726,6 +722,8 @@ void RenderSymbolLayer::prepare(const LayerPrepareParameters& params) { namespace { +const SegmentVector emptySegmentVector; + template const auto& getProperty(const SymbolBucket::PaintProperties& paintProps, bool isText) { return isText ? paintProps.textBinders.get() : paintProps.iconBinders.get(); diff --git a/src/mbgl/renderer/render_orchestrator.cpp b/src/mbgl/renderer/render_orchestrator.cpp index c6708de84..5901fc828 100644 --- a/src/mbgl/renderer/render_orchestrator.cpp +++ b/src/mbgl/renderer/render_orchestrator.cpp @@ -306,7 +306,7 @@ std::unique_ptr RenderOrchestrator::createRenderTree( std::unordered_set constantsMaskChanged; for (RenderLayer& layer : orderedLayers) { const std::string& id = layer.getID(); - const bool layerAddedOrChanged = layerDiff.added.count(id) || layerDiff.changed.count(id); + const bool layerAddedOrChanged = layerDiff.added.contains(id) || layerDiff.changed.contains(id); evaluationParameters.layerChanged = layerAddedOrChanged; evaluationParameters.hasCrossfade = layer.hasCrossfade(); @@ -383,7 +383,8 @@ std::unique_ptr RenderOrchestrator::createRenderTree( if (layerInfo->source != LayerTypeInfo::Source::NotRequired) { if (layer.baseImpl->source == sourceImpl->id) { const std::string& layerId = layer.getID(); - sourceNeedsRelayout = (sourceNeedsRelayout || hasImageDiff || constantsMaskChanged.count(layerId) || + sourceNeedsRelayout = (sourceNeedsRelayout || hasImageDiff || + constantsMaskChanged.contains(layerId) || hasLayoutDifference(layerDiff, layerId)); if (layerIsVisible) { filteredLayersForSource.push_back(layer.evaluatedProperties); diff --git a/src/mbgl/renderer/source_state.cpp b/src/mbgl/renderer/source_state.cpp index f2457cb2e..1ac0cd8eb 100644 --- a/src/mbgl/renderer/source_state.cpp +++ b/src/mbgl/renderer/source_state.cpp @@ -110,18 +110,17 @@ void SourceFeatureState::removeState(const std::optional& sourceLay const std::optional& stateKey) { std::string sourceLayer = sourceLayerID.value_or(std::string()); - bool sourceLayerDeleted = (deletedStates.count(sourceLayer) > 0) && deletedStates[sourceLayer].empty(); + bool sourceLayerDeleted = deletedStates.contains(sourceLayer) && deletedStates[sourceLayer].empty(); if (sourceLayerDeleted) { return; } if (stateKey && featureID) { - if ((deletedStates.count(sourceLayer) == 0) && (deletedStates[sourceLayer].count(*featureID)) == 0) { + if (!deletedStates.contains(sourceLayer) && !deletedStates[sourceLayer].contains(*featureID)) { deletedStates[sourceLayer][*featureID][*stateKey] = {}; } } else if (featureID) { - bool updateInQueue = (stateChanges.count(sourceLayer) != 0U) && - (stateChanges[sourceLayer].count(*featureID) != 0U); + bool updateInQueue = stateChanges.contains(sourceLayer) && stateChanges[sourceLayer].contains(*featureID); if (updateInQueue) { for (const auto& changeEntry : stateChanges[sourceLayer][*featureID]) { deletedStates[sourceLayer][*featureID][changeEntry.first] = {}; diff --git a/src/mbgl/renderer/style_diff.cpp b/src/mbgl/renderer/style_diff.cpp index fbdf45134..c8d5e768b 100644 --- a/src/mbgl/renderer/style_diff.cpp +++ b/src/mbgl/renderer/style_diff.cpp @@ -62,7 +62,7 @@ LayerDifference diffLayers(const Immutable>& a, } bool hasLayoutDifference(const LayerDifference& layerDiff, const std::string& layerID) { - if (layerDiff.added.count(layerID)) return true; + if (layerDiff.added.contains(layerID)) return true; const auto it = layerDiff.changed.find(layerID); if (it == layerDiff.changed.end()) return false; return it->second.before->hasLayoutDifference(*it->second.after); diff --git a/src/mbgl/style/expression/compound_expression.cpp b/src/mbgl/style/expression/compound_expression.cpp index cd8a8738a..0d0b4dbe2 100644 --- a/src/mbgl/style/expression/compound_expression.cpp +++ b/src/mbgl/style/expression/compound_expression.cpp @@ -1098,6 +1098,7 @@ std::string expectedTypesError(const Definitions& definitions, const std::vector } }); } + std::string signatures = overloads.empty() ? boost::algorithm::join(availableOverloads, " | ") : boost::algorithm::join(overloads, " | "); diff --git a/src/mbgl/style/sources/geojson_source_impl.cpp b/src/mbgl/style/sources/geojson_source_impl.cpp index 413e0bd6e..ae81f0855 100644 --- a/src/mbgl/style/sources/geojson_source_impl.cpp +++ b/src/mbgl/style/sources/geojson_source_impl.cpp @@ -111,7 +111,7 @@ std::shared_ptr GeoJSONData::create(const GeoJSON& geoJSON, }; clusterOptions.reduce = [feature, options](PropertyMap& toReturn, const PropertyMap& toFill) { for (const auto& p : options->clusterProperties) { - if (toFill.count(p.first) == 0) { + if (!toFill.contains(p.first)) { continue; } feature->properties = toFill; diff --git a/src/mbgl/style/style_impl.cpp b/src/mbgl/style/style_impl.cpp index bc32c0e22..36676f8eb 100644 --- a/src/mbgl/style/style_impl.cpp +++ b/src/mbgl/style/style_impl.cpp @@ -28,8 +28,6 @@ namespace mbgl { namespace style { -static Observer nullObserver; - Style::Impl::Impl(std::shared_ptr fileSource_, float pixelRatio, const TaggedScheduler& threadPool_) : fileSource(std::move(fileSource_)), spriteLoader(std::make_unique(pixelRatio, threadPool_)), diff --git a/src/mbgl/text/cross_tile_symbol_index.cpp b/src/mbgl/text/cross_tile_symbol_index.cpp index 91acf2955..df1534c7c 100644 --- a/src/mbgl/text/cross_tile_symbol_index.cpp +++ b/src/mbgl/text/cross_tile_symbol_index.cpp @@ -203,7 +203,7 @@ bool CrossTileSymbolLayerIndex::removeStaleBuckets(const std::unordered_setsecond.bucketInstanceId)) { + if (!currentIDs.contains(it->second.bucketInstanceId)) { removeBucketCrossTileIDs(zoomIndexes.first, it->second); it = zoomIndexes.second.erase(it); tilesChanged = true; diff --git a/src/mbgl/text/placement.cpp b/src/mbgl/text/placement.cpp index feedcbdc8..05b35df4d 100644 --- a/src/mbgl/text/placement.cpp +++ b/src/mbgl/text/placement.cpp @@ -249,7 +249,7 @@ void Placement::placeSymbolBucket(const BucketPlacementData& params, std::set 0; + bool isDuplicate = seenCrossTileIDs.contains(symbolInstance.crossTileID); auto it = opacities.find(symbolInstance.crossTileID); auto opacityState = defaultOpacityState; @@ -1414,7 +1414,7 @@ void TilePlacement::placeLayers(const RenderLayerReferences& layers) { const SymbolInstance& symbol = intersection.symbol; const PlacementContext& ctx = intersection.ctx; currentIntersectionPriority = intersection.priority; - if (seenCrossTileIDs.count(symbol.crossTileID) != 0u) continue; + if (seenCrossTileIDs.contains(symbol.crossTileID)) continue; JointPlacement placement = placeSymbol(symbol, ctx); if (shouldRetryPlacement(placement, ctx)) continue; seenCrossTileIDs.insert(symbol.crossTileID); diff --git a/src/mbgl/util/grid_index.hpp b/src/mbgl/util/grid_index.hpp index 729b612dc..cdec3144b 100644 --- a/src/mbgl/util/grid_index.hpp +++ b/src/mbgl/util/grid_index.hpp @@ -265,7 +265,7 @@ void GridIndex::query(const BBox& queryBBox, std::function::query(const BBox& queryBBox, std::function::query(const BCircle& queryBCircle, std::function::query(const BCircle& queryBCircle, std::functionqueryRenderedFeatures(point0); - EXPECT_EQ(features.size(), 1u); + ASSERT_EQ(features.size(), 1u); EXPECT_EQ(features[0].id.is(), false); EXPECT_EQ(features[0].id, uint64_t(0)); auto features2 = test.frontend.getRenderer()->queryRenderedFeatures(point1); - EXPECT_EQ(features2.size(), 1u); + ASSERT_EQ(features2.size(), 1u); EXPECT_EQ(features[0].id.is(), false); EXPECT_EQ(features2[0].id, uint64_t(1)); } diff --git a/test/api/query.test.cpp b/test/api/query.test.cpp index 87d34feae..ad70ec7d5 100644 --- a/test/api/query.test.cpp +++ b/test/api/query.test.cpp @@ -201,7 +201,7 @@ TEST(Query, QueryFeatureExtensionsSuperclusterChildren) { QueryTest test; auto topClusterFeature = getTopClusterFeature(test); - EXPECT_EQ(topClusterFeature.size(), 1u); + ASSERT_EQ(topClusterFeature.size(), 1u); const auto featureProps = topClusterFeature[0].properties; auto clusterId = featureProps.find("cluster_id"s); auto cluster = featureProps.find("cluster"s); @@ -213,7 +213,7 @@ TEST(Query, QueryFeatureExtensionsSuperclusterChildren) { EXPECT_TRUE(queryChildren.is()); auto children = queryChildren.get(); - EXPECT_EQ(children.size(), 4u); + ASSERT_EQ(children.size(), 4u); // Compare results produced by supercluster with default clustering options. EXPECT_EQ(children[0].properties["cluster_id"].get(), 2u); @@ -229,7 +229,7 @@ TEST(Query, QueryFeatureExtensionsSuperclusterChildren) { TEST(Query, QueryFeatureExtensionsSuperclusterExpansionZoom) { QueryTest test; auto topClusterFeature = getTopClusterFeature(test); - EXPECT_EQ(topClusterFeature.size(), 1u); + ASSERT_EQ(topClusterFeature.size(), 1u); auto queryChildren = test.frontend.getRenderer()->queryFeatureExtensions( "cluster_source"s, topClusterFeature[0], "supercluster"s, "children"s); @@ -251,7 +251,7 @@ TEST(Query, QueryFeatureExtensionsSuperclusterExpansionZoom) { TEST(Query, QueryFeatureExtensionsSuperclusterLeaves) { QueryTest test; auto topClusterFeature = getTopClusterFeature(test); - EXPECT_EQ(topClusterFeature.size(), 1u); + ASSERT_EQ(topClusterFeature.size(), 1u); // Get leaves for cluster 1, with default limit 10, offset 0. auto queryClusterLeaves = test.frontend.getRenderer()->queryFeatureExtensions( @@ -265,7 +265,7 @@ TEST(Query, QueryFeatureExtensionsSuperclusterLeaves) { auto queryClusterLeavesLimit3 = test.frontend.getRenderer()->queryFeatureExtensions( "cluster_source"s, topClusterFeature[0], "supercluster"s, "leaves"s, limitOpts); auto limitLeaves3 = queryClusterLeavesLimit3.get(); - EXPECT_EQ(limitLeaves3.size(), 3u); + ASSERT_EQ(limitLeaves3.size(), 3u); EXPECT_EQ(limitLeaves3[0].properties["name"].get(), "Niagara Falls"s); EXPECT_EQ(limitLeaves3[1].properties["name"].get(), "Cape May"s); diff --git a/test/storage/http_file_source.test.cpp b/test/storage/http_file_source.test.cpp index d4f1b3c9d..68c5e890b 100644 --- a/test/storage/http_file_source.test.cpp +++ b/test/storage/http_file_source.test.cpp @@ -140,9 +140,9 @@ TEST(HTTPFileSource, TEST_REQUIRES_SERVER(ExpiresParsing)) { EXPECT_EQ(nullptr, res.error); ASSERT_TRUE(res.data.get()); EXPECT_EQ("Hello World!", *res.data); - EXPECT_EQ(Timestamp{Seconds(1420797926)}, res.expires); + EXPECT_TRUE(Timestamp{Seconds(1420797926)} == res.expires); EXPECT_FALSE(res.mustRevalidate); - EXPECT_EQ(Timestamp{Seconds(1420794326)}, res.modified); + EXPECT_TRUE(Timestamp{Seconds(1420794326)} == res.modified); EXPECT_EQ("foo", *res.etag); loop.stop(); }); diff --git a/test/storage/main_resource_loader.test.cpp b/test/storage/main_resource_loader.test.cpp index 16e9e0685..383320f87 100644 --- a/test/storage/main_resource_loader.test.cpp +++ b/test/storage/main_resource_loader.test.cpp @@ -42,9 +42,9 @@ TEST(MainResourceLoader, TEST_REQUIRES_SERVER(CacheResponse)) { EXPECT_EQ(response.error, res2.error); ASSERT_TRUE(res2.data.get()); EXPECT_EQ(*response.data, *res2.data); - EXPECT_EQ(response.expires, res2.expires); + EXPECT_TRUE(response.expires == res2.expires); EXPECT_EQ(response.mustRevalidate, res2.mustRevalidate); - EXPECT_EQ(response.modified, res2.modified); + EXPECT_TRUE(response.modified == res2.modified); EXPECT_EQ(response.etag, res2.etag); loop.stop(); @@ -166,7 +166,7 @@ TEST(MainResourceLoader, TEST_REQUIRES_SERVER(CacheRevalidateModified)) { EXPECT_EQ("Response", *res.data); EXPECT_FALSE(bool(res.expires)); EXPECT_TRUE(res.mustRevalidate); - EXPECT_EQ(Timestamp{Seconds(1420070400)}, *res.modified); + EXPECT_TRUE(Timestamp{Seconds(1420070400)} == *res.modified); EXPECT_FALSE(res.etag); // The first response is stored in the cache, but it has @@ -188,7 +188,7 @@ TEST(MainResourceLoader, TEST_REQUIRES_SERVER(CacheRevalidateModified)) { EXPECT_EQ("Response", *res2.data); EXPECT_TRUE(bool(res2.expires)); EXPECT_TRUE(res2.mustRevalidate); - EXPECT_EQ(Timestamp{Seconds(1420070400)}, *res2.modified); + EXPECT_TRUE(Timestamp{Seconds(1420070400)} == *res2.modified); EXPECT_FALSE(res2.etag); } else { // The test server sends a Cache-Control header with a max-age @@ -203,7 +203,7 @@ TEST(MainResourceLoader, TEST_REQUIRES_SERVER(CacheRevalidateModified)) { EXPECT_FALSE(res2.data.get()); EXPECT_TRUE(bool(res2.expires)); EXPECT_TRUE(res2.mustRevalidate); - EXPECT_EQ(Timestamp{Seconds(1420070400)}, *res2.modified); + EXPECT_TRUE(Timestamp{Seconds(1420070400)} == *res2.modified); EXPECT_FALSE(res2.etag); loop.stop(); } @@ -311,7 +311,7 @@ TEST(MainResourceLoader, OptionalNonExpired) { ASSERT_TRUE(res.data.get()); EXPECT_EQ("Cached value", *res.data); ASSERT_TRUE(bool(res.expires)); - EXPECT_EQ(*response.expires, *res.expires); + EXPECT_TRUE(*response.expires == *res.expires); EXPECT_FALSE(res.mustRevalidate); EXPECT_FALSE(bool(res.modified)); EXPECT_FALSE(bool(res.etag)); @@ -344,7 +344,7 @@ TEST(MainResourceLoader, OptionalExpired) { ASSERT_TRUE(res.data.get()); EXPECT_EQ("Cached value", *res.data); ASSERT_TRUE(bool(res.expires)); - EXPECT_EQ(*response.expires, *res.expires); + EXPECT_TRUE(*response.expires == *res.expires); EXPECT_FALSE(res.mustRevalidate); EXPECT_FALSE(bool(res.modified)); EXPECT_FALSE(bool(res.etag)); @@ -406,7 +406,7 @@ TEST(MainResourceLoader, TEST_REQUIRES_SERVER(NoCacheRefreshEtagNotModified)) { EXPECT_TRUE(res.notModified); EXPECT_FALSE(res.data.get()); ASSERT_TRUE(bool(res.expires)); - EXPECT_LT(util::now(), *res.expires); + EXPECT_TRUE(util::now() < *res.expires); EXPECT_TRUE(res.mustRevalidate); EXPECT_FALSE(bool(res.modified)); ASSERT_TRUE(bool(res.etag)); @@ -517,10 +517,10 @@ TEST(MainResourceLoader, TEST_REQUIRES_SERVER(NoCacheRefreshModifiedNotModified) EXPECT_TRUE(res.notModified); EXPECT_FALSE(res.data.get()); ASSERT_TRUE(bool(res.expires)); - EXPECT_LT(util::now(), *res.expires); + EXPECT_TRUE(util::now() < *res.expires); EXPECT_TRUE(res.mustRevalidate); ASSERT_TRUE(bool(res.modified)); - EXPECT_EQ(Timestamp{Seconds(1420070400)}, *res.modified); + EXPECT_TRUE(Timestamp{Seconds(1420070400)} == *res.modified); EXPECT_FALSE(bool(res.etag)); loop.stop(); }); @@ -557,7 +557,7 @@ TEST(MainResourceLoader, TEST_REQUIRES_SERVER(NoCacheRefreshModifiedModified)) { EXPECT_EQ("Response", *res.data); EXPECT_FALSE(bool(res.expires)); EXPECT_TRUE(res.mustRevalidate); - EXPECT_EQ(Timestamp{Seconds(1420070400)}, *res.modified); + EXPECT_TRUE(Timestamp{Seconds(1420070400)} == *res.modified); EXPECT_FALSE(res.etag); loop.stop(); }); @@ -662,10 +662,10 @@ TEST(MainResourceLoader, TEST_REQUIRES_SERVER(RespondToStaleMustRevalidate)) { ASSERT_TRUE(res.data.get()); EXPECT_EQ("Cached value", *res.data); ASSERT_TRUE(res.expires); - EXPECT_EQ(Timestamp{Seconds(1417392000)}, *res.expires); + EXPECT_TRUE(Timestamp{Seconds(1417392000)} == *res.expires); EXPECT_TRUE(res.mustRevalidate); ASSERT_TRUE(res.modified); - EXPECT_EQ(Timestamp{Seconds(1417392000)}, *res.modified); + EXPECT_TRUE(Timestamp{Seconds(1417392000)} == *res.modified); ASSERT_TRUE(res.etag); EXPECT_EQ("snowfall", *res.etag); @@ -702,10 +702,10 @@ TEST(MainResourceLoader, TEST_REQUIRES_SERVER(RespondToStaleMustRevalidate)) { // a 304 Not Modified response. EXPECT_EQ("Prior value", *res.data); ASSERT_TRUE(res.expires); - EXPECT_LE(util::now(), *res.expires); + EXPECT_TRUE(util::now() <= *res.expires); EXPECT_TRUE(res.mustRevalidate); ASSERT_TRUE(res.modified); - EXPECT_EQ(Timestamp{Seconds(1417392000)}, *res.modified); + EXPECT_TRUE(Timestamp{Seconds(1417392000)} == *res.modified); ASSERT_TRUE(res.etag); EXPECT_EQ("snowfall", *res.etag); loop.stop(); diff --git a/test/storage/offline_database.test.cpp b/test/storage/offline_database.test.cpp index bbb44f910..fe7aa34f3 100644 --- a/test/storage/offline_database.test.cpp +++ b/test/storage/offline_database.test.cpp @@ -1790,7 +1790,7 @@ TEST(OfflineDatabase, TEST_REQUIRES_WRITE(MergeDatabaseWithSingleRegion_Update)) auto updatedTile = db.getRegionResource(Resource::tile(tileURL, 1, 0, 0, 1, Tileset::Scheme::XYZ)); auto updatedStamp = updatedTile->first.modified; - EXPECT_EQ(*originalStamp, *updatedStamp); + EXPECT_TRUE(*originalStamp == *updatedStamp); } } @@ -1815,7 +1815,7 @@ TEST(OfflineDatabase, MergeDatabaseWithSingleRegion_NoUpdate) { auto updatedTile = db.getRegionResource(Resource::tile(tileURL, 1, 0, 0, 1, Tileset::Scheme::XYZ)); // Verify the modified timestamp matches the tile in the main db. - EXPECT_EQ(originalStamp, updatedTile->first.modified); + EXPECT_TRUE(originalStamp == updatedTile->first.modified); } TEST(OfflineDatabase, MergeDatabaseWithSingleRegion_AmbientTiles) { diff --git a/test/storage/online_file_source.test.cpp b/test/storage/online_file_source.test.cpp index 5525b1899..1673b13c1 100644 --- a/test/storage/online_file_source.test.cpp +++ b/test/storage/online_file_source.test.cpp @@ -155,7 +155,7 @@ TEST(OnlineFileSource, TEST_REQUIRES_SERVER(RetryDelayOnExpiredTile)) { std::unique_ptr req = fs->request(resource, [&](Response res) { counter++; EXPECT_EQ(nullptr, res.error); - EXPECT_GT(util::now(), *res.expires); + EXPECT_TRUE(util::now() > *res.expires); EXPECT_FALSE(res.mustRevalidate); loop.stop(); }); @@ -177,14 +177,14 @@ TEST(OnlineFileSource, TEST_REQUIRES_SERVER(RetryOnClockSkew)) { switch (counter++) { case 0: { EXPECT_EQ(nullptr, res.error); - EXPECT_GT(util::now(), *res.expires); + EXPECT_TRUE(util::now() > *res.expires); } break; case 1: { EXPECT_EQ(nullptr, res.error); auto now = util::now(); - EXPECT_LT(now + Seconds(40), *res.expires) << "Expiration not interpolated to 60s"; - EXPECT_GT(now + Seconds(80), *res.expires) << "Expiration not interpolated to 60s"; + EXPECT_TRUE(now + Seconds(40) < *res.expires) << "Expiration not interpolated to 60s"; + EXPECT_TRUE(now + Seconds(80) > *res.expires) << "Expiration not interpolated to 60s"; loop.stop(); } break; @@ -385,7 +385,7 @@ TEST(OnlineFileSource, TEST_REQUIRES_SERVER(RateLimitStandard)) { ASSERT_NE(nullptr, res.error); EXPECT_EQ(Response::Error::Reason::RateLimit, res.error->reason); ASSERT_EQ(true, bool(res.error->retryAfter)); - ASSERT_LT(util::now(), res.error->retryAfter); + ASSERT_TRUE(util::now() < res.error->retryAfter); loop.stop(); }); @@ -400,7 +400,7 @@ TEST(OnlineFileSource, TEST_REQUIRES_SERVER(RateLimitMBX)) { ASSERT_NE(nullptr, res.error); EXPECT_EQ(Response::Error::Reason::RateLimit, res.error->reason); ASSERT_EQ(true, bool(res.error->retryAfter)); - ASSERT_LT(util::now(), res.error->retryAfter); + ASSERT_TRUE(util::now() < res.error->retryAfter); loop.stop(); }); diff --git a/test/util/tiny_map.test.cpp b/test/util/tiny_map.test.cpp index 0fa38e4ec..dddcbf66f 100644 --- a/test/util/tiny_map.test.cpp +++ b/test/util/tiny_map.test.cpp @@ -336,7 +336,7 @@ void benchmark(const std::string_view label, for (std::size_t j = 0; j < lookups; ++j) { for (const auto& k : testKeys) { if (map.count(k)) { - do_not_optimize_away++; + do_not_optimize_away = do_not_optimize_away + 1; } } }