Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clang-tidy warnings to make it actually useful #1048

Merged
merged 59 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
1e2e47a
misc-include-cleaner for every file
azrogers Dec 17, 2024
77094ed
Format
azrogers Dec 17, 2024
7ef48d5
Fix additional clang-tidy issues
azrogers Dec 17, 2024
6aa10bb
Fix cast issues
azrogers Dec 18, 2024
86a4ea9
Why is clang-tidy throwing bits/basic_string in here?
azrogers Dec 18, 2024
d8b5e64
Fix s2 includes ordering
azrogers Dec 18, 2024
09a22f3
Fix errors
azrogers Dec 18, 2024
99c57bf
Enable two more clang-tidy checks
azrogers Dec 18, 2024
1558147
Fix broken test
azrogers Dec 18, 2024
bd4f19d
Fix unchecked optional accesses
azrogers Dec 18, 2024
4aeee63
More checks
azrogers Dec 18, 2024
3442828
Re-enable remaining non-problematic checks
azrogers Dec 18, 2024
6abd62b
Use latest clang and clang-tidy for CI
azrogers Dec 18, 2024
b0977af
Missing sudo
azrogers Dec 18, 2024
e05114a
Specify llvm version number
azrogers Dec 18, 2024
e2cd734
Enable self-assignment check, install newer CMake on CI
azrogers Dec 18, 2024
0cb9743
Use previous LLVM install step
azrogers Dec 18, 2024
7679b59
Print version info on CI
azrogers Dec 18, 2024
2b658ae
Revert to 24.04
azrogers Dec 18, 2024
3d3185d
clang-tidy-19 -> clang-tidy
azrogers Dec 18, 2024
fbac5cf
...actually install clang-tidy-19
azrogers Dec 18, 2024
74f3f23
clang-tidy -> clang-tidy-19
azrogers Dec 18, 2024
9fc2400
Add cppcoreguidelines checks
azrogers Dec 19, 2024
94cc799
Misc checks
azrogers Dec 19, 2024
f7d287d
Modernize checks
azrogers Dec 19, 2024
2c992b7
Performance checks
azrogers Dec 19, 2024
d722646
Format
azrogers Dec 19, 2024
738de4b
Fix CI ranges issue
azrogers Dec 19, 2024
8c08de5
Fix MSVC issue
azrogers Dec 19, 2024
9a2fe68
NULL -> nullptr
azrogers Dec 19, 2024
b4a6700
Small review changes
azrogers Dec 20, 2024
2c8aa4a
Fix includes using script
azrogers Dec 20, 2024
768b651
Quotes to brackets
azrogers Dec 20, 2024
3d9b0b4
Remove unnecessary static
azrogers Dec 20, 2024
182ee0b
Add missing <memory> header
azrogers Dec 20, 2024
869a432
Undo trivially constructable std::move removals
azrogers Dec 20, 2024
61c1fa5
Make clang-tidy happy again
azrogers Dec 20, 2024
1b7b8ce
Fix review issues
azrogers Dec 20, 2024
ca0bf67
Move tileset methods back
azrogers Dec 20, 2024
1db4336
Resolve review items
azrogers Jan 6, 2025
028ee29
Merge remote-tracking branch 'origin/main' into clang-tidy-cleanup
kring Jan 13, 2025
d907086
Fix dodgy formatting of null string values.
kring Jan 13, 2025
4c69cd5
Print clang-tidy messages even on failure.
kring Jan 13, 2025
cdebce9
Better way to run even on failure.
kring Jan 13, 2025
59f01eb
Fix clang-tidy errors.
kring Jan 13, 2025
d4b8f50
Revert stylistic change (but maybe clang-tidy will be mad)
kring Jan 13, 2025
db5cc4e
Revert unnecessay movement of code.
kring Jan 13, 2025
79ce68e
Avoid repeated branch body.
kring Jan 13, 2025
9003438
Undo unnecessary code movement.
kring Jan 13, 2025
666521e
Rename variable.
kring Jan 13, 2025
c988bfe
Rename variable.
kring Jan 13, 2025
daaec96
Replace assert with full check.
kring Jan 13, 2025
896b82f
Add missing const.
kring Jan 13, 2025
5077aeb
Remove unused header.
kring Jan 13, 2025
adeb3da
Fix parameter type instead of removing std::moves.
kring Jan 13, 2025
cab5c3d
Formatting.
kring Jan 13, 2025
5d6b7c4
Undo GLM_FORCE_CXX2A
azrogers Jan 13, 2025
9ee89cb
Add description to conform-includes.js
azrogers Jan 13, 2025
7eb9677
Add option for clang-tidy threads
azrogers Jan 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
60 changes: 52 additions & 8 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Checks:
- "bugprone-dynamic-static-initializers"
- "-bugprone-easily-swappable-parameters"
- "bugprone-empty-catch"
- "bugprone-exception-escape"
# See https://github.com/CesiumGS/cesium-native/issues/348
#- "bugprone-exception-escape"
- "bugprone-fold-init-type"
- "bugprone-forward-declaration-namespace"
- "bugprone-forwarding-reference-overload"
Expand All @@ -36,7 +37,8 @@ Checks:
- "bugprone-macro-repeated-side-effects"
- "bugprone-misplaced-operator-in-strlen-in-alloc"
- "bugprone-misplaced-pointer-arithmetic-in-alloc"
- "bugprone-misplaced-widening-cast"
# Produces a lot of results that are just extra-verbose - skipping for now
#- "bugprone-misplaced-widening-cast"
- "bugprone-move-forwarding-reference"
- "bugprone-multi-level-implicit-pointer-conversion"
- "bugprone-multiple-new-in-one-expression"
Expand All @@ -53,7 +55,6 @@ Checks:
- "bugprone-return-const-ref-from-parameter"
- "bugprone-shared-ptr-array-mismatch"
- "bugprone-signal-handler"
- "bugprone-signed-char-misuse"
- "bugprone-sizeof-container"
- "bugprone-sizeof-expression"
- "bugprone-spuriously-wake-up-functions"
Expand All @@ -72,24 +73,64 @@ Checks:
- "bugprone-suspicious-string-compare"
- "bugprone-suspicious-stringview-data-usage"
- "bugprone-swapped-arguments"
- "bugprone-switch-missing-default-case"
- "bugprone-terminating-continue"
- "bugprone-throw-keyword-missing"
- "bugprone-too-small-loop-variable"
- "bugprone-undefined-memory-manipulation"
- "bugprone-undelegated-constructor"
- "bugprone-unhandled-exception-at-new"
#- "bugprone-unhandled-exception-at-new"
- "bugprone-unique-ptr-array-mismatch"
- "bugprone-unsafe-functions"
- "bugprone-unused-local-non-trivial-variable"
- "bugprone-unused-raii"
- "bugprone-unused-return-value"
- "bugprone-use-after-move"
- "bugprone-virtual-near-miss"
- "cppcoreguidelines-avoid-capturing-lambda-coroutines"
- "cppcoreguidelines-avoid-goto"
- "cppcoreguidelines-avoid-reference-coroutine-parameters"
- "cppcoreguidelines-interfaces-global-init"
- "cppcoreguidelines-misleading-capture-default-by-value"
- "cppcoreguidelines-no-suspend-with-lock"
- "cppcoreguidelines-prefer-member-initializer"
- "cppcoreguidelines-pro-type-cstyle-cast"
- "cppcoreguidelines-pro-type-static-cast-downcast"
- "cppcoreguidelines-pro-type-union-access"
- "cppcoreguidelines-slicing"
- "google-runtime-int"
# We should enable this one at some point, but it produces a huge number of changes
# - "misc-const-correctness"
- "misc-misleading-bidrectional"
- "misc-misleading-identifier"
- "misc-misplaced-const"
- "misc-non-copyable-objects"
- "misc-redundant-expression"
- "misc-unused-parameters"
- "misc-unused-using-decls"
- "misc-use-anonymous-namespace"
- "misc-use-internal-linkage"
- "modernize-deprecated-headers"
#- "modernize-loop-convert"
- "modernize-make-shared"
- "modernize-make-unique"
- "modernize-min-max-use-initializer-list"
- "modernize-raw-string-literal"
- "modernize-redundant-void-arg"
- "modernize-replace-auto-ptr"
#- "modernize-type-traits"
#- "modernize-use-constraints"
- "modernize-use-emplace"
- "modernize-use-equals-default"
- "modernize-use-equals-delete"
- "modernize-use-nullptr"
- "modernize-use-starts-ends-with"
- "modernize-use-std-numbers"
#- "modernize-use-using"
- "performance-*"
- "-performance-enum-size"
- "-readability-redundant-member-init"

