Skip to content

Commit

Permalink
clang-tidy: Fix header regex and the resulting nags
Browse files Browse the repository at this point in the history
  • Loading branch information
sndels committed Aug 6, 2024
1 parent 4050a81 commit f8f4576
Show file tree
Hide file tree
Showing 22 changed files with 85 additions and 35 deletions.
9 changes: 8 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@
# glm
# cppcoreguidelines-pro-type-vararg:
# fprintf, I really don't like formatting with streams
# cppcoreguidelines-rvalue-reference-param-not-moved
# false positives from WHEELS_MOV
# TODO: Is there a way to annotate the macro like custom asserts?
# misc-no-recursion
# I do use recursion in places
# misc-include-cleaner
# Not available on my laptop yet so let's skip it for now
# modernize-use-trailing-return-type:
# Haven't touched professionally, best not add 'noise'
# modernize-use-auto
Expand Down Expand Up @@ -63,6 +68,8 @@ Checks: "*,
-cppcoreguidelines-pro-type-reinterpret-cast,
-cppcoreguidelines-pro-type-union-access,
-cppcoreguidelines-pro-type-vararg,
-cppcoreguidelines-rvalue-reference-param-not-moved,
-misc-include-cleaner,
-misc-non-private-member-variables-in-classes,
-misc-no-recursion,
-modernize-use-trailing-return-type,
Expand All @@ -75,5 +82,5 @@ Checks: "*,
-readability-uppercase-literal-suffix
"
WarningsAsErrors: '*'
HeaderFilterRegex: '.*/prosper/include/.*'
HeaderFilterRegex: '.*[/\\]+prosper[/\\]+src[/\\]+.*\.hpp'
FormatStyle: file
3 changes: 3 additions & 0 deletions src/Allocators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ struct Allocators
void destroy();
};

// This is depended on by Device and init()/destroy() order relative to other
// similar globals is handled in main()
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
extern Allocators gAllocators;

#endif // PROSPER_ALLOCATORS_HPP
3 changes: 3 additions & 0 deletions src/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class Window
bool m_resized{false};
};

// This is depended on by Device and init()/destroy() order relative to other
// similar globals is handled in main()
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
extern Window gWindow;

#endif // PROSPER_WINDOW_HPP
3 changes: 3 additions & 0 deletions src/gfx/DescriptorAllocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class DescriptorAllocator
// This allocator should only be used for the descriptors that can live
// until the end of the program. As such, reset() shouldn't be called so
// that users can rely on the descriptors being there once allocated.
// This is depended on by Device and init()/destroy() order relative to other
// similar globals is handled in main()
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
extern DescriptorAllocator gStaticDescriptorsAlloc;

#endif // PROSPER_GFX_DESCRIPTOR_ALLOCATOR_HPP
3 changes: 3 additions & 0 deletions src/gfx/Device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ class Device
MemoryAllocationBytes m_memoryAllocations;
};

// This is depended on by Device and init()/destroy() order relative to other
// similar globals is handled in main()
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
extern Device gDevice;

#endif // PROSPER_GFX_DEVICE_HPP
1 change: 1 addition & 0 deletions src/gfx/Fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
class DescriptorAllocator;

// Device.hpp
// NOLINTNEXTLINE(bugprone-forward-declaration-namespace)
class Device;
struct DeviceProperties;
struct MemoryAllocationBytes;
Expand Down
5 changes: 4 additions & 1 deletion src/gfx/Resources.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ struct Buffer
// NOTE: Remember to amend clone() new members are added

Buffer() noexcept = default;
~Buffer() = default;
// Copying is probably a mistake so disable implicit copies
Buffer(const Buffer &) = delete;
Buffer(Buffer &&) noexcept = default;
Expand All @@ -193,7 +194,7 @@ struct Buffer

// There are use cases for mirrored buffers in async loading so expose a
// convenience clone
Buffer clone() const;
[[nodiscard]] Buffer clone() const;

[[nodiscard]] wheels::Optional<vk::BufferMemoryBarrier2> transitionBarrier(
BufferState newState, bool force_barrier = false);
Expand Down Expand Up @@ -235,6 +236,7 @@ struct TexelBuffer
VmaAllocation allocation{nullptr};

