diff --git a/.clang-tidy b/.clang-tidy index 409d22a0..88de4c53 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 b57c4a9e..e024a0f9 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 9068c7c7..6d15bf3a 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 0d6b351b..84cce8bb 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 8503eff8..00e52c55 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 54f5eee3..fee7c1c3 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 16fbf105..630115d4 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 447b41bf..b9844f5c 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 44b07902..cc18829b 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 29c45a0b..4e11597a 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 23c69514..354af03b 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 38f4490a..753e6d83 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);