#WarningsAsErrors: "*"
WarningsAsErrors: ""
WarningsAsErrors: "*"
FormatStyle: none
CheckOptions:
- key: readability-implicit-bool-conversion.AllowPointerConditions
Expand All @@ -99,7 +140,10 @@ CheckOptions:
- key: modernize-use-auto.RemoveStars
value: "true"
- key: misc-include-cleaner.IgnoreHeaders
value: ".*cesium-async\\+\\+\\.h"
value: ".*cesium-async\\+\\+\\.h;.*bits\/.*.h"
- key: performance-move-const-arg.CheckTriviallyCopyableMove
value: "false"
HeaderFilterRegex: ".*"
HeaderFileExtensions: ["h"]
ExcludeHeaderFilterRegex: ".*\\.ezvcpkg\/.*"
ImplementationFileExtensions: ["cpp"]
23 changes: 16 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ jobs:
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Install ninja
uses: seanmiddleditch/gha-setup-ninja@master
- name: Install nasm
uses: ilammy/setup-nasm@v1
- name: Install latest ninja and cmake
uses: lukka/get-cmake@latest
azrogers marked this conversation as resolved.
Show resolved Hide resolved
- name: ccache
uses: hendrikmuhs/[email protected]
with:
key: ccache-ubuntu-24.04-clang-clang-tidy
- name: Install latest clang and clang-tidy
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 19
sudo apt-get install clang-tidy-19
- name: Cache vcpkg artifacts
uses: actions/cache@v4
with:
Expand All @@ -35,8 +39,8 @@ jobs:
vcpkg-ubuntu-24.04-clang
- name: Set CC and CXX
run: |
echo "CC=clang-18" >> "$GITHUB_ENV"
echo "CXX=clang++-18" >> "$GITHUB_ENV"
echo "CC=/usr/bin/clang-19" >> "$GITHUB_ENV"
echo "CXX=/usr/bin/clang++-19" >> "$GITHUB_ENV"
- name: Make more swap space available
run: |
sudo swapoff -a
Expand All @@ -47,8 +51,13 @@ jobs:
sudo swapon --show
- name: Run clang-tidy
run: |
echo `$CC --version | head -n 1`, `cmake --version | head -n 1`
cmake -B build -S . -DCMAKE_BUILD_TYPE=Debug
cmake --build build --target clang-tidy
cmake --build build --target clang-tidy > output.log
- name: List clang-tidy warnings & errors
run: |
sed -n '/\(error\|warning\):/,/^$/p' output.log