TexelBuffer() noexcept = default;
~TexelBuffer() = default;
// Copying is probably a mistake so disable implicit copies
TexelBuffer(const TexelBuffer &) = delete;
TexelBuffer(TexelBuffer &&) noexcept = default;
Expand Down Expand Up @@ -309,6 +311,7 @@ struct Image
vk::DeviceSize rawByteSize{0};

Image() noexcept = default;
~Image() = default;
// Copying is probably a mistake so disable implicit copies
Image(const Image &) = delete;
Image(Image &&) noexcept = default;
Expand Down
2 changes: 1 addition & 1 deletion src/render/ComputePass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class ComputePass
void destroyPipelines();

void createDescriptorSets(
wheels::ScopedScratch scopeAlloc, const char *,
wheels::ScopedScratch scopeAlloc, const char *debugName,
vk::ShaderStageFlags storageStageFlags);

void createPipeline(
Expand Down
2 changes: 1 addition & 1 deletion src/render/RenderResourceCollection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class RenderResourceCollection

protected:
void assertValidHandle(Handle handle) const;
wheels::StrSpan aliasedDebugName(Handle handle) const;
[[nodiscard]] wheels::StrSpan aliasedDebugName(Handle handle) const;

private:
static const uint64_t sNotInUseGenerationFlag = static_cast<size_t>(1)
Expand Down
3 changes: 3 additions & 0 deletions src/render/RenderResources.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ class RenderResources
bool m_initialized{false};
};

// This is depended on by Device and init()/destroy() order relative to other
// similar globals is handled in main()
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
extern RenderResources gRenderResources;

struct Transitions
Expand Down
2 changes: 1 addition & 1 deletion src/render/Renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Renderer
void render(
wheels::ScopedScratch scopeAlloc, vk::CommandBuffer cb,
const Camera &cam, World &world, const vk::Rect2D &renderArea,
const SwapchainImage &swapImage, const uint32_t nextFrame,
const SwapchainImage &swapImage, uint32_t nextFrame,
const Options &options);

private:
Expand Down
7 changes: 3 additions & 4 deletions src/render/SkyboxRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ class SkyboxRenderer
SkyboxRenderer &operator=(SkyboxRenderer &&other) = delete;

void init(
wheels::ScopedScratch scopeAlloc,
const vk::DescriptorSetLayout camDSLayout,
wheels::ScopedScratch scopeAlloc, vk::DescriptorSetLayout camDSLayout,
const WorldDSLayouts &worldDSLayouts);

void recompileShaders(
wheels::ScopedScratch scopeAlloc,
const wheels::HashSet<std::filesystem::path> &changedFiles,
const vk::DescriptorSetLayout camDSLayout,
vk::DescriptorSetLayout camDSLayout,
const WorldDSLayouts &worldDSLayouts);

struct RecordInOut
Expand All @@ -50,7 +49,7 @@ class SkyboxRenderer
void destroyGraphicsPipelines();

void createGraphicsPipelines(
const vk::DescriptorSetLayout camDSLayout,
vk::DescriptorSetLayout camDSLayout,
const WorldDSLayouts &worldDSLayouts);

bool m_initialized{false};
Expand Down
6 changes: 3 additions & 3 deletions src/scene/Accessors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class TimeAccessor
TimeAccessor(
const float *data, uint32_t count, const Interval &interval) noexcept;

float endTimeS() const;
KeyFrameInterpolation interpolation(float timeS) const;
[[nodiscard]] float endTimeS() const;
[[nodiscard]] KeyFrameInterpolation interpolation(float timeS) const;

private:
const float *m_data{nullptr};
Expand All @@ -41,7 +41,7 @@ template <typename T> class ValueAccessor
// Count is for vector elements, not individual float
ValueAccessor(const uint8_t *data, uint32_t count) noexcept;

T read(uint32_t index) const;
[[nodiscard]] T read(uint32_t index) const;

private:
const uint8_t *m_data{nullptr};
Expand Down
4 changes: 2 additions & 2 deletions src/scene/Animations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ template <typename T> class Animation
InterpolationType interpolation, TimeAccessor &&timeFrames,
ValueAccessor<T> &&valueFrames);

