From 3745ea23367d275d1d25105c81c3bcd243e00a53 Mon Sep 17 00:00:00 2001 From: Norm Evangelista Date: Sun, 15 Jan 2023 18:15:34 -0800 Subject: [PATCH] Added readability-container-size-empty, readability-isolate-declaration FIxed Windows escapes for readability-* checks Fixed Linux DRM readability-isolate-declaration escape Fixed typo in fix :-| Fixed clang-format issue --- .clang-tidy | 2 ++ examples/ftp/Ftp.cpp | 12 +++++++---- examples/vulkan/Vulkan.cpp | 2 +- examples/win32/Win32.cpp | 3 ++- src/SFML/Audio/SoundFileWriterOgg.cpp | 4 +++- src/SFML/Audio/SoundStream.cpp | 3 ++- src/SFML/Window/DRM/DRMContext.cpp | 3 ++- src/SFML/Window/Unix/CursorImpl.cpp | 3 ++- src/SFML/Window/Unix/GlxContext.cpp | 16 ++++++++++++-- src/SFML/Window/Unix/InputImpl.cpp | 21 ++++++++++++------ src/SFML/Window/Unix/WindowImplX11.cpp | 26 ++++++++++++++++------- src/SFML/Window/Win32/WindowImplWin32.cpp | 3 ++- 12 files changed, 70 insertions(+), 28 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 409d22a0d..88de4c53a 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -5,7 +5,9 @@ Checks: > modernize-use-equals-default, modernize-use-equals-delete, modernize-use-nullptr, + readability-container-size-empty, readability-identifier-naming, + readability-isolate-declaration, -clang-analyzer-core.NonNullParamChecker, -clang-analyzer-core.NullDereference, -clang-analyzer-nullability.NullablePassedToNonnull, diff --git a/examples/ftp/Ftp.cpp b/examples/ftp/Ftp.cpp index b57c4a9eb..e024a0f9d 100644 --- a/examples/ftp/Ftp.cpp +++ b/examples/ftp/Ftp.cpp @@ -43,7 +43,8 @@ int main() return EXIT_FAILURE; // Ask for user name and password - std::string user, password; + std::string user; + std::string password; std::cout << "User name: "; std::cin >> user; std::cout << "Password: "; @@ -141,7 +142,8 @@ int main() case 6: { // Rename a file - std::string source, destination; + std::string source; + std::string destination; std::cout << "Name of the file to rename: "; std::cin >> source; std::cout << "New name: "; @@ -163,7 +165,8 @@ int main() case 8: { // Download a file from server - std::string filename, directory; + std::string filename; + std::string directory; std::cout << "Filename of the file to download (relative to current directory): "; std::cin >> filename; std::cout << "Directory to download the file to: "; @@ -175,7 +178,8 @@ int main() case 9: { // Upload a file to server - std::string filename, directory; + std::string filename; + std::string directory; std::cout << "Path of the file to upload (absolute or relative to working directory): "; std::cin >> filename; std::cout << "Directory to upload the file to (relative to current directory): "; diff --git a/examples/vulkan/Vulkan.cpp b/examples/vulkan/Vulkan.cpp index 9068c7c7f..6d15bf3ac 100644 --- a/examples/vulkan/Vulkan.cpp +++ b/examples/vulkan/Vulkan.cpp @@ -389,7 +389,7 @@ public: for (VkFence fence : fences) vkWaitForFences(device, 1, &fence, VK_TRUE, std::numeric_limits::max()); - if (commandBuffers.size()) + if (!commandBuffers.empty()) vkFreeCommandBuffers(device, commandPool, static_cast(commandBuffers.size()), commandBuffers.data()); commandBuffers.clear(); diff --git a/examples/win32/Win32.cpp b/examples/win32/Win32.cpp index 0d6b351b6..84cce8bbb 100644 --- a/examples/win32/Win32.cpp +++ b/examples/win32/Win32.cpp @@ -111,7 +111,8 @@ int main() sf::RenderWindow sfmlView2(view2); // Load some textures to display - sf::Texture texture1, texture2; + sf::Texture texture1; + sf::Texture texture2; if (!texture1.loadFromFile("resources/image1.jpg") || !texture2.loadFromFile("resources/image2.jpg")) return EXIT_FAILURE; sf::Sprite sprite1(texture1); diff --git a/src/SFML/Audio/SoundFileWriterOgg.cpp b/src/SFML/Audio/SoundFileWriterOgg.cpp index 8503eff87..00e52c550 100644 --- a/src/SFML/Audio/SoundFileWriterOgg.cpp +++ b/src/SFML/Audio/SoundFileWriterOgg.cpp @@ -92,7 +92,9 @@ bool SoundFileWriterOgg::open(const std::filesystem::path& filename, unsigned in vorbis_comment_init(&comment); // Generate the header packets - ogg_packet header, headerComm, headerCode; + ogg_packet header; + ogg_packet headerComm; + ogg_packet headerCode; status = vorbis_analysis_headerout(&m_state, &comment, &header, &headerComm, &headerCode); vorbis_comment_clear(&comment); if (status < 0) diff --git a/src/SFML/Audio/SoundStream.cpp b/src/SFML/Audio/SoundStream.cpp index 54f5eee35..fee7c1c31 100644 --- a/src/SFML/Audio/SoundStream.cpp +++ b/src/SFML/Audio/SoundStream.cpp @@ -346,7 +346,8 @@ void SoundStream::streamData() } else { - ALint size, bits; + ALint size; + ALint bits; alCheck(alGetBufferi(buffer, AL_SIZE, &size)); alCheck(alGetBufferi(buffer, AL_BITS, &bits)); diff --git a/src/SFML/Window/DRM/DRMContext.cpp b/src/SFML/Window/DRM/DRMContext.cpp index 16fbf1054..630115d4a 100644 --- a/src/SFML/Window/DRM/DRMContext.cpp +++ b/src/SFML/Window/DRM/DRMContext.cpp @@ -483,7 +483,8 @@ EGLDisplay getInitializedDisplay() eglCheck(display = eglGetDisplay(reinterpret_cast(gbmDevice))); - EGLint major, minor; + EGLint major; + EGLint minor; eglCheck(eglInitialize(display, &major, &minor)); gladLoaderLoadEGL(display); diff --git a/src/SFML/Window/Unix/CursorImpl.cpp b/src/SFML/Window/Unix/CursorImpl.cpp index 447b41bf1..b9844f5c9 100644 --- a/src/SFML/Window/Unix/CursorImpl.cpp +++ b/src/SFML/Window/Unix/CursorImpl.cpp @@ -138,7 +138,8 @@ bool CursorImpl::loadFromPixelsMonochrome(const std::uint8_t* pixels, Vector2u s size.y); // Define the foreground color as white and the background as black. - XColor fg, bg; + XColor fg; + XColor bg; fg.red = 0xFFFF; fg.blue = 0xFFFF; fg.green = 0xFFFF; diff --git a/src/SFML/Window/Unix/GlxContext.cpp b/src/SFML/Window/Unix/GlxContext.cpp index 44b07902e..cc18829bb 100644 --- a/src/SFML/Window/Unix/GlxContext.cpp +++ b/src/SFML/Window/Unix/GlxContext.cpp @@ -333,7 +333,15 @@ XVisualInfo GlxContext::selectBestVisual(::Display* display, unsigned int bitsPe continue; // Extract the components of the current visual - int red, green, blue, alpha, depth, stencil, multiSampling, samples, sRgb; + int red; + int green; + int blue; + int alpha; + int depth; + int stencil; + int multiSampling; + int samples; + int sRgb; glXGetConfig(display, &visuals[i], GLX_RED_SIZE, &red); glXGetConfig(display, &visuals[i], GLX_GREEN_SIZE, &green); glXGetConfig(display, &visuals[i], GLX_BLUE_SIZE, &blue); @@ -402,7 +410,11 @@ XVisualInfo GlxContext::selectBestVisual(::Display* display, unsigned int bitsPe void GlxContext::updateSettingsFromVisualInfo(XVisualInfo* visualInfo) { // Update the creation settings from the chosen format - int depth, stencil, multiSampling, samples, sRgb; + int depth; + int stencil; + int multiSampling; + int samples; + int sRgb; glXGetConfig(m_display, visualInfo, GLX_DEPTH_SIZE, &depth); glXGetConfig(m_display, visualInfo, GLX_STENCIL_SIZE, &stencil); diff --git a/src/SFML/Window/Unix/InputImpl.cpp b/src/SFML/Window/Unix/InputImpl.cpp index 29c45a0b1..4e11597a9 100644 --- a/src/SFML/Window/Unix/InputImpl.cpp +++ b/src/SFML/Window/Unix/InputImpl.cpp @@ -194,9 +194,12 @@ bool InputImpl::isMouseButtonPressed(Mouse::Button button) Display* display = openDisplay(); // we don't care about these but they are required - ::Window root, child; - int wx, wy; - int gx, gy; + ::Window root; + ::Window child; + int wx; + int wy; + int gx; + int gy; unsigned int buttons = 0; XQueryPointer(display, DefaultRootWindow(display), &root, &child, &gx, &gy, &wx, &wy, &buttons); @@ -230,8 +233,10 @@ Vector2i InputImpl::getMousePosition() Display* display = openDisplay(); // we don't care about these but they are required - ::Window root, child; - int x, y; + ::Window root; + ::Window child; + int x; + int y; unsigned int buttons; int gx = 0; @@ -255,8 +260,10 @@ Vector2i InputImpl::getMousePosition(const WindowBase& relativeTo) Display* display = openDisplay(); // we don't care about these but they are required - ::Window root, child; - int gx, gy; + ::Window root; + ::Window child; + int gx; + int gy; unsigned int buttons; int x = 0; diff --git a/src/SFML/Window/Unix/WindowImplX11.cpp b/src/SFML/Window/Unix/WindowImplX11.cpp index 23c69514d..354af03be 100644 --- a/src/SFML/Window/Unix/WindowImplX11.cpp +++ b/src/SFML/Window/Unix/WindowImplX11.cpp @@ -286,7 +286,8 @@ bool ewmhSupported() // Get the parent window. ::Window getParentWindow(::Display* disp, ::Window win) { - ::Window root, parent; + ::Window root; + ::Window parent; ::Window* children = nullptr; unsigned int numChildren; @@ -858,7 +859,8 @@ Vector2i WindowImplX11::getPosition() const // go using setPosition() and XMoveWindow(). To have the two match // as expected, we may have to subtract decorations and borders. ::Window child; - int xAbsRelToRoot, yAbsRelToRoot; + int xAbsRelToRoot; + int yAbsRelToRoot; XTranslateCoordinates(m_display, m_window, DefaultRootWindow(m_display), 0, 0, &xAbsRelToRoot, &yAbsRelToRoot, &child); @@ -871,7 +873,8 @@ Vector2i WindowImplX11::getPosition() const // CASE 2: most modern WMs support EWMH and can define _NET_FRAME_EXTENTS // with the exact frame size to subtract, so if present, we prefer it and // query it first. According to spec, this already includes any borders. - long xFrameExtent, yFrameExtent; + long xFrameExtent; + long yFrameExtent; if (getEWMHFrameExtents(m_display, m_window, xFrameExtent, yFrameExtent)) { @@ -904,8 +907,12 @@ Vector2i WindowImplX11::getPosition() const // Get final X/Y coordinates: take the relative position to // the root of the furthest ancestor window. - int xRelToRoot, yRelToRoot; - unsigned int width, height, borderWidth, depth; + int xRelToRoot; + int yRelToRoot; + unsigned int width; + unsigned int height; + unsigned int borderWidth; + unsigned int depth; XGetGeometry(m_display, ancestor, &root, &xRelToRoot, &yRelToRoot, &width, &height, &borderWidth, &depth); @@ -1331,7 +1338,8 @@ void WindowImplX11::setVideoMode(const VideoMode& mode) return; // Check if the XRandR extension is present - int xRandRMajor, xRandRMinor; + int xRandRMajor; + int xRandRMinor; if (!checkXRandR(xRandRMajor, xRandRMinor)) { // XRandR extension is not supported: we cannot use fullscreen mode @@ -1426,7 +1434,8 @@ void WindowImplX11::resetVideoMode() { // Try to set old configuration // Check if the XRandR extension - int xRandRMajor, xRandRMinor; + int xRandRMajor; + int xRandRMinor; if (checkXRandR(xRandRMajor, xRandRMinor)) { XRRScreenResources* res = XRRGetScreenResources(m_display, DefaultRootWindow(m_display)); @@ -2215,7 +2224,8 @@ Vector2i WindowImplX11::getPrimaryMonitorPosition() } // Get xRandr version - int xRandRMajor, xRandRMinor; + int xRandRMajor; + int xRandRMinor; if (!checkXRandR(xRandRMajor, xRandRMinor)) xRandRMajor = xRandRMinor = 0; diff --git a/src/SFML/Window/Win32/WindowImplWin32.cpp b/src/SFML/Window/Win32/WindowImplWin32.cpp index 38f4490a0..753e6d837 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.cpp +++ b/src/SFML/Window/Win32/WindowImplWin32.cpp @@ -428,7 +428,8 @@ void WindowImplWin32::setKeyRepeatEnabled(bool enabled) void WindowImplWin32::requestFocus() { // Allow focus stealing only within the same process; compare PIDs of current and foreground window - DWORD thisPid, foregroundPid; + DWORD thisPid; + DWORD foregroundPid; GetWindowThreadProcessId(m_handle, &thisPid); GetWindowThreadProcessId(GetForegroundWindow(), &foregroundPid);