diff --git a/.clang-tidy b/.clang-tidy index 6f6a82c2b..c9aafc8c2 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -3,28 +3,28 @@ Checks: - "-*" - "misc-include-cleaner" - "bugprone-argument-comment" - #- "bugprone-assert-side-effect" - #- "bugprone-assignment-in-if-condition" - #- "bugprone-bad-signal-to-kill-thread" - #- "bugprone-bool-pointer-implicit-conversion" - #- "bugprone-branch-clone" - #- "bugprone-casting-through-void" - #- "bugprone-chained-comparison" - #- "bugprone-compare-pointer-to-member-virtual-function" - #- "bugprone-copy-constructor-init" + - "bugprone-assert-side-effect" + - "bugprone-assignment-in-if-condition" + - "bugprone-bad-signal-to-kill-thread" + - "bugprone-bool-pointer-implicit-conversion" + - "bugprone-branch-clone" + - "bugprone-casting-through-void" + - "bugprone-chained-comparison" + - "bugprone-compare-pointer-to-member-virtual-function" + - "bugprone-copy-constructor-init" #- "bugprone-crtp-constructor-accessibility" - #- "bugprone-dangling-handle" - #- "bugprone-dynamic-static-initializers" - #- "-bugprone-easily-swappable-parameters" - #- "bugprone-empty-catch" + - "bugprone-dangling-handle" + - "bugprone-dynamic-static-initializers" + - "-bugprone-easily-swappable-parameters" + - "bugprone-empty-catch" #- "bugprone-exception-escape" - #- "bugprone-fold-init-type" - #- "bugprone-forward-declaration-namespace" - #- "bugprone-forwarding-reference-overload" - #- "bugprone-implicit-widening-of-multiplication-result" - #- "bugprone-inaccurate-erase" - #- "bugprone-inc-dec-in-conditions" - #- "bugprone-incorrect-enable-if" + - "bugprone-fold-init-type" + - "bugprone-forward-declaration-namespace" + - "bugprone-forwarding-reference-overload" + - "bugprone-implicit-widening-of-multiplication-result" + - "bugprone-inaccurate-erase" + - "bugprone-inc-dec-in-conditions" + - "bugprone-incorrect-enable-if" #- "bugprone-incorrect-roundings" #- "bugprone-infinite-loop" #- "bugprone-unhandled-self-assignment" diff --git a/Cesium3DTilesSelection/include/Cesium3DTilesSelection/TilesetOptions.h b/Cesium3DTilesSelection/include/Cesium3DTilesSelection/TilesetOptions.h index bb09588cb..72030d7b1 100644 --- a/Cesium3DTilesSelection/include/Cesium3DTilesSelection/TilesetOptions.h +++ b/Cesium3DTilesSelection/include/Cesium3DTilesSelection/TilesetOptions.h @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -204,7 +205,7 @@ struct CESIUM3DTILESSELECTION_API TilesetOptions { * unloaded until the total is under this number or until only required tiles * remain, whichever comes first. */ - int64_t maximumCachedBytes = 512 * 1024 * 1024; + int64_t maximumCachedBytes = static_cast(512 * 1024 * 1024); /** * @brief A table that maps the camera height above the ellipsoid to a fog diff --git a/Cesium3DTilesSelection/src/EllipsoidTilesetLoader.cpp b/Cesium3DTilesSelection/src/EllipsoidTilesetLoader.cpp index 346a84a96..9c326a04e 100644 --- a/Cesium3DTilesSelection/src/EllipsoidTilesetLoader.cpp +++ b/Cesium3DTilesSelection/src/EllipsoidTilesetLoader.cpp @@ -178,9 +178,11 @@ EllipsoidTilesetLoader::createGeometry(const Tile& tile) const { static constexpr uint16_t resolution = 24; std::vector indices; - indices.reserve(6 * (resolution - 1) * (resolution - 1)); + indices.reserve( + static_cast(6 * (resolution - 1) * (resolution - 1))); - std::vector vertices(resolution * resolution); + std::vector vertices( + static_cast(resolution * resolution)); std::vector normals(vertices.size()); const Ellipsoid& ellipsoid = _projection.getEllipsoid(); diff --git a/Cesium3DTilesSelection/src/Tileset.cpp b/Cesium3DTilesSelection/src/Tileset.cpp index 91b8845df..9d93e76fe 100644 --- a/Cesium3DTilesSelection/src/Tileset.cpp +++ b/Cesium3DTilesSelection/src/Tileset.cpp @@ -1326,10 +1326,9 @@ Tileset::TraversalDetails Tileset::_visitTile( // initially marked for RENDER here, it may later switch to REFINE as a // result of `mustContinueRefiningToDeeperTiles`. VisitTileAction action = VisitTileAction::Render; - if (unconditionallyRefine) - action = VisitTileAction::Refine; - else if (!meetsSse && !ancestorMeetsSse) + if (unconditionallyRefine || (!meetsSse && !ancestorMeetsSse)) { action = VisitTileAction::Refine; + } const TileSelectionState lastFrameSelectionState = tile.getLastSelectionState(); diff --git a/Cesium3DTilesSelection/test/TestTilesetContentManager.cpp b/Cesium3DTilesSelection/test/TestTilesetContentManager.cpp index c9c29be63..8e15c934b 100644 --- a/Cesium3DTilesSelection/test/TestTilesetContentManager.cpp +++ b/Cesium3DTilesSelection/test/TestTilesetContentManager.cpp @@ -127,8 +127,8 @@ CesiumGltf::Model createGlobeGrid( glm::dvec3 max = min; std::vector positions; - indices.reserve(6 * (width - 1) * (height - 1)); - positions.reserve(width * height); + indices.reserve(static_cast(6 * (width - 1) * (height - 1))); + positions.reserve(static_cast(width * height)); for (uint32_t y = 0; y < height; ++y) { for (uint32_t x = 0; x < width; ++x) { double longitude = beginPoint.longitude + x * dimension; diff --git a/CesiumAsync/include/CesiumAsync/SharedAssetDepot.h b/CesiumAsync/include/CesiumAsync/SharedAssetDepot.h index 2ddd21d9a..71f1b1f75 100644 --- a/CesiumAsync/include/CesiumAsync/SharedAssetDepot.h +++ b/CesiumAsync/include/CesiumAsync/SharedAssetDepot.h @@ -47,7 +47,7 @@ class CESIUMASYNC_API SharedAssetDepot * * Default is 16MiB. */ - int64_t inactiveAssetSizeLimitBytes = 16 * 1024 * 1024; + int64_t inactiveAssetSizeLimitBytes = static_cast(16 * 1024 * 1024); /** * @brief Signature for the callback function that will be called to fetch and diff --git a/CesiumAsync/src/InternalTimegm.cpp b/CesiumAsync/src/InternalTimegm.cpp index 2242f9ab3..48a363bea 100644 --- a/CesiumAsync/src/InternalTimegm.cpp +++ b/CesiumAsync/src/InternalTimegm.cpp @@ -5,6 +5,7 @@ #include "InternalTimegm.h" +#include #include #include @@ -33,9 +34,10 @@ time_t internalTimegm(std::tm const* t) { const int day_of_year = daysFrom1jan(year, month, day); const int days_since_epoch = daysFrom1970(year) + day_of_year; - const time_t seconds_in_day = 3600 * 24; - const time_t result = seconds_in_day * days_since_epoch + 3600 * t->tm_hour + - 60 * t->tm_min + t->tm_sec; + const time_t seconds_in_day = static_cast(3600 * 24); + const time_t result = seconds_in_day * days_since_epoch + + static_cast(3600 * t->tm_hour) + + static_cast(60 * t->tm_min) + t->tm_sec; return result; } diff --git a/CesiumGeometry/src/QuadtreeRectangleAvailability.cpp b/CesiumGeometry/src/QuadtreeRectangleAvailability.cpp index 4e98427c7..226cfd713 100644 --- a/CesiumGeometry/src/QuadtreeRectangleAvailability.cpp +++ b/CesiumGeometry/src/QuadtreeRectangleAvailability.cpp @@ -22,9 +22,9 @@ QuadtreeRectangleAvailability::QuadtreeRectangleAvailability( uint32_t maximumLevel) noexcept : _tilingScheme(tilingScheme), _maximumLevel(maximumLevel), - _rootNodes( + _rootNodes(static_cast( this->_tilingScheme.getRootTilesX() * - this->_tilingScheme.getRootTilesY()) { + this->_tilingScheme.getRootTilesY())) { for (uint32_t j = 0; j < this->_tilingScheme.getRootTilesY(); ++j) { const uint32_t rowStart = j * this->_tilingScheme.getRootTilesX(); for (uint32_t i = 0; i < this->_tilingScheme.getRootTilesX(); ++i) { diff --git a/CesiumGltf/src/Accessor.cpp b/CesiumGltf/src/Accessor.cpp index df2b56510..741796a40 100644 --- a/CesiumGltf/src/Accessor.cpp +++ b/CesiumGltf/src/Accessor.cpp @@ -4,6 +4,7 @@ #include +#include #include #include @@ -82,7 +83,8 @@ Accessor::computeByteStride(const CesiumGltf::Model& model) const noexcept { if (pBufferView->byteStride && pBufferView->byteStride.value() != 0) { return pBufferView->byteStride.value(); } - return computeNumberOfComponents(this->type) * - computeByteSizeOfComponent(this->componentType); + return static_cast( + computeNumberOfComponents(this->type) * + computeByteSizeOfComponent(this->componentType)); } } // namespace CesiumGltf diff --git a/CesiumGltf/src/TextureView.cpp b/CesiumGltf/src/TextureView.cpp index 06edbedd0..49d495ec5 100644 --- a/CesiumGltf/src/TextureView.cpp +++ b/CesiumGltf/src/TextureView.cpp @@ -170,7 +170,8 @@ std::vector TextureView::sampleNearestPixel( static_cast(image.height) - 1); int64_t pixelIndex = - image.bytesPerChannel * image.channels * (y * image.width + x); + static_cast(image.bytesPerChannel * image.channels) * + (y * image.width + x); // TODO: Currently stb only outputs uint8 pixel types. If that // changes this should account for additional pixel byte sizes. diff --git a/CesiumGltfReader/src/decodeDraco.cpp b/CesiumGltfReader/src/decodeDraco.cpp index ef2e4512f..98c0f3ce8 100644 --- a/CesiumGltfReader/src/decodeDraco.cpp +++ b/CesiumGltfReader/src/decodeDraco.cpp @@ -127,10 +127,10 @@ void copyDecodedIndices( return; } - if (pIndicesAccessor->count != pMesh->num_faces() * 3) { + if (pIndicesAccessor->count != static_cast(pMesh->num_faces() * 3)) { readGltf.warnings.emplace_back( "indices accessor doesn't match with decoded Draco indices"); - pIndicesAccessor->count = pMesh->num_faces() * 3; + pIndicesAccessor->count = static_cast(pMesh->num_faces() * 3); } draco::PointIndex::ValueType numPoint = pMesh->num_points(); @@ -237,8 +237,8 @@ void copyDecodedAttribute( CesiumGltf::Buffer& buffer = model.buffers.emplace_back(); const int8_t numberOfComponents = pAccessor->computeNumberOfComponents(); - const int64_t stride = - numberOfComponents * pAccessor->computeByteSizeOfComponent(); + const int64_t stride = static_cast( + numberOfComponents * pAccessor->computeByteSizeOfComponent()); const int64_t sizeBytes = pAccessor->count * stride; buffer.cesium.data.resize(static_cast(sizeBytes)); diff --git a/CesiumGltfReader/test/TestGltfReader.cpp b/CesiumGltfReader/test/TestGltfReader.cpp index 25c8fa24e..20d516d1a 100644 --- a/CesiumGltfReader/test/TestGltfReader.cpp +++ b/CesiumGltfReader/test/TestGltfReader.cpp @@ -747,7 +747,7 @@ TEST_CASE("GltfReader::loadGltf") { const CesiumGltf::Image& image = result.model->images[0]; CHECK(image.pAsset->width == 2048); CHECK(image.pAsset->height == 2048); - CHECK(image.pAsset->pixelData.size() == 2048 * 2048 * 4); + CHECK(image.pAsset->pixelData.size() == static_cast(2048 * 2048 * 4); CHECK(!result.model->buffers.empty()); for (const CesiumGltf::Buffer& buffer : result.model->buffers) { diff --git a/CesiumQuantizedMeshTerrain/src/QuantizedMeshLoader.cpp b/CesiumQuantizedMeshTerrain/src/QuantizedMeshLoader.cpp index 701aae611..fec3e89d6 100644 --- a/CesiumQuantizedMeshTerrain/src/QuantizedMeshLoader.cpp +++ b/CesiumQuantizedMeshTerrain/src/QuantizedMeshLoader.cpp @@ -270,7 +270,8 @@ static std::optional parseQuantizedMesh( // read the west edge indices meshView.westEdgeIndicesCount = readValue(data, readIndex, 0); readIndex += sizeof(uint32_t); - edgeByteSizes = meshView.westEdgeIndicesCount * indexSizeBytes; + edgeByteSizes = + static_cast(meshView.westEdgeIndicesCount * indexSizeBytes); if (readIndex + edgeByteSizes > data.size()) { return std::nullopt; } @@ -282,7 +283,8 @@ static std::optional parseQuantizedMesh( // read the south edge meshView.southEdgeIndicesCount = readValue(data, readIndex, 0); readIndex += sizeof(uint32_t); - edgeByteSizes = meshView.southEdgeIndicesCount * indexSizeBytes; + edgeByteSizes = + static_cast(meshView.southEdgeIndicesCount * indexSizeBytes); if (readIndex + edgeByteSizes > data.size()) { return std::nullopt; } @@ -294,7 +296,8 @@ static std::optional parseQuantizedMesh( // read the east edge meshView.eastEdgeIndicesCount = readValue(data, readIndex, 0); readIndex += sizeof(uint32_t); - edgeByteSizes = meshView.eastEdgeIndicesCount * indexSizeBytes; + edgeByteSizes = + static_cast(meshView.eastEdgeIndicesCount * indexSizeBytes); if (readIndex + edgeByteSizes > data.size()) { return std::nullopt; } @@ -306,7 +309,8 @@ static std::optional parseQuantizedMesh( // read the north edge meshView.northEdgeIndicesCount = readValue(data, readIndex, 0); readIndex += sizeof(uint32_t); - edgeByteSizes = meshView.northEdgeIndicesCount * indexSizeBytes; + edgeByteSizes = + static_cast(meshView.northEdgeIndicesCount * indexSizeBytes); if (readIndex + edgeByteSizes > data.size()) { return std::nullopt; } @@ -330,12 +334,13 @@ static std::optional parseQuantizedMesh( if (extensionID == 1) { // Oct-encoded per-vertex normals - if (readIndex + vertexCount * 2 > data.size()) { + if (readIndex + static_cast(vertexCount * 2) > data.size()) { break; } - meshView.octEncodedNormalBuffer = - std::span(data.data() + readIndex, vertexCount * 2); + meshView.octEncodedNormalBuffer = std::span( + data.data() + readIndex, + static_cast(vertexCount * 2)); } else if (enableWaterMask && extensionID == 2) { // Water Mask if (extensionLength == 1) { @@ -410,7 +415,7 @@ static void addSkirt( const double north = rectangle.getNorth(); size_t newEdgeIndex = currentVertexCount; - size_t positionIdx = currentVertexCount * 3; + size_t positionIdx = static_cast(currentVertexCount * 3); size_t indexIdx = currentIndicesCount; for (size_t i = 0; i < edgeIndices.size(); ++i) { E edgeIdx = edgeIndices[i]; @@ -726,10 +731,11 @@ static std::vector generateNormals( // decode position without skirt, but preallocate position buffer to include // skirt as well std::vector outputPositionsBuffer( - (vertexCount + skirtVertexCount) * 3 * sizeof(float)); + static_cast((vertexCount + skirtVertexCount) * 3) * + sizeof(float)); std::span outputPositions( reinterpret_cast(outputPositionsBuffer.data()), - (vertexCount + skirtVertexCount) * 3); + static_cast((vertexCount + skirtVertexCount) * 3)); size_t positionOutputIndex = 0; const glm::dvec3 center( diff --git a/CesiumQuantizedMeshTerrain/test/TestQuantizedMeshContent.cpp b/CesiumQuantizedMeshTerrain/test/TestQuantizedMeshContent.cpp index 81a0af668..f17585fc4 100644 --- a/CesiumQuantizedMeshTerrain/test/TestQuantizedMeshContent.cpp +++ b/CesiumQuantizedMeshTerrain/test/TestQuantizedMeshContent.cpp @@ -419,7 +419,7 @@ void checkGridMesh( int32_t v = 0; std::vector uvs; - uvs.reserve(verticesWidth * verticesHeight); + uvs.reserve(static_cast(verticesWidth * verticesHeight)); uint32_t positionIdx = 0; uint32_t idx = 0; for (uint32_t y = 0; y < verticesHeight; ++y) { @@ -491,8 +491,10 @@ void checkGridMesh( size_t eastIndicesCount = quantizedMesh.vertexData.eastIndices.size(); size_t northIndicesCount = quantizedMesh.vertexData.northIndices.size(); - size_t gridVerticesCount = verticesWidth * verticesHeight; - size_t gridIndicesCount = (verticesHeight - 1) * (verticesWidth - 1) * 6; + size_t gridVerticesCount = + static_cast(verticesWidth * verticesHeight); + size_t gridIndicesCount = + static_cast((verticesHeight - 1) * (verticesWidth - 1) * 6); size_t totalSkirtVertices = westIndicesCount + southIndicesCount + eastIndicesCount + northIndicesCount; size_t totalSkirtIndices = (totalSkirtVertices - 4) * 6; @@ -593,7 +595,8 @@ static void checkGeneratedGridNormal( uint32_t verticesWidth, uint32_t verticesHeight) { uint32_t totalGridIndices = (verticesWidth - 1) * (verticesHeight - 1) * 6; - std::vector expectedNormals(verticesWidth * verticesHeight); + std::vector expectedNormals( + static_cast(verticesWidth * verticesHeight)); for (uint32_t i = 0; i < totalGridIndices; i += 3) { I id0 = indices[i]; I id1 = indices[i + 1]; @@ -639,7 +642,8 @@ static void checkGeneratedGridNormal( size_t eastIndicesCount = quantizedMesh.vertexData.eastIndices.size(); size_t northIndicesCount = quantizedMesh.vertexData.northIndices.size(); - size_t gridVerticesCount = verticesWidth * verticesHeight; + size_t gridVerticesCount = + static_cast(verticesWidth * verticesHeight); size_t totalSkirtVertices = westIndicesCount + southIndicesCount + eastIndicesCount + northIndicesCount; @@ -1026,7 +1030,8 @@ TEST_CASE("Test converting quantized mesh to gltf with skirt") { glm::vec3 normal = glm::normalize(glm::vec3(0.2, 1.4, 0.3)); uint8_t x = 0, y = 0; octEncode(normal, x, y); - std::vector octNormals(verticesWidth * verticesHeight * 2); + std::vector octNormals( + static_cast(verticesWidth * verticesHeight * 2)); for (size_t i = 0; i < octNormals.size(); i += 2) { octNormals[i] = std::byte(x); octNormals[i + 1] = std::byte(y); @@ -1068,7 +1073,7 @@ TEST_CASE("Test converting quantized mesh to gltf with skirt") { REQUIRE( static_cast(normals.size()) == - (verticesWidth * verticesHeight + totalSkirtVerticesCount)); + (static_cast(verticesWidth * verticesHeight + totalSkirtVerticesCount)); for (int64_t i = 0; i < normals.size(); ++i) { REQUIRE(Math::equalsEpsilon(normals[i].x, normal.x, Math::Epsilon2)); REQUIRE(Math::equalsEpsilon(normals[i].y, normal.y, Math::Epsilon2)); @@ -1113,7 +1118,8 @@ TEST_CASE("Test converting ill-formed quantized mesh") { glm::vec3 normal = glm::normalize(glm::vec3(0.2, 1.4, 0.3)); uint8_t x = 0, y = 0; octEncode(normal, x, y); - std::vector octNormals(verticesWidth * verticesHeight * 2); + std::vector octNormals( + static_cast(verticesWidth * verticesHeight * 2)); for (size_t i = 0; i < octNormals.size(); i += 2) { octNormals[i] = std::byte(x); octNormals[i + 1] = std::byte(y); diff --git a/CesiumRasterOverlays/include/CesiumRasterOverlays/RasterOverlay.h b/CesiumRasterOverlays/include/CesiumRasterOverlays/RasterOverlay.h index bdad340ce..12be88f35 100644 --- a/CesiumRasterOverlays/include/CesiumRasterOverlays/RasterOverlay.h +++ b/CesiumRasterOverlays/include/CesiumRasterOverlays/RasterOverlay.h @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -50,7 +51,7 @@ struct CESIUMRASTEROVERLAYS_API RasterOverlayOptions { * in memory in case they're needed again soon. This property controls the * maximum size of that cache. */ - int64_t subTileCacheBytes = 16 * 1024 * 1024; + int64_t subTileCacheBytes = static_cast(16 * 1024 * 1024); /** * @brief The maximum pixel size of raster overlay textures, in either diff --git a/CesiumRasterOverlays/test/TestQuadtreeRasterOverlayTileProvider.cpp b/CesiumRasterOverlays/test/TestQuadtreeRasterOverlayTileProvider.cpp index ac763b373..98aa8d755 100644 --- a/CesiumRasterOverlays/test/TestQuadtreeRasterOverlayTileProvider.cpp +++ b/CesiumRasterOverlays/test/TestQuadtreeRasterOverlayTileProvider.cpp @@ -96,7 +96,7 @@ class TestTileProvider : public QuadtreeRasterOverlayTileProvider { result.pImage->bytesPerChannel = 1; result.pImage->channels = 4; result.pImage->pixelData.resize( - this->getWidth() * this->getHeight() * 4, + static_cast(this->getWidth() * this->getHeight() * 4), std::byte(tileID.level)); } diff --git a/cmake/macros/setup_clang_tidy.cmake b/cmake/macros/setup_clang_tidy.cmake index 060bb0400..29374efb4 100644 --- a/cmake/macros/setup_clang_tidy.cmake +++ b/cmake/macros/setup_clang_tidy.cmake @@ -87,7 +87,7 @@ function(setup_clang_tidy) ${_PROJECT_BUILD_DIRECTORY} # path that contains a compile_commands.json ) add_custom_target( - clang-tidy-fix COMMAND ${CLANG_TIDY_RUNNER_PATH} -fix -extra-arg=-Wno-unknown-warning-option -clang-tidy-binary ${CLANG_TIDY_PATH} -p + clang-tidy-fix COMMAND ${CLANG_TIDY_RUNNER_PATH} -fix -extra-arg=-Wno-unknown-warning-option -j14 -clang-tidy-binary ${CLANG_TIDY_PATH} -p ${_PROJECT_BUILD_DIRECTORY} # path that contains a compile_commands.json ) else()