float endTimeS() const;
[[nodiscard]] float endTimeS() const;

void registerTarget(T &target);
void update(float timeS);
Expand Down Expand Up @@ -69,7 +69,7 @@ template <typename T> void Animation<T>::update(float timeS)
{
const KeyFrameInterpolation interp = m_timeFrames.interpolation(timeS);

T firstValue;
T firstValue{};
if (interp.t == 0.f && m_interpolation == InterpolationType::CubicSpline)
// Three values per frame, property value is the middle one
firstValue = m_valueFrames.read(interp.firstFrame * 3 + 1);
Expand Down
2 changes: 1 addition & 1 deletion src/scene/Camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class Camera
// Applies an offset without touching the held one
void applyOffset(const CameraOffset &offset);

FrustumCorners getFrustumCorners() const;
[[nodiscard]] FrustumCorners getFrustumCorners() const;

private:
void createBindingsReflection(wheels::ScopedScratch scopeAlloc);
Expand Down
6 changes: 3 additions & 3 deletions src/scene/World.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class World
void endFrame();

// Returns true if the visible scene was changed.
bool handleDeferredLoading(vk::CommandBuffer cb);
bool unbuiltBlases() const;
[[nodiscard]] bool handleDeferredLoading(vk::CommandBuffer cb);
[[nodiscard]] bool unbuiltBlases() const;

void drawDeferredLoadingUi() const;
// Returns true if the next frame will use a different scene
Expand All @@ -57,7 +57,7 @@ class World
void updateBuffers(wheels::ScopedScratch scopeAlloc);
// Has to be called after updateBuffers(). Returns true if new BLASes were
// added.
bool buildAccelerationStructures(
[[nodiscard]] bool buildAccelerationStructures(
wheels::ScopedScratch scopeAlloc, vk::CommandBuffer cb);
void drawSkybox(vk::CommandBuffer cb) const;

Expand Down
7 changes: 5 additions & 2 deletions src/scene/WorldData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,10 @@ vk::Filter getVkFilterMode(cgltf_int glEnum)
case s_gl_linear_mipmap_nearest:
case s_gl_linear_mimpap_linear:
return vk::Filter::eLinear;
default:
LOG_ERR("Invalid gl filter %d", glEnum);
}

LOG_ERR("Invalid gl filter %d", glEnum);
return vk::Filter::eLinear;
}

Expand All @@ -201,8 +202,10 @@ vk::SamplerAddressMode getVkAddressMode(cgltf_int glEnum)
return vk::SamplerAddressMode::eMirroredRepeat;
case s_gl_repeat:
return vk::SamplerAddressMode::eRepeat;
default:
LOG_ERR("Invalid gl wrapping mode %d", glEnum);
}
LOG_ERR("Invalid gl wrapping mode %d", glEnum);

return vk::SamplerAddressMode::eClampToEdge;
}

Expand Down
4 changes: 3 additions & 1 deletion src/utils/Hashes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ template <> struct Hash<std::filesystem::path>
[[nodiscard]] uint64_t operator()(
const std::filesystem::path &value) const noexcept
{
return wyhash(value.string().c_str(), value.string().size(), 0, _wyp);
return wyhash(
value.string().c_str(), value.string().size(), 0,
(uint64_t const *)_wyp);
}
};

Expand Down
3 changes: 3 additions & 0 deletions src/utils/InputHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ class InputHandler
wheels::Optional<MouseGesture> m_mouseGesture;
};

// This is depended on by Device and init()/destroy() order relative to other
// similar globals is handled in main()
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
extern InputHandler gInputHandler;

#endif // PROSPER_UTILS_INPUT_HANDLER_HPP
11 changes: 5 additions & 6 deletions src/utils/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ namespace
// This should be plenty for even the worst shader error messes and still small
// enough to comfortably fit the 1MB stack on windows.
const int sTmpStrLength = static_cast<int>(kilobytes(8));
const char *const sOutOfSpaceError =
const StaticArray sOutOfSpaceError =
"\n[ ERROR: Logger ran out of tmp formatting space ]\n";
const int sOutOfSpaceErrorLength = static_cast<int>(strlen(sOutOfSpaceError));

