From e0c4d14541fb4b5a82853d16846cf819df4611e1 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Wed, 30 Mar 2022 22:39:31 -0600 Subject: [PATCH] Use `[[maybe_unused]]` for parameters that are sometimes not used Depending on preprocessor settings, certain parameters may or may not be used. Instead of casing to (void) when not used, it's easier to use C++17's [[maybe_unused]] attribute to express this. --- include/SFML/System/Utf.inl | 8 ++------ src/SFML/Graphics/VertexBuffer.cpp | 3 +-- src/SFML/Window/EglContext.cpp | 5 ++--- src/SFML/Window/Vulkan.cpp | 6 ++---- src/SFML/Window/WindowImpl.cpp | 5 +---- 5 files changed, 8 insertions(+), 19 deletions(-) diff --git a/include/SFML/System/Utf.inl b/include/SFML/System/Utf.inl index 35cad7be4..3c7f30e88 100644 --- a/include/SFML/System/Utf.inl +++ b/include/SFML/System/Utf.inl @@ -645,7 +645,7 @@ Out Utf<32>::toUtf32(In begin, In end, Out output) //////////////////////////////////////////////////////////// template -Uint32 Utf<32>::decodeAnsi(In input, const std::locale& locale) +Uint32 Utf<32>::decodeAnsi(In input, [[maybe_unused]] const std::locale& locale) { // On Windows, GCC's standard library (glibc++) has almost // no support for Unicode stuff. As a consequence, in this @@ -656,8 +656,6 @@ Uint32 Utf<32>::decodeAnsi(In input, const std::locale& locale) (defined(__GLIBCPP__) || defined (__GLIBCXX__)) && /* ... and standard library is glibc++ ... */ \ !(defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)) /* ... and STLPort is not used on top of it */ - (void)locale; // to avoid warnings - wchar_t character = 0; mbtowc(&character, &input, 1); return static_cast(character); @@ -690,7 +688,7 @@ Uint32 Utf<32>::decodeWide(In input) //////////////////////////////////////////////////////////// template -Out Utf<32>::encodeAnsi(Uint32 codepoint, Out output, char replacement, const std::locale& locale) +Out Utf<32>::encodeAnsi(Uint32 codepoint, Out output, char replacement, [[maybe_unused]] const std::locale& locale) { // On Windows, gcc's standard library (glibc++) has almost // no support for Unicode stuff. As a consequence, in this @@ -701,8 +699,6 @@ Out Utf<32>::encodeAnsi(Uint32 codepoint, Out output, char replacement, const st (defined(__GLIBCPP__) || defined (__GLIBCXX__)) && /* ... and standard library is glibc++ ... */ \ !(defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)) /* ... and STLPort is not used on top of it */ - (void)locale; // to avoid warnings - char character = 0; if (wctomb(&character, static_cast(codepoint)) >= 0) *output++ = character; diff --git a/src/SFML/Graphics/VertexBuffer.cpp b/src/SFML/Graphics/VertexBuffer.cpp index b9e2beb2f..d3fef25a2 100644 --- a/src/SFML/Graphics/VertexBuffer.cpp +++ b/src/SFML/Graphics/VertexBuffer.cpp @@ -206,11 +206,10 @@ bool VertexBuffer::update(const Vertex* vertices, std::size_t vertexCount, unsig //////////////////////////////////////////////////////////// -bool VertexBuffer::update(const VertexBuffer& vertexBuffer) +bool VertexBuffer::update([[maybe_unused]] const VertexBuffer& vertexBuffer) { #ifdef SFML_OPENGL_ES - (void) vertexBuffer; return false; #else diff --git a/src/SFML/Window/EglContext.cpp b/src/SFML/Window/EglContext.cpp index 6f69b237d..5a31501b2 100644 --- a/src/SFML/Window/EglContext.cpp +++ b/src/SFML/Window/EglContext.cpp @@ -132,7 +132,7 @@ m_config (nullptr) //////////////////////////////////////////////////////////// -EglContext::EglContext(EglContext* shared, const ContextSettings& settings, const WindowImpl& owner, unsigned int bitsPerPixel) : +EglContext::EglContext(EglContext* shared, const ContextSettings& settings, [[maybe_unused]] const WindowImpl& owner, unsigned int bitsPerPixel) : m_display (EGL_NO_DISPLAY), m_context (EGL_NO_CONTEXT), m_surface (EGL_NO_SURFACE), @@ -164,8 +164,7 @@ m_config (nullptr) // Create EGL surface (except on Android because the window is created // asynchronously, its activity manager will call it for us) createSurface(owner.getSystemHandle()); -#else - (void) owner; + #endif } diff --git a/src/SFML/Window/Vulkan.cpp b/src/SFML/Window/Vulkan.cpp index 9dce81636..9bf614f6c 100644 --- a/src/SFML/Window/Vulkan.cpp +++ b/src/SFML/Window/Vulkan.cpp @@ -55,11 +55,10 @@ using VulkanImplType = sf::priv::VulkanImplWin32; namespace sf { //////////////////////////////////////////////////////////// -bool Vulkan::isAvailable(bool requireGraphics) +bool Vulkan::isAvailable([[maybe_unused]] bool requireGraphics) { #if defined(SFML_VULKAN_IMPLEMENTATION_NOT_AVAILABLE) - (void) requireGraphics; return false; #else @@ -71,11 +70,10 @@ bool Vulkan::isAvailable(bool requireGraphics) //////////////////////////////////////////////////////////// -VulkanFunctionPointer Vulkan::getFunction(const char* name) +VulkanFunctionPointer Vulkan::getFunction([[maybe_unused]] const char* name) { #if defined(SFML_VULKAN_IMPLEMENTATION_NOT_AVAILABLE) - (void) name; return nullptr; #else diff --git a/src/SFML/Window/WindowImpl.cpp b/src/SFML/Window/WindowImpl.cpp index 3e45efe11..cc2293e8a 100644 --- a/src/SFML/Window/WindowImpl.cpp +++ b/src/SFML/Window/WindowImpl.cpp @@ -295,13 +295,10 @@ void WindowImpl::processSensorEvents() //////////////////////////////////////////////////////////// -bool WindowImpl::createVulkanSurface(const VkInstance& instance, VkSurfaceKHR& surface, const VkAllocationCallbacks* allocator) +bool WindowImpl::createVulkanSurface([[maybe_unused]] const VkInstance& instance, [[maybe_unused]] VkSurfaceKHR& surface, [[maybe_unused]] const VkAllocationCallbacks* allocator) { #if defined(SFML_VULKAN_IMPLEMENTATION_NOT_AVAILABLE) - (void) instance; - (void) surface; - (void) allocator; return false; #else