Documentation:
runs-on: ubuntu-22.04
steps:
Expand Down
18 changes: 12 additions & 6 deletions Cesium3DTiles/src/MetadataQuery.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
#include <Cesium3DTiles/Class.h>
#include <Cesium3DTiles/ClassProperty.h>
#include <Cesium3DTiles/MetadataEntity.h>
#include <Cesium3DTiles/MetadataQuery.h>
#include <Cesium3DTiles/Schema.h>

#include <optional>
#include <string>
#include <utility>

namespace Cesium3DTiles {

Expand All @@ -14,10 +22,8 @@ MetadataQuery::findFirstPropertyWithSemantic(

const Cesium3DTiles::Class& klass = classIt->second;

for (auto it = entity.properties.begin(); it != entity.properties.end();
++it) {
const std::pair<std::string, CesiumUtility::JsonValue>& property = *it;
auto propertyIt = klass.properties.find(property.first);
for (const auto& propertyValue : entity.properties) {
auto propertyIt = klass.properties.find(propertyValue.first);
if (propertyIt == klass.properties.end())
continue;

Expand All @@ -26,9 +32,9 @@ MetadataQuery::findFirstPropertyWithSemantic(
return FoundMetadataProperty{
classIt->first,
classIt->second,
it->first,
propertyValue.first,
propertyIt->second,
it->second};
propertyValue.second};
}
}

Expand Down
8 changes: 7 additions & 1 deletion Cesium3DTiles/test/TestMetadataQuery.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#include <Cesium3DTiles/Class.h>
#include <Cesium3DTiles/ClassProperty.h>
#include <Cesium3DTiles/MetadataEntity.h>
#include <Cesium3DTiles/MetadataQuery.h>
#include <Cesium3DTiles/Schema.h>
#include <CesiumUtility/JsonValue.h>

#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>

#include <optional>

using namespace Cesium3DTiles;
using namespace CesiumUtility;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include "GltfConverterResult.h"

#include <Cesium3DTilesContent/GltfConverterResult.h>
#include <CesiumAsync/Future.h>
#include <CesiumGltf/Model.h>
#include <CesiumGltfReader/GltfReader.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include "Library.h"

#include <Cesium3DTilesContent/Library.h>
#include <CesiumGltf/Model.h>
#include <CesiumUtility/ErrorList.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ int32_t createAccessorInGltf(
const int32_t bufferViewId,
const int32_t componentType,
const int64_t count,
const std::string type);
const std::string& type);