// TODO:
// InlineArray and resize_uninitialized() instead?
Expand Down Expand Up @@ -97,7 +96,7 @@ struct TmpStr

// Include final null after the overflow error
const int space = sTmpStrLength - asserted_cast<int>(writePtr) -
sOutOfSpaceErrorLength - 1;
asserted_cast<int>(sOutOfSpaceError.size()) - 1;
WHEELS_ASSERT(space >= 0);

const int charsWritten =
Expand Down Expand Up @@ -162,11 +161,11 @@ struct TmpStr
{
WHEELS_ASSERT(
sTmpStrLength - asserted_cast<int>(writePtr) >=
sOutOfSpaceErrorLength + 1);
asserted_cast<int>(sOutOfSpaceError.size()) + 1);
// Copy the final null too
memcpy(
str.data() + writePtr, sOutOfSpaceError,
sOutOfSpaceErrorLength + 1);
str.data() + writePtr, sOutOfSpaceError.data(),
asserted_cast<int>(sOutOfSpaceError.size()) + 1);
}
}
};
Expand Down
3 changes: 3 additions & 0 deletions src/utils/Profiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ class Profiler
gAllocators.general};
};

// This is depended on by Device and init()/destroy() order relative to other
// similar globals is handled in main()
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
extern Profiler gProfiler;

// The scope variable is never accessed so let's reduce the noise with a macro
Expand Down
31 changes: 23 additions & 8 deletions src/utils/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,18 @@ template <typename T, typename V> constexpr T asserted_cast(V a)
{
#ifndef NDEBUG
static_assert(
!std::is_floating_point<T>::value &&
!std::is_floating_point_v<T> &&
"No assertions for floating point target type");

if constexpr (!std::is_same<T, V>::value && std::is_integral<T>::value)
if constexpr (!std::is_same_v<T, V> && std::is_integral_v<T>)
{
if (a >= 0)
{
if constexpr (std::is_integral<V>::value)
if constexpr (std::is_integral_v<V>)
{
if constexpr ((sizeof(T) < sizeof(V) ||
(sizeof(T) == sizeof(V) &&
std::is_signed<T>::value &&
!std::is_signed<V>::value)))
(sizeof(T) == sizeof(V) && std::is_signed_v<T> &&
!std::is_signed_v<V>)))
{
if (a > static_cast<V>(std::numeric_limits<T>::max()))
WHEELS_ASSERT(!"overflow");
Expand Down Expand Up @@ -95,7 +94,7 @@ void writeRawSpan(std::ofstream &stream, wheels::Span<const T> span)

inline void writeRawStrSpan(std::ofstream &stream, const wheels::StrSpan span)
{
stream.write(span.data(), span.size());
stream.write(span.data(), asserted_cast<std::streamsize>(span.size()));
}

template <typename T> void writeRaw(std::ofstream &stream, const T &value)
Expand Down Expand Up @@ -151,6 +150,7 @@ inline void appendEnumVariantsAsDefines(
// remainder. Assumes both inputs are positive. Returns 0 when dividend is 0.
template <typename T>
requires std::is_integral_v<T>
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
T roundedUpQuotient(T dividend, T divisor)
{
if (dividend == 0) [[unlikely]]
Expand All @@ -174,9 +174,24 @@ struct DeferDummy
template <class F> struct Deferrer
{
F f;
Deferrer(const F &f)
: f{f}
{
}
~Deferrer() { f(); }

Deferrer(const Deferrer<F> &) = delete;
Deferrer &operator=(const Deferrer<F> &) = delete;
Deferrer(Deferrer<F> &&) = delete;
Deferrer &operator=(Deferrer<F> &&) = delete;
};
template <class F> Deferrer<F> operator*(DeferDummy, F f) { return {f}; }
template <class F> Deferrer<F> operator*(DeferDummy dummy, F f)
{
(void)dummy;
return {f};
}
// Caller supplies the lambda scope, works as intended
// NOLINTNEXTLINE(bugprone-macro-parentheses)
#define defer auto TOKEN_APPEND(zzDefer, __LINE__) = DeferDummy{} *[&]()

void setCurrentThreadName(const char *name);
Expand Down

0 comments on commit f8f4576

Please sign in to comment.