From 8a5b206bb887368b3b017545ed4b894191241996 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Sun, 15 Jan 2023 11:30:12 -0700 Subject: [PATCH] Add clang-tidy modernize-use-default-member-init check --- .clang-tidy | 1 + examples/shader/Effect.hpp | 4 +- examples/voip/Server.cpp | 6 +- examples/vulkan/Vulkan.cpp | 107 ++++++++++------------------- include/SFML/Graphics/Font.hpp | 8 +-- src/SFML/Graphics/Font.cpp | 2 +- src/SFML/Window/GlContext.cpp | 6 +- src/SFML/Window/OSX/CursorImpl.hpp | 2 +- src/SFML/Window/OSX/CursorImpl.mm | 4 +- 9 files changed, 52 insertions(+), 88 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 54a2e4501..0aa8d3a3e 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -4,6 +4,7 @@ Checks: > modernize-concat-nested-namespaces, modernize-deprecated-headers, modernize-loop-convert, + modernize-use-default-member-init, modernize-use-equals-default, modernize-use-equals-delete, modernize-use-nullptr, diff --git a/examples/shader/Effect.hpp b/examples/shader/Effect.hpp index e82f4e1cf..fd63b74b3 100644 --- a/examples/shader/Effect.hpp +++ b/examples/shader/Effect.hpp @@ -54,7 +54,7 @@ public: } protected: - Effect(const std::string& name) : m_name(name), m_isLoaded(false) + Effect(const std::string& name) : m_name(name) { } @@ -72,7 +72,7 @@ private: private: std::string m_name; - bool m_isLoaded; + bool m_isLoaded{}; // NOLINTNEXTLINE(readability-identifier-naming) static const sf::Font* s_font; diff --git a/examples/voip/Server.cpp b/examples/voip/Server.cpp index 053b83f4a..b0d9c60ee 100644 --- a/examples/voip/Server.cpp +++ b/examples/voip/Server.cpp @@ -26,7 +26,7 @@ public: /// Default constructor /// //////////////////////////////////////////////////////////// - NetworkAudioStream() : m_offset(0), m_hasFinished(false) + NetworkAudioStream() { // Set the sound parameters initialize(1, 44100); @@ -161,8 +161,8 @@ private: std::recursive_mutex m_mutex; std::vector m_samples; std::vector m_tempBuffer; - std::size_t m_offset; - bool m_hasFinished; + std::size_t m_offset{}; + bool m_hasFinished{}; }; diff --git a/examples/vulkan/Vulkan.cpp b/examples/vulkan/Vulkan.cpp index 6d15bf3ac..7485f1dc7 100644 --- a/examples/vulkan/Vulkan.cpp +++ b/examples/vulkan/Vulkan.cpp @@ -203,42 +203,7 @@ class VulkanExample { public: // Constructor - VulkanExample() : - window(sf::VideoMode({800, 600}), "SFML window with Vulkan", sf::Style::Default), - vulkanAvailable(sf::Vulkan::isAvailable()), - maxFramesInFlight(2), - currentFrame(0), - swapchainOutOfDate(false), - instance(), - debugReportCallback(), - surface(), - gpu(), - queueFamilyIndex(-1), - device(), - queue(), - swapchainFormat(), - swapchainExtent(), - swapchain(), - depthFormat(VK_FORMAT_UNDEFINED), - depthImage(), - depthImageMemory(), - depthImageView(), - vertexShaderModule(), - fragmentShaderModule(), - descriptorSetLayout(), - pipelineLayout(), - renderPass(), - graphicsPipeline(), - commandPool(), - vertexBuffer(), - vertexBufferMemory(), - indexBuffer(), - indexBufferMemory(), - textureImage(), - textureImageMemory(), - textureImageView(), - textureSampler(), - descriptorPool() + VulkanExample() { // Vulkan setup procedure if (vulkanAvailable) @@ -2602,50 +2567,50 @@ public: } private: - sf::WindowBase window; + sf::WindowBase window{sf::VideoMode({800, 600}), "SFML window with Vulkan", sf::Style::Default}; - bool vulkanAvailable; + bool vulkanAvailable{sf::Vulkan::isAvailable()}; - const unsigned int maxFramesInFlight; - unsigned int currentFrame; - bool swapchainOutOfDate; + const unsigned int maxFramesInFlight{2}; + unsigned int currentFrame{}; + bool swapchainOutOfDate{}; - VkInstance instance; - VkDebugReportCallbackEXT debugReportCallback; - VkSurfaceKHR surface; - VkPhysicalDevice gpu; - int queueFamilyIndex; - VkDevice device; - VkQueue queue; - VkSurfaceFormatKHR swapchainFormat; - VkExtent2D swapchainExtent; - VkSwapchainKHR swapchain; + VkInstance instance{}; + VkDebugReportCallbackEXT debugReportCallback{}; + VkSurfaceKHR surface{}; + VkPhysicalDevice gpu{}; + int queueFamilyIndex{-1}; + VkDevice device{}; + VkQueue queue{}; + VkSurfaceFormatKHR swapchainFormat{}; + VkExtent2D swapchainExtent{}; + VkSwapchainKHR swapchain{}; std::vector swapchainImages; std::vector swapchainImageViews; - VkFormat depthFormat; - VkImage depthImage; - VkDeviceMemory depthImageMemory; - VkImageView depthImageView; - VkShaderModule vertexShaderModule; - VkShaderModule fragmentShaderModule; + VkFormat depthFormat{VK_FORMAT_UNDEFINED}; + VkImage depthImage{}; + VkDeviceMemory depthImageMemory{}; + VkImageView depthImageView{}; + VkShaderModule vertexShaderModule{}; + VkShaderModule fragmentShaderModule{}; VkPipelineShaderStageCreateInfo shaderStages[2]; - VkDescriptorSetLayout descriptorSetLayout; - VkPipelineLayout pipelineLayout; - VkRenderPass renderPass; - VkPipeline graphicsPipeline; + VkDescriptorSetLayout descriptorSetLayout{}; + VkPipelineLayout pipelineLayout{}; + VkRenderPass renderPass{}; + VkPipeline graphicsPipeline{}; std::vector swapchainFramebuffers; - VkCommandPool commandPool; - VkBuffer vertexBuffer; - VkDeviceMemory vertexBufferMemory; - VkBuffer indexBuffer; - VkDeviceMemory indexBufferMemory; + VkCommandPool commandPool{}; + VkBuffer vertexBuffer{}; + VkDeviceMemory vertexBufferMemory{}; + VkBuffer indexBuffer{}; + VkDeviceMemory indexBufferMemory{}; std::vector uniformBuffers; std::vector uniformBuffersMemory; - VkImage textureImage; - VkDeviceMemory textureImageMemory; - VkImageView textureImageView; - VkSampler textureSampler; - VkDescriptorPool descriptorPool; + VkImage textureImage{}; + VkDeviceMemory textureImageMemory{}; + VkImageView textureImageView{}; + VkSampler textureSampler{}; + VkDescriptorPool descriptorPool{}; std::vector descriptorSets; std::vector commandBuffers; std::vector imageAvailableSemaphores; diff --git a/include/SFML/Graphics/Font.hpp b/include/SFML/Graphics/Font.hpp index eeb93e756..e21e3ab7e 100644 --- a/include/SFML/Graphics/Font.hpp +++ b/include/SFML/Graphics/Font.hpp @@ -357,10 +357,10 @@ private: { explicit Page(bool smooth); - GlyphTable glyphs; //!< Table mapping code points to their corresponding glyph - Texture texture; //!< Texture containing the pixels of the glyphs - unsigned int nextRow; //!< Y position of the next new row in the texture - std::vector rows; //!< List containing the position of all the existing rows + GlyphTable glyphs; //!< Table mapping code points to their corresponding glyph + Texture texture; //!< Texture containing the pixels of the glyphs + unsigned int nextRow{3}; //!< Y position of the next new row in the texture + std::vector rows; //!< List containing the position of all the existing rows }; //////////////////////////////////////////////////////////// diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index af67b2c44..e8051772b 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -835,7 +835,7 @@ bool Font::setCurrentSize(unsigned int characterSize) const //////////////////////////////////////////////////////////// -Font::Page::Page(bool smooth) : nextRow(3) +Font::Page::Page(bool smooth) { // Make sure that the texture is initialized by default sf::Image image; diff --git a/src/SFML/Window/GlContext.cpp b/src/SFML/Window/GlContext.cpp index e385d8cf4..4e4e66db1 100644 --- a/src/SFML/Window/GlContext.cpp +++ b/src/SFML/Window/GlContext.cpp @@ -199,7 +199,7 @@ struct TransientContext /// \brief Constructor /// //////////////////////////////////////////////////////////// - TransientContext() : referenceCount(0), context(nullptr), sharedContextLock(), useSharedContext(false) + TransientContext() { if (resourceCount == 0) { @@ -241,10 +241,10 @@ struct TransientContext /////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - unsigned int referenceCount; + unsigned int referenceCount{}; std::unique_ptr context; std::optional> sharedContextLock; - bool useSharedContext; + bool useSharedContext{}; }; // This per-thread variable tracks if and how a transient diff --git a/src/SFML/Window/OSX/CursorImpl.hpp b/src/SFML/Window/OSX/CursorImpl.hpp index f9b4841e5..e97bdfa0e 100644 --- a/src/SFML/Window/OSX/CursorImpl.hpp +++ b/src/SFML/Window/OSX/CursorImpl.hpp @@ -104,7 +104,7 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - NSCursorRef m_cursor; ///< System cursor handle + NSCursorRef m_cursor{}; ///< System cursor handle }; } // namespace sf::priv diff --git a/src/SFML/Window/OSX/CursorImpl.mm b/src/SFML/Window/OSX/CursorImpl.mm index ce5cc7a10..afd43f33a 100644 --- a/src/SFML/Window/OSX/CursorImpl.mm +++ b/src/SFML/Window/OSX/CursorImpl.mm @@ -51,9 +51,7 @@ namespace sf::priv { //////////////////////////////////////////////////////////// -CursorImpl::CursorImpl() : m_cursor(nil) -{ -} +CursorImpl::CursorImpl() = default; ////////////////////////////////////////////////////////////