/**
* Applies the given relative-to-center (RTC) translation to the transforms of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#pragma once

#include "Library.h"

#include <Cesium3DTilesContent/GltfConverterResult.h>
#include <Cesium3DTilesContent/Library.h>
#include <CesiumAsync/Future.h>
#include <CesiumAsync/IAssetAccessor.h>
#include <CesiumGeometry/Axis.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include "GltfConverterResult.h"

#include <Cesium3DTilesContent/GltfConverterResult.h>
#include <CesiumAsync/Future.h>
#include <CesiumGltf/Model.h>
#include <CesiumGltfReader/GltfReader.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "Library.h"
#include <Cesium3DTilesContent/Library.h>

namespace Cesium3DTilesContent {

Expand Down
14 changes: 13 additions & 1 deletion Cesium3DTilesContent/src/B3dmToGltfConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@

#include <Cesium3DTilesContent/B3dmToGltfConverter.h>
#include <Cesium3DTilesContent/BinaryToGltfConverter.h>
#include <Cesium3DTilesContent/GltfConverterResult.h>
#include <Cesium3DTilesContent/GltfConverters.h>
#include <CesiumAsync/Future.h>
#include <CesiumGltf/ExtensionCesiumRTC.h>
#include <CesiumUtility/Log.h>
#include <CesiumGltfReader/GltfReader.h>
#include <CesiumUtility/Assert.h>

#include <fmt/format.h>
#include <rapidjson/document.h>

#include <cstddef>
#include <cstdint>
#include <span>
#include <utility>

namespace Cesium3DTilesContent {
namespace {
Expand Down Expand Up @@ -158,6 +169,7 @@ rapidjson::Document parseFeatureTableJsonData(
if (rtcIt != document.MemberEnd() && rtcIt->value.IsArray() &&
rtcIt->value.Size() == 3 && rtcIt->value[0].IsNumber() &&
rtcIt->value[1].IsNumber() && rtcIt->value[2].IsNumber()) {
CESIUM_ASSERT(result.model.has_value());
// Add the RTC_CENTER value to the glTF as a CESIUM_RTC extension.
rapidjson::Value& rtcValue = rtcIt->value;
auto& cesiumRTC =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
#include <CesiumUtility/Assert.h>

#include <glm/common.hpp>
#include <rapidjson/document.h>
#include <rapidjson/rapidjson.h>

#include <cstddef>
#include <cstdint>
#include <string>
#include <vector>

using namespace Cesium3DTilesContent::CesiumImpl;

Expand Down
37 changes: 31 additions & 6 deletions Cesium3DTilesContent/src/BatchTableToGltfStructuralMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,46 @@

#include "BatchTableHierarchyPropertyValues.h"

#include <CesiumGltf/Buffer.h>
#include <CesiumGltf/BufferView.h>
#include <CesiumGltf/Class.h>
#include <CesiumGltf/ClassProperty.h>
#include <CesiumGltf/ExtensionExtMeshFeatures.h>
#include <CesiumGltf/ExtensionKhrDracoMeshCompression.h>
#include <CesiumGltf/ExtensionModelExtStructuralMetadata.h>
#include <CesiumGltf/FeatureId.h>
#include <CesiumGltf/Mesh.h>
#include <CesiumGltf/MeshPrimitive.h>
#include <CesiumGltf/Model.h>
#include <CesiumGltf/PropertyTable.h>
#include <CesiumGltf/PropertyTableProperty.h>
#include <CesiumGltf/PropertyType.h>
#include <CesiumGltf/PropertyTypeTraits.h>
#include <CesiumGltf/Schema.h>
#include <CesiumUtility/Assert.h>
#include <CesiumUtility/Log.h>

#include <glm/glm.hpp>
#include <CesiumUtility/ErrorList.h>
#include <CesiumUtility/JsonValue.h>

#include <fmt/format.h>
#include <glm/common.hpp>
#include <rapidjson/document.h>
#include <rapidjson/rapidjson.h>
#include <rapidjson/stringbuffer.h>
#include <rapidjson/writer.h>

#include <cstddef>
#include <cstdint>
#include <cstring>
#include <limits>
#include <map>
#include <optional>
#include <span>
#include <string>
#include <type_traits>
#include <unordered_set>
#include <utility>
#include <variant>
#include <vector>

using namespace CesiumGltf;
using namespace Cesium3DTilesContent::CesiumImpl;
Expand Down Expand Up @@ -387,7 +411,7 @@ struct CompatibleTypes {
* This is helpful for when a property contains a sentinel value as non-null
* data; the sentinel value can then be removed from consideration.
*/
void removeSentinelValues(CesiumUtility::JsonValue value) noexcept {
void removeSentinelValues(const CesiumUtility::JsonValue& value) noexcept {
if (value.isNumber()) {
// Don't try to use string as sentinels for numbers.
_canUseNullStringSentinel = false;
Expand All @@ -406,7 +430,7 @@ struct CompatibleTypes {
_canUseZeroSentinel = false;
_canUseNegativeOneSentinel = false;

auto stringValue = value.getString();
const auto& stringValue = value.getString();
if (stringValue == "null") {
_canUseNullStringSentinel = false;
}
Expand Down Expand Up @@ -708,7 +732,7 @@ void updateExtensionWithJsonStringProperty(
// Because serialized string json will add double quotations in the
// buffer which is not needed by us, we will manually add the string to
// the buffer
const auto& rapidjsonStr = it->IsNull() ? *noDataValue : it->GetString();
const auto& rapidjsonStr = it->GetString();
Copy link
Member

@kring kring Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The more I look at this code, the more I think it's wrong (both before and after this PR).

The intention of this if/else is, AFAICT, to make sure that property values are shown the same way they would be if serialize to JSON, except that strings should not be quoted. So we should go into the if when we have a non-string, and into the else when we have a string (so that we can remove the quotes).

Mostly this is straightforward, but there's one tricky bit. If the value is null, and the property has a default value, then we need to use that default value (which is always a string).

But that's not what this code is going to do. If the value is null, then it->IsString() will be false, and so we'll always go into the if block and never the else. That will end up writing the string null to the buffer instead of the default value.

I believe the correct code looks roughly like:

if (it->IsString() || (it->IsNull() && noDataValue)) {
    // use string formatting that removes quotes
} else {
    // Use JSON formatting
}

I'll make this change and push it into this PR.

rapidjsonStrBuffer.Reserve(it->GetStringLength());
for (rapidjson::SizeType j = 0; j < it->GetStringLength(); ++j) {
rapidjsonStrBuffer.PutUnsafe(rapidjsonStr[j]);
Expand Down Expand Up @@ -791,6 +815,7 @@ void updateExtensionWithJsonScalarProperty(

for (int64_t i = 0; i < propertyTable.count; ++i, ++p, ++it) {
if (it->IsNull()) {
CESIUM_ASSERT(noDataValue.has_value());
azrogers marked this conversation as resolved.
Show resolved Hide resolved
*p = *noDataValue;
} else {
*p = static_cast<T>(it->template Get<TRapidJson>());
Expand Down
Loading
Loading