From e1469aa8f2d29218eab8786426db1f0cafa2c297 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Thu, 27 Jun 2024 09:12:23 -0600 Subject: [PATCH] Use `[[nodiscard]]` in more places --- .clang-tidy | 1 - examples/sound_effects/SoundEffects.cpp | 2 +- include/SFML/Audio/InputSoundFile.hpp | 14 ++++---- include/SFML/Audio/Music.hpp | 8 ++--- include/SFML/Audio/Sound.hpp | 10 +++--- include/SFML/Audio/SoundRecorder.hpp | 8 ++--- include/SFML/Audio/SoundSource.hpp | 36 +++++++++---------- include/SFML/Audio/SoundStream.hpp | 14 ++++---- include/SFML/Graphics/Color.hpp | 2 +- include/SFML/Graphics/Image.hpp | 6 ++-- include/SFML/Graphics/Rect.hpp | 6 ++-- include/SFML/Graphics/Shader.hpp | 2 +- include/SFML/Graphics/Transform.hpp | 8 ++--- include/SFML/Graphics/VertexArray.hpp | 6 ++-- include/SFML/Graphics/VertexBuffer.hpp | 8 ++--- include/SFML/Network/Ftp.hpp | 10 +++--- include/SFML/Network/Http.hpp | 12 +++---- include/SFML/Network/IpAddress.hpp | 4 +-- include/SFML/Network/Packet.hpp | 8 ++--- include/SFML/Network/Socket.hpp | 4 +-- include/SFML/Network/TcpListener.hpp | 2 +- include/SFML/Network/TcpSocket.hpp | 6 ++-- include/SFML/Network/UdpSocket.hpp | 2 +- include/SFML/System/Clock.hpp | 4 +-- include/SFML/System/String.hpp | 16 ++++----- include/SFML/System/Time.hpp | 8 ++--- include/SFML/System/Vector2.hpp | 18 +++++----- include/SFML/System/Vector3.hpp | 12 +++---- include/SFML/Window/Context.hpp | 2 +- include/SFML/Window/Cursor.hpp | 2 +- include/SFML/Window/VideoMode.hpp | 2 +- include/SFML/Window/Window.hpp | 2 +- include/SFML/Window/WindowBase.hpp | 10 +++--- src/SFML/Audio/AudioDevice.hpp | 2 +- src/SFML/Graphics/RenderTextureImpl.hpp | 2 +- .../Graphics/RenderTextureImplDefault.hpp | 2 +- src/SFML/Graphics/RenderTextureImplFBO.hpp | 2 +- src/SFML/Window/Android/JoystickImpl.hpp | 4 +-- src/SFML/Window/Android/WindowImplAndroid.hpp | 8 ++--- src/SFML/Window/DRM/WindowImplDRM.hpp | 8 ++--- src/SFML/Window/GlContext.hpp | 2 +- src/SFML/Window/JoystickManager.hpp | 6 ++-- src/SFML/Window/SensorManager.hpp | 4 +-- src/SFML/Window/Unix/JoystickImpl.hpp | 4 +-- src/SFML/Window/Unix/WindowImplX11.hpp | 8 ++--- src/SFML/Window/Win32/JoystickImpl.hpp | 6 ++-- src/SFML/Window/Win32/WindowImplWin32.hpp | 8 ++--- src/SFML/Window/WindowImpl.hpp | 12 +++---- src/SFML/Window/iOS/JoystickImpl.hpp | 4 +-- src/SFML/Window/iOS/WindowImplUIKit.hpp | 10 +++--- src/SFML/Window/macOS/JoystickImpl.hpp | 4 +-- src/SFML/Window/macOS/WindowImplCocoa.hpp | 8 ++--- test/Audio/SoundSource.test.cpp | 4 +-- test/System/FileInputStream.test.cpp | 2 +- 54 files changed, 182 insertions(+), 183 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 705cb24e5..f03087b2e 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -54,7 +54,6 @@ Checks: > -misc-non-private-member-variables-in-classes, -modernize-avoid-c-arrays, -modernize-macro-to-enum, - -modernize-use-nodiscard, -modernize-use-trailing-return-type, -performance-avoid-endl, -performance-enum-size, diff --git a/examples/sound_effects/SoundEffects.cpp b/examples/sound_effects/SoundEffects.cpp index 8049170cf..623be7d86 100644 --- a/examples/sound_effects/SoundEffects.cpp +++ b/examples/sound_effects/SoundEffects.cpp @@ -44,7 +44,7 @@ public: s_font = &font; } - const std::string& getName() const + [[nodiscard]] const std::string& getName() const { return m_name; } diff --git a/include/SFML/Audio/InputSoundFile.hpp b/include/SFML/Audio/InputSoundFile.hpp index 42032972b..0e6c872a8 100644 --- a/include/SFML/Audio/InputSoundFile.hpp +++ b/include/SFML/Audio/InputSoundFile.hpp @@ -103,7 +103,7 @@ public: /// \return Number of samples /// //////////////////////////////////////////////////////////// - std::uint64_t getSampleCount() const; + [[nodiscard]] std::uint64_t getSampleCount() const; //////////////////////////////////////////////////////////// /// \brief Get the number of channels used by the sound @@ -111,7 +111,7 @@ public: /// \return Number of channels (1 = mono, 2 = stereo) /// //////////////////////////////////////////////////////////// - unsigned int getChannelCount() const; + [[nodiscard]] unsigned int getChannelCount() const; //////////////////////////////////////////////////////////// /// \brief Get the sample rate of the sound @@ -119,7 +119,7 @@ public: /// \return Sample rate, in samples per second /// //////////////////////////////////////////////////////////// - unsigned int getSampleRate() const; + [[nodiscard]] unsigned int getSampleRate() const; //////////////////////////////////////////////////////////// /// \brief Get the map of position in sample frame to sound channel @@ -132,7 +132,7 @@ public: /// \see getSampleRate, getChannelCount, getDuration /// //////////////////////////////////////////////////////////// - const std::vector& getChannelMap() const; + [[nodiscard]] const std::vector& getChannelMap() const; //////////////////////////////////////////////////////////// /// \brief Get the total duration of the sound file @@ -143,7 +143,7 @@ public: /// \return Duration of the sound file /// //////////////////////////////////////////////////////////// - Time getDuration() const; + [[nodiscard]] Time getDuration() const; //////////////////////////////////////////////////////////// /// \brief Get the read offset of the file in time @@ -151,7 +151,7 @@ public: /// \return Time position /// //////////////////////////////////////////////////////////// - Time getTimeOffset() const; + [[nodiscard]] Time getTimeOffset() const; //////////////////////////////////////////////////////////// /// \brief Get the read offset of the file in samples @@ -159,7 +159,7 @@ public: /// \return Sample position /// //////////////////////////////////////////////////////////// - std::uint64_t getSampleOffset() const; + [[nodiscard]] std::uint64_t getSampleOffset() const; //////////////////////////////////////////////////////////// /// \brief Change the current read position to the given sample offset diff --git a/include/SFML/Audio/Music.hpp b/include/SFML/Audio/Music.hpp index a01ef115f..7d69b99ce 100644 --- a/include/SFML/Audio/Music.hpp +++ b/include/SFML/Audio/Music.hpp @@ -155,7 +155,7 @@ public: /// \return Music duration /// //////////////////////////////////////////////////////////// - Time getDuration() const; + [[nodiscard]] Time getDuration() const; //////////////////////////////////////////////////////////// /// \brief Get the positions of the of the sound's looping sequence @@ -172,7 +172,7 @@ public: /// \see setLoopPoints /// //////////////////////////////////////////////////////////// - TimeSpan getLoopPoints() const; + [[nodiscard]] TimeSpan getLoopPoints() const; //////////////////////////////////////////////////////////// /// \brief Sets the beginning and duration of the sound's looping sequence using sf::Time @@ -252,7 +252,7 @@ private: /// \return The number of samples elapsed at the given time /// //////////////////////////////////////////////////////////// - std::uint64_t timeToSamples(Time position) const; + [[nodiscard]] std::uint64_t timeToSamples(Time position) const; //////////////////////////////////////////////////////////// /// \brief Helper to convert a sample position to an sf::Time @@ -262,7 +262,7 @@ private: /// \return The Time position of the given sample /// //////////////////////////////////////////////////////////// - Time samplesToTime(std::uint64_t samples) const; + [[nodiscard]] Time samplesToTime(std::uint64_t samples) const; //////////////////////////////////////////////////////////// // Member data diff --git a/include/SFML/Audio/Sound.hpp b/include/SFML/Audio/Sound.hpp index 5e763a2de..fa17b2299 100644 --- a/include/SFML/Audio/Sound.hpp +++ b/include/SFML/Audio/Sound.hpp @@ -179,7 +179,7 @@ public: /// \return Sound buffer attached to the sound /// //////////////////////////////////////////////////////////// - const SoundBuffer& getBuffer() const; + [[nodiscard]] const SoundBuffer& getBuffer() const; //////////////////////////////////////////////////////////// /// \brief Tell whether or not the sound is in loop mode @@ -189,7 +189,7 @@ public: /// \see setLoop /// //////////////////////////////////////////////////////////// - bool getLoop() const; + [[nodiscard]] bool getLoop() const; //////////////////////////////////////////////////////////// /// \brief Get the current playing position of the sound @@ -199,7 +199,7 @@ public: /// \see setPlayingOffset /// //////////////////////////////////////////////////////////// - Time getPlayingOffset() const; + [[nodiscard]] Time getPlayingOffset() const; //////////////////////////////////////////////////////////// /// \brief Get the current status of the sound (stopped, paused, playing) @@ -207,7 +207,7 @@ public: /// \return Current status of the sound /// //////////////////////////////////////////////////////////// - Status getStatus() const override; + [[nodiscard]] Status getStatus() const override; //////////////////////////////////////////////////////////// /// \brief Overload of assignment operator @@ -237,7 +237,7 @@ private: /// \return The sound object /// //////////////////////////////////////////////////////////// - void* getSound() const override; + [[nodiscard]] void* getSound() const override; //////////////////////////////////////////////////////////// // Member data diff --git a/include/SFML/Audio/SoundRecorder.hpp b/include/SFML/Audio/SoundRecorder.hpp index dd9548816..06b5a900e 100644 --- a/include/SFML/Audio/SoundRecorder.hpp +++ b/include/SFML/Audio/SoundRecorder.hpp @@ -96,7 +96,7 @@ public: /// \return Sample rate, in samples per second /// //////////////////////////////////////////////////////////// - unsigned int getSampleRate() const; + [[nodiscard]] unsigned int getSampleRate() const; //////////////////////////////////////////////////////////// /// \brief Get a list of the names of all available audio capture devices @@ -144,7 +144,7 @@ public: /// \return The name of the current audio capture device /// //////////////////////////////////////////////////////////// - const std::string& getDevice() const; + [[nodiscard]] const std::string& getDevice() const; //////////////////////////////////////////////////////////// /// \brief Set the channel count of the audio capture device @@ -172,7 +172,7 @@ public: /// \see setChannelCount /// //////////////////////////////////////////////////////////// - unsigned int getChannelCount() const; + [[nodiscard]] unsigned int getChannelCount() const; //////////////////////////////////////////////////////////// /// \brief Get the map of position in sample frame to sound channel @@ -183,7 +183,7 @@ public: /// \return Map of position in sample frame to sound channel /// //////////////////////////////////////////////////////////// - const std::vector& getChannelMap() const; + [[nodiscard]] const std::vector& getChannelMap() const; //////////////////////////////////////////////////////////// /// \brief Check if the system supports audio capture diff --git a/include/SFML/Audio/SoundSource.hpp b/include/SFML/Audio/SoundSource.hpp index abb110b79..3c99cf64e 100644 --- a/include/SFML/Audio/SoundSource.hpp +++ b/include/SFML/Audio/SoundSource.hpp @@ -440,7 +440,7 @@ public: /// \see setPitch /// //////////////////////////////////////////////////////////// - float getPitch() const; + [[nodiscard]] float getPitch() const; //////////////////////////////////////////////////////////// /// \brief Get the pan of the sound @@ -450,7 +450,7 @@ public: /// \see setPan /// //////////////////////////////////////////////////////////// - float getPan() const; + [[nodiscard]] float getPan() const; //////////////////////////////////////////////////////////// /// \brief Get the volume of the sound @@ -460,7 +460,7 @@ public: /// \see setVolume /// //////////////////////////////////////////////////////////// - float getVolume() const; + [[nodiscard]] float getVolume() const; //////////////////////////////////////////////////////////// /// \brief Tell whether spatialization of the sound is enabled @@ -470,7 +470,7 @@ public: /// \see setSpatializationEnabled /// //////////////////////////////////////////////////////////// - bool isSpatializationEnabled() const; + [[nodiscard]] bool isSpatializationEnabled() const; //////////////////////////////////////////////////////////// /// \brief Get the 3D position of the sound in the audio scene @@ -480,7 +480,7 @@ public: /// \see setPosition /// //////////////////////////////////////////////////////////// - Vector3f getPosition() const; + [[nodiscard]] Vector3f getPosition() const; //////////////////////////////////////////////////////////// /// \brief Get the 3D direction of the sound in the audio scene @@ -490,7 +490,7 @@ public: /// \see setDirection /// //////////////////////////////////////////////////////////// - Vector3f getDirection() const; + [[nodiscard]] Vector3f getDirection() const; //////////////////////////////////////////////////////////// /// \brief Get the cone properties of the sound in the audio scene @@ -500,7 +500,7 @@ public: /// \see setCone /// //////////////////////////////////////////////////////////// - Cone getCone() const; + [[nodiscard]] Cone getCone() const; //////////////////////////////////////////////////////////// /// \brief Get the 3D velocity of the sound in the audio scene @@ -510,7 +510,7 @@ public: /// \see setVelocity /// //////////////////////////////////////////////////////////// - Vector3f getVelocity() const; + [[nodiscard]] Vector3f getVelocity() const; //////////////////////////////////////////////////////////// /// \brief Get the doppler factor of the sound @@ -520,7 +520,7 @@ public: /// \see setDopplerFactor /// //////////////////////////////////////////////////////////// - float getDopplerFactor() const; + [[nodiscard]] float getDopplerFactor() const; //////////////////////////////////////////////////////////// /// \brief Get the directional attenuation factor of the sound @@ -530,7 +530,7 @@ public: /// \see setDirectionalAttenuationFactor /// //////////////////////////////////////////////////////////// - float getDirectionalAttenuationFactor() const; + [[nodiscard]] float getDirectionalAttenuationFactor() const; //////////////////////////////////////////////////////////// /// \brief Tell whether the sound's position is relative to the @@ -541,7 +541,7 @@ public: /// \see setRelativeToListener /// //////////////////////////////////////////////////////////// - bool isRelativeToListener() const; + [[nodiscard]] bool isRelativeToListener() const; //////////////////////////////////////////////////////////// /// \brief Get the minimum distance of the sound @@ -551,7 +551,7 @@ public: /// \see setMinDistance, getAttenuation /// //////////////////////////////////////////////////////////// - float getMinDistance() const; + [[nodiscard]] float getMinDistance() const; //////////////////////////////////////////////////////////// /// \brief Get the maximum distance of the sound @@ -561,7 +561,7 @@ public: /// \see setMaxDistance, getAttenuation /// //////////////////////////////////////////////////////////// - float getMaxDistance() const; + [[nodiscard]] float getMaxDistance() const; //////////////////////////////////////////////////////////// /// \brief Get the minimum gain of the sound @@ -571,7 +571,7 @@ public: /// \see setMinGain, getAttenuation /// //////////////////////////////////////////////////////////// - float getMinGain() const; + [[nodiscard]] float getMinGain() const; //////////////////////////////////////////////////////////// /// \brief Get the maximum gain of the sound @@ -581,7 +581,7 @@ public: /// \see setMaxGain, getAttenuation /// //////////////////////////////////////////////////////////// - float getMaxGain() const; + [[nodiscard]] float getMaxGain() const; //////////////////////////////////////////////////////////// /// \brief Get the attenuation factor of the sound @@ -591,7 +591,7 @@ public: /// \see setAttenuation, getMinDistance /// //////////////////////////////////////////////////////////// - float getAttenuation() const; + [[nodiscard]] float getAttenuation() const; //////////////////////////////////////////////////////////// /// \brief Overload of assignment operator @@ -644,7 +644,7 @@ public: /// \return Current status of the sound /// //////////////////////////////////////////////////////////// - virtual Status getStatus() const = 0; + [[nodiscard]] virtual Status getStatus() const = 0; protected: //////////////////////////////////////////////////////////// @@ -662,7 +662,7 @@ private: /// \return The sound object /// //////////////////////////////////////////////////////////// - virtual void* getSound() const = 0; + [[nodiscard]] virtual void* getSound() const = 0; }; // NOLINTEND(readability-make-member-function-const) diff --git a/include/SFML/Audio/SoundStream.hpp b/include/SFML/Audio/SoundStream.hpp index fdf94da53..71ab646f2 100644 --- a/include/SFML/Audio/SoundStream.hpp +++ b/include/SFML/Audio/SoundStream.hpp @@ -124,7 +124,7 @@ public: /// \return Number of channels /// //////////////////////////////////////////////////////////// - unsigned int getChannelCount() const; + [[nodiscard]] unsigned int getChannelCount() const; //////////////////////////////////////////////////////////// /// \brief Get the stream sample rate of the stream @@ -135,7 +135,7 @@ public: /// \return Sample rate, in number of samples per second /// //////////////////////////////////////////////////////////// - unsigned int getSampleRate() const; + [[nodiscard]] unsigned int getSampleRate() const; //////////////////////////////////////////////////////////// /// \brief Get the map of position in sample frame to sound channel @@ -146,7 +146,7 @@ public: /// \return Map of position in sample frame to sound channel /// //////////////////////////////////////////////////////////// - std::vector getChannelMap() const; + [[nodiscard]] std::vector getChannelMap() const; //////////////////////////////////////////////////////////// /// \brief Get the current status of the stream (stopped, paused, playing) @@ -154,7 +154,7 @@ public: /// \return Current status /// //////////////////////////////////////////////////////////// - Status getStatus() const override; + [[nodiscard]] Status getStatus() const override; //////////////////////////////////////////////////////////// /// \brief Change the current playing position of the stream @@ -179,7 +179,7 @@ public: /// \see setPlayingOffset /// //////////////////////////////////////////////////////////// - Time getPlayingOffset() const; + [[nodiscard]] Time getPlayingOffset() const; //////////////////////////////////////////////////////////// /// \brief Set whether or not the stream should loop after reaching the end @@ -204,7 +204,7 @@ public: /// \see setLoop /// //////////////////////////////////////////////////////////// - bool getLoop() const; + [[nodiscard]] bool getLoop() const; //////////////////////////////////////////////////////////// /// \brief Set the effect processor to be applied to the sound @@ -292,7 +292,7 @@ private: /// \return The sound object /// //////////////////////////////////////////////////////////// - void* getSound() const override; + [[nodiscard]] void* getSound() const override; //////////////////////////////////////////////////////////// // Member data diff --git a/include/SFML/Graphics/Color.hpp b/include/SFML/Graphics/Color.hpp index 869a25097..f847fb159 100644 --- a/include/SFML/Graphics/Color.hpp +++ b/include/SFML/Graphics/Color.hpp @@ -75,7 +75,7 @@ public: /// \return Color represented as a 32-bit unsigned integer /// //////////////////////////////////////////////////////////// - constexpr std::uint32_t toInteger() const; + [[nodiscard]] constexpr std::uint32_t toInteger() const; //////////////////////////////////////////////////////////// // Static member data diff --git a/include/SFML/Graphics/Image.hpp b/include/SFML/Graphics/Image.hpp index 6c94eef04..a15be9fc7 100644 --- a/include/SFML/Graphics/Image.hpp +++ b/include/SFML/Graphics/Image.hpp @@ -170,7 +170,7 @@ public: /// \return Size of the image, in pixels /// //////////////////////////////////////////////////////////// - Vector2u getSize() const; + [[nodiscard]] Vector2u getSize() const; //////////////////////////////////////////////////////////// /// \brief Create a transparency mask from a specified color-key @@ -248,7 +248,7 @@ public: /// \see setPixel /// //////////////////////////////////////////////////////////// - Color getPixel(const Vector2u& coords) const; + [[nodiscard]] Color getPixel(const Vector2u& coords) const; //////////////////////////////////////////////////////////// /// \brief Get a read-only pointer to the array of pixels @@ -263,7 +263,7 @@ public: /// \return Read-only pointer to the array of pixels /// //////////////////////////////////////////////////////////// - const std::uint8_t* getPixelsPtr() const; + [[nodiscard]] const std::uint8_t* getPixelsPtr() const; //////////////////////////////////////////////////////////// /// \brief Flip the image horizontally (left <-> right) diff --git a/include/SFML/Graphics/Rect.hpp b/include/SFML/Graphics/Rect.hpp index fbcad4bd7..62fb98c19 100644 --- a/include/SFML/Graphics/Rect.hpp +++ b/include/SFML/Graphics/Rect.hpp @@ -90,7 +90,7 @@ public: /// \see findIntersection /// //////////////////////////////////////////////////////////// - constexpr bool contains(const Vector2& point) const; + [[nodiscard]] constexpr bool contains(const Vector2& point) const; //////////////////////////////////////////////////////////// /// \brief Check the intersection between two rectangles @@ -102,7 +102,7 @@ public: /// \see contains /// //////////////////////////////////////////////////////////// - constexpr std::optional> findIntersection(const Rect& rectangle) const; + [[nodiscard]] constexpr std::optional> findIntersection(const Rect& rectangle) const; //////////////////////////////////////////////////////////// /// \brief Get the position of the center of the rectangle @@ -110,7 +110,7 @@ public: /// \return Center of rectangle /// //////////////////////////////////////////////////////////// - constexpr Vector2 getCenter() const; + [[nodiscard]] constexpr Vector2 getCenter() const; //////////////////////////////////////////////////////////// // Member data diff --git a/include/SFML/Graphics/Shader.hpp b/include/SFML/Graphics/Shader.hpp index 48b725c04..c60cfeb7c 100644 --- a/include/SFML/Graphics/Shader.hpp +++ b/include/SFML/Graphics/Shader.hpp @@ -588,7 +588,7 @@ public: /// \return OpenGL handle of the shader or 0 if not yet loaded /// //////////////////////////////////////////////////////////// - unsigned int getNativeHandle() const; + [[nodiscard]] unsigned int getNativeHandle() const; //////////////////////////////////////////////////////////// /// \brief Bind a shader for rendering diff --git a/include/SFML/Graphics/Transform.hpp b/include/SFML/Graphics/Transform.hpp index 8d9182462..826e1579d 100644 --- a/include/SFML/Graphics/Transform.hpp +++ b/include/SFML/Graphics/Transform.hpp @@ -86,7 +86,7 @@ public: /// \return Pointer to a 4x4 matrix /// //////////////////////////////////////////////////////////// - constexpr const float* getMatrix() const; + [[nodiscard]] constexpr const float* getMatrix() const; //////////////////////////////////////////////////////////// /// \brief Return the inverse of the transform @@ -97,7 +97,7 @@ public: /// \return A new transform which is the inverse of self /// //////////////////////////////////////////////////////////// - constexpr Transform getInverse() const; + [[nodiscard]] constexpr Transform getInverse() const; //////////////////////////////////////////////////////////// /// \brief Transform a 2D point @@ -113,7 +113,7 @@ public: /// \return Transformed point /// //////////////////////////////////////////////////////////// - constexpr Vector2f transformPoint(const Vector2f& point) const; + [[nodiscard]] constexpr Vector2f transformPoint(const Vector2f& point) const; //////////////////////////////////////////////////////////// /// \brief Transform a rectangle @@ -129,7 +129,7 @@ public: /// \return Transformed rectangle /// //////////////////////////////////////////////////////////// - constexpr FloatRect transformRect(const FloatRect& rectangle) const; + [[nodiscard]] constexpr FloatRect transformRect(const FloatRect& rectangle) const; //////////////////////////////////////////////////////////// /// \brief Combine the current transform with another one diff --git a/include/SFML/Graphics/VertexArray.hpp b/include/SFML/Graphics/VertexArray.hpp index 9a3a8b534..9c2f66302 100644 --- a/include/SFML/Graphics/VertexArray.hpp +++ b/include/SFML/Graphics/VertexArray.hpp @@ -74,7 +74,7 @@ public: /// \return Number of vertices in the array /// //////////////////////////////////////////////////////////// - std::size_t getVertexCount() const; + [[nodiscard]] std::size_t getVertexCount() const; //////////////////////////////////////////////////////////// /// \brief Get a read-write access to a vertex by its index @@ -162,7 +162,7 @@ public: /// \return Primitive type /// //////////////////////////////////////////////////////////// - PrimitiveType getPrimitiveType() const; + [[nodiscard]] PrimitiveType getPrimitiveType() const; //////////////////////////////////////////////////////////// /// \brief Compute the bounding rectangle of the vertex array @@ -173,7 +173,7 @@ public: /// \return Bounding rectangle of the vertex array /// //////////////////////////////////////////////////////////// - FloatRect getBounds() const; + [[nodiscard]] FloatRect getBounds() const; private: //////////////////////////////////////////////////////////// diff --git a/include/SFML/Graphics/VertexBuffer.hpp b/include/SFML/Graphics/VertexBuffer.hpp index 510a3e182..43f2a326a 100644 --- a/include/SFML/Graphics/VertexBuffer.hpp +++ b/include/SFML/Graphics/VertexBuffer.hpp @@ -145,7 +145,7 @@ public: /// \return Number of vertices in the vertex buffer /// //////////////////////////////////////////////////////////// - std::size_t getVertexCount() const; + [[nodiscard]] std::size_t getVertexCount() const; //////////////////////////////////////////////////////////// /// \brief Update the whole buffer from an array of vertices @@ -238,7 +238,7 @@ public: /// \return OpenGL handle of the vertex buffer or 0 if not yet created /// //////////////////////////////////////////////////////////// - unsigned int getNativeHandle() const; + [[nodiscard]] unsigned int getNativeHandle() const; //////////////////////////////////////////////////////////// /// \brief Set the type of primitives to draw @@ -259,7 +259,7 @@ public: /// \return Primitive type /// //////////////////////////////////////////////////////////// - PrimitiveType getPrimitiveType() const; + [[nodiscard]] PrimitiveType getPrimitiveType() const; //////////////////////////////////////////////////////////// /// \brief Set the usage specifier of this vertex buffer @@ -284,7 +284,7 @@ public: /// \return Usage specifier /// //////////////////////////////////////////////////////////// - Usage getUsage() const; + [[nodiscard]] Usage getUsage() const; //////////////////////////////////////////////////////////// /// \brief Bind a vertex buffer for rendering diff --git a/include/SFML/Network/Ftp.hpp b/include/SFML/Network/Ftp.hpp index ee7fd2366..30b538a04 100644 --- a/include/SFML/Network/Ftp.hpp +++ b/include/SFML/Network/Ftp.hpp @@ -154,7 +154,7 @@ public: /// \return True if the status is a success, false if it is a failure /// //////////////////////////////////////////////////////////// - bool isOk() const; + [[nodiscard]] bool isOk() const; //////////////////////////////////////////////////////////// /// \brief Get the status code of the response @@ -162,7 +162,7 @@ public: /// \return Status code /// //////////////////////////////////////////////////////////// - Status getStatus() const; + [[nodiscard]] Status getStatus() const; //////////////////////////////////////////////////////////// /// \brief Get the full message contained in the response @@ -170,7 +170,7 @@ public: /// \return The response message /// //////////////////////////////////////////////////////////// - const std::string& getMessage() const; + [[nodiscard]] const std::string& getMessage() const; private: //////////////////////////////////////////////////////////// @@ -201,7 +201,7 @@ public: /// \return Directory name /// //////////////////////////////////////////////////////////// - const std::filesystem::path& getDirectory() const; + [[nodiscard]] const std::filesystem::path& getDirectory() const; private: //////////////////////////////////////////////////////////// @@ -233,7 +233,7 @@ public: /// \return Array containing the requested listing /// //////////////////////////////////////////////////////////// - const std::vector& getListing() const; + [[nodiscard]] const std::vector& getListing() const; private: //////////////////////////////////////////////////////////// diff --git a/include/SFML/Network/Http.hpp b/include/SFML/Network/Http.hpp index 779f4a186..9c03415d6 100644 --- a/include/SFML/Network/Http.hpp +++ b/include/SFML/Network/Http.hpp @@ -168,7 +168,7 @@ public: /// \return True if the field exists, false otherwise /// //////////////////////////////////////////////////////////// - bool hasField(const std::string& field) const; + [[nodiscard]] bool hasField(const std::string& field) const; //////////////////////////////////////////////////////////// // Types @@ -245,7 +245,7 @@ public: /// \return Value of the field, or empty string if not found /// //////////////////////////////////////////////////////////// - const std::string& getField(const std::string& field) const; + [[nodiscard]] const std::string& getField(const std::string& field) const; //////////////////////////////////////////////////////////// /// \brief Get the response status code @@ -258,7 +258,7 @@ public: /// \return Status code of the response /// //////////////////////////////////////////////////////////// - Status getStatus() const; + [[nodiscard]] Status getStatus() const; //////////////////////////////////////////////////////////// /// \brief Get the major HTTP version number of the response @@ -268,7 +268,7 @@ public: /// \see getMinorHttpVersion /// //////////////////////////////////////////////////////////// - unsigned int getMajorHttpVersion() const; + [[nodiscard]] unsigned int getMajorHttpVersion() const; //////////////////////////////////////////////////////////// /// \brief Get the minor HTTP version number of the response @@ -278,7 +278,7 @@ public: /// \see getMajorHttpVersion /// //////////////////////////////////////////////////////////// - unsigned int getMinorHttpVersion() const; + [[nodiscard]] unsigned int getMinorHttpVersion() const; //////////////////////////////////////////////////////////// /// \brief Get the body of the response @@ -292,7 +292,7 @@ public: /// \return The response body /// //////////////////////////////////////////////////////////// - const std::string& getBody() const; + [[nodiscard]] const std::string& getBody() const; private: friend class Http; diff --git a/include/SFML/Network/IpAddress.hpp b/include/SFML/Network/IpAddress.hpp index 4ca5d5038..dcbd52254 100644 --- a/include/SFML/Network/IpAddress.hpp +++ b/include/SFML/Network/IpAddress.hpp @@ -103,7 +103,7 @@ public: /// \see toInteger /// //////////////////////////////////////////////////////////// - std::string toString() const; + [[nodiscard]] std::string toString() const; //////////////////////////////////////////////////////////// /// \brief Get an integer representation of the address @@ -119,7 +119,7 @@ public: /// \see toString /// //////////////////////////////////////////////////////////// - std::uint32_t toInteger() const; + [[nodiscard]] std::uint32_t toInteger() const; //////////////////////////////////////////////////////////// /// \brief Get the computer's local address diff --git a/include/SFML/Network/Packet.hpp b/include/SFML/Network/Packet.hpp index 6cf2226fa..56ecc912e 100644 --- a/include/SFML/Network/Packet.hpp +++ b/include/SFML/Network/Packet.hpp @@ -108,7 +108,7 @@ public: /// \see append /// //////////////////////////////////////////////////////////// - std::size_t getReadPosition() const; + [[nodiscard]] std::size_t getReadPosition() const; //////////////////////////////////////////////////////////// /// \brief Clear the packet @@ -133,7 +133,7 @@ public: /// \see getDataSize /// //////////////////////////////////////////////////////////// - const void* getData() const; + [[nodiscard]] const void* getData() const; //////////////////////////////////////////////////////////// /// \brief Get the size of the data contained in the packet @@ -146,7 +146,7 @@ public: /// \see getData /// //////////////////////////////////////////////////////////// - std::size_t getDataSize() const; + [[nodiscard]] std::size_t getDataSize() const; //////////////////////////////////////////////////////////// /// \brief Tell if the reading position has reached the @@ -160,7 +160,7 @@ public: /// \see operator bool /// //////////////////////////////////////////////////////////// - bool endOfPacket() const; + [[nodiscard]] bool endOfPacket() const; //////////////////////////////////////////////////////////// /// \brief Test the validity of the packet, for reading diff --git a/include/SFML/Network/Socket.hpp b/include/SFML/Network/Socket.hpp index d2022eddc..bbb4c1606 100644 --- a/include/SFML/Network/Socket.hpp +++ b/include/SFML/Network/Socket.hpp @@ -118,7 +118,7 @@ public: /// \see setBlocking /// //////////////////////////////////////////////////////////// - bool isBlocking() const; + [[nodiscard]] bool isBlocking() const; protected: //////////////////////////////////////////////////////////// @@ -151,7 +151,7 @@ protected: /// \return The internal (OS-specific) handle of the socket /// //////////////////////////////////////////////////////////// - SocketHandle getNativeHandle() const; + [[nodiscard]] SocketHandle getNativeHandle() const; //////////////////////////////////////////////////////////// /// \brief Create the internal representation of the socket diff --git a/include/SFML/Network/TcpListener.hpp b/include/SFML/Network/TcpListener.hpp index a6232c7c8..c3b82bdbe 100644 --- a/include/SFML/Network/TcpListener.hpp +++ b/include/SFML/Network/TcpListener.hpp @@ -61,7 +61,7 @@ public: /// \see listen /// //////////////////////////////////////////////////////////// - unsigned short getLocalPort() const; + [[nodiscard]] unsigned short getLocalPort() const; //////////////////////////////////////////////////////////// /// \brief Start listening for incoming connection attempts diff --git a/include/SFML/Network/TcpSocket.hpp b/include/SFML/Network/TcpSocket.hpp index 9ed632539..29581e9b7 100644 --- a/include/SFML/Network/TcpSocket.hpp +++ b/include/SFML/Network/TcpSocket.hpp @@ -69,7 +69,7 @@ public: /// \see connect, getRemotePort /// //////////////////////////////////////////////////////////// - unsigned short getLocalPort() const; + [[nodiscard]] unsigned short getLocalPort() const; //////////////////////////////////////////////////////////// /// \brief Get the address of the connected peer @@ -82,7 +82,7 @@ public: /// \see getRemotePort /// //////////////////////////////////////////////////////////// - std::optional getRemoteAddress() const; + [[nodiscard]] std::optional getRemoteAddress() const; //////////////////////////////////////////////////////////// /// \brief Get the port of the connected peer to which @@ -95,7 +95,7 @@ public: /// \see getRemoteAddress /// //////////////////////////////////////////////////////////// - unsigned short getRemotePort() const; + [[nodiscard]] unsigned short getRemotePort() const; //////////////////////////////////////////////////////////// /// \brief Connect the socket to a remote peer diff --git a/include/SFML/Network/UdpSocket.hpp b/include/SFML/Network/UdpSocket.hpp index 9cf165fef..933ca0481 100644 --- a/include/SFML/Network/UdpSocket.hpp +++ b/include/SFML/Network/UdpSocket.hpp @@ -72,7 +72,7 @@ public: /// \see bind /// //////////////////////////////////////////////////////////// - unsigned short getLocalPort() const; + [[nodiscard]] unsigned short getLocalPort() const; //////////////////////////////////////////////////////////// /// \brief Bind the socket to a specific port diff --git a/include/SFML/System/Clock.hpp b/include/SFML/System/Clock.hpp index 7fed7f109..9ddddbbb4 100644 --- a/include/SFML/System/Clock.hpp +++ b/include/SFML/System/Clock.hpp @@ -101,7 +101,7 @@ public: /// \return Time elapsed /// //////////////////////////////////////////////////////////// - Time getElapsedTime() const; + [[nodiscard]] Time getElapsedTime() const; //////////////////////////////////////////////////////////// /// \brief Check whether the clock is running @@ -109,7 +109,7 @@ public: /// \return True if the clock is running, false otherwise /// //////////////////////////////////////////////////////////// - bool isRunning() const; + [[nodiscard]] bool isRunning() const; //////////////////////////////////////////////////////////// /// \brief Start the clock diff --git a/include/SFML/System/String.hpp b/include/SFML/System/String.hpp index 383e0120d..d5b8502ba 100644 --- a/include/SFML/System/String.hpp +++ b/include/SFML/System/String.hpp @@ -310,7 +310,7 @@ public: /// \see toUtf16, toUtf32 /// //////////////////////////////////////////////////////////// - sf::U8String toUtf8() const; + [[nodiscard]] sf::U8String toUtf8() const; //////////////////////////////////////////////////////////// /// \brief Convert the Unicode string to a UTF-16 string @@ -320,7 +320,7 @@ public: /// \see toUtf8, toUtf32 /// //////////////////////////////////////////////////////////// - std::u16string toUtf16() const; + [[nodiscard]] std::u16string toUtf16() const; //////////////////////////////////////////////////////////// /// \brief Convert the Unicode string to a UTF-32 string @@ -333,7 +333,7 @@ public: /// \see toUtf8, toUtf16 /// //////////////////////////////////////////////////////////// - std::u32string toUtf32() const; + [[nodiscard]] std::u32string toUtf32() const; //////////////////////////////////////////////////////////// /// \brief Overload of += operator to append an UTF-32 string @@ -389,7 +389,7 @@ public: /// \see isEmpty /// //////////////////////////////////////////////////////////// - std::size_t getSize() const; + [[nodiscard]] std::size_t getSize() const; //////////////////////////////////////////////////////////// /// \brief Check whether the string is empty or not @@ -399,7 +399,7 @@ public: /// \see clear, getSize /// //////////////////////////////////////////////////////////// - bool isEmpty() const; + [[nodiscard]] bool isEmpty() const; //////////////////////////////////////////////////////////// /// \brief Erase one or more characters from the string @@ -493,7 +493,7 @@ public: /// \return Read-only pointer to the array of characters /// //////////////////////////////////////////////////////////// - const char32_t* getData() const; + [[nodiscard]] const char32_t* getData() const; //////////////////////////////////////////////////////////// /// \brief Return an iterator to the beginning of the string @@ -513,7 +513,7 @@ public: /// \see end /// //////////////////////////////////////////////////////////// - ConstIterator begin() const; + [[nodiscard]] ConstIterator begin() const; //////////////////////////////////////////////////////////// /// \brief Return an iterator to the end of the string @@ -541,7 +541,7 @@ public: /// \see begin /// //////////////////////////////////////////////////////////// - ConstIterator end() const; + [[nodiscard]] ConstIterator end() const; private: friend SFML_SYSTEM_API bool operator==(const String& left, const String& right); diff --git a/include/SFML/System/Time.hpp b/include/SFML/System/Time.hpp index 9b637dc28..7105b7fb8 100644 --- a/include/SFML/System/Time.hpp +++ b/include/SFML/System/Time.hpp @@ -66,7 +66,7 @@ public: /// \see asMilliseconds, asMicroseconds /// //////////////////////////////////////////////////////////// - constexpr float asSeconds() const; + [[nodiscard]] constexpr float asSeconds() const; //////////////////////////////////////////////////////////// /// \brief Return the time value as a number of milliseconds @@ -76,7 +76,7 @@ public: /// \see asSeconds, asMicroseconds /// //////////////////////////////////////////////////////////// - constexpr std::int32_t asMilliseconds() const; + [[nodiscard]] constexpr std::int32_t asMilliseconds() const; //////////////////////////////////////////////////////////// /// \brief Return the time value as a number of microseconds @@ -86,7 +86,7 @@ public: /// \see asSeconds, asMilliseconds /// //////////////////////////////////////////////////////////// - constexpr std::int64_t asMicroseconds() const; + [[nodiscard]] constexpr std::int64_t asMicroseconds() const; //////////////////////////////////////////////////////////// /// \brief Return the time value as a std::chorono::duration @@ -94,7 +94,7 @@ public: /// \return Time in microseconds /// //////////////////////////////////////////////////////////// - constexpr std::chrono::microseconds toDuration() const; + [[nodiscard]] constexpr std::chrono::microseconds toDuration() const; //////////////////////////////////////////////////////////// /// \brief Implicit conversion to std::chrono::duration diff --git a/include/SFML/System/Vector2.hpp b/include/SFML/System/Vector2.hpp index 66fa1cc26..45a6c8e84 100644 --- a/include/SFML/System/Vector2.hpp +++ b/include/SFML/System/Vector2.hpp @@ -93,7 +93,7 @@ public: /// If you are not interested in the actual length, but only in comparisons, consider using lengthSq(). /// //////////////////////////////////////////////////////////// - SFML_SYSTEM_API T length() const; + [[nodiscard]] SFML_SYSTEM_API T length() const; //////////////////////////////////////////////////////////// /// \brief Square of vector's length. @@ -101,7 +101,7 @@ public: /// Suitable for comparisons, more efficient than length(). /// //////////////////////////////////////////////////////////// - constexpr T lengthSq() const; + [[nodiscard]] constexpr T lengthSq() const; //////////////////////////////////////////////////////////// /// \brief Vector with same direction but length 1 (floating-point). @@ -120,7 +120,7 @@ public: /// \pre Neither \c *this nor \c rhs is a zero vector. /// //////////////////////////////////////////////////////////// - SFML_SYSTEM_API Angle angleTo(const Vector2& rhs) const; + [[nodiscard]] SFML_SYSTEM_API Angle angleTo(const Vector2& rhs) const; //////////////////////////////////////////////////////////// /// \brief Signed angle from +X or (1,0) vector (floating-point). @@ -131,7 +131,7 @@ public: /// \pre This vector is no zero vector. /// //////////////////////////////////////////////////////////// - SFML_SYSTEM_API Angle angle() const; + [[nodiscard]] SFML_SYSTEM_API Angle angle() const; //////////////////////////////////////////////////////////// /// \brief Rotate by angle \c phi (floating-point). @@ -163,13 +163,13 @@ public: /// this amounts to a clockwise rotation. /// //////////////////////////////////////////////////////////// - constexpr Vector2 perpendicular() const; + [[nodiscard]] constexpr Vector2 perpendicular() const; //////////////////////////////////////////////////////////// /// \brief Dot product of two 2D vectors. /// //////////////////////////////////////////////////////////// - constexpr T dot(const Vector2& rhs) const; + [[nodiscard]] constexpr T dot(const Vector2& rhs) const; //////////////////////////////////////////////////////////// /// \brief Z component of the cross product of two 2D vectors. @@ -178,7 +178,7 @@ public: /// and returns the result's Z component (X and Y components are always zero). /// //////////////////////////////////////////////////////////// - constexpr T cross(const Vector2& rhs) const; + [[nodiscard]] constexpr T cross(const Vector2& rhs) const; //////////////////////////////////////////////////////////// /// \brief Component-wise multiplication of \c *this and \c rhs. @@ -189,7 +189,7 @@ public: /// This operation is also known as the Hadamard or Schur product. /// //////////////////////////////////////////////////////////// - constexpr Vector2 cwiseMul(const Vector2& rhs) const; + [[nodiscard]] constexpr Vector2 cwiseMul(const Vector2& rhs) const; //////////////////////////////////////////////////////////// /// \brief Component-wise division of \c *this and \c rhs. @@ -201,7 +201,7 @@ public: /// \pre Neither component of \c rhs is zero. /// //////////////////////////////////////////////////////////// - constexpr Vector2 cwiseDiv(const Vector2& rhs) const; + [[nodiscard]] constexpr Vector2 cwiseDiv(const Vector2& rhs) const; //////////////////////////////////////////////////////////// diff --git a/include/SFML/System/Vector3.hpp b/include/SFML/System/Vector3.hpp index 5b8ddb5db..d3d8fc9fb 100644 --- a/include/SFML/System/Vector3.hpp +++ b/include/SFML/System/Vector3.hpp @@ -76,7 +76,7 @@ public: /// If you are not interested in the actual length, but only in comparisons, consider using lengthSq(). /// //////////////////////////////////////////////////////////// - SFML_SYSTEM_API T length() const; + [[nodiscard]] SFML_SYSTEM_API T length() const; //////////////////////////////////////////////////////////// /// \brief Square of vector's length. @@ -84,7 +84,7 @@ public: /// Suitable for comparisons, more efficient than length(). /// //////////////////////////////////////////////////////////// - constexpr T lengthSq() const; + [[nodiscard]] constexpr T lengthSq() const; //////////////////////////////////////////////////////////// /// \brief Vector with same direction but length 1 (floating-point). @@ -98,13 +98,13 @@ public: /// \brief Dot product of two 3D vectors. /// //////////////////////////////////////////////////////////// - constexpr T dot(const Vector3& rhs) const; + [[nodiscard]] constexpr T dot(const Vector3& rhs) const; //////////////////////////////////////////////////////////// /// \brief Cross product of two 3D vectors. /// //////////////////////////////////////////////////////////// - constexpr Vector3 cross(const Vector3& rhs) const; + [[nodiscard]] constexpr Vector3 cross(const Vector3& rhs) const; //////////////////////////////////////////////////////////// /// \brief Component-wise multiplication of \c *this and \c rhs. @@ -115,7 +115,7 @@ public: /// This operation is also known as the Hadamard or Schur product. /// //////////////////////////////////////////////////////////// - constexpr Vector3 cwiseMul(const Vector3& rhs) const; + [[nodiscard]] constexpr Vector3 cwiseMul(const Vector3& rhs) const; //////////////////////////////////////////////////////////// /// \brief Component-wise division of \c *this and \c rhs. @@ -127,7 +127,7 @@ public: /// \pre Neither component of \c rhs is zero. /// //////////////////////////////////////////////////////////// - constexpr Vector3 cwiseDiv(const Vector3& rhs) const; + [[nodiscard]] constexpr Vector3 cwiseDiv(const Vector3& rhs) const; //////////////////////////////////////////////////////////// // Member data diff --git a/include/SFML/Window/Context.hpp b/include/SFML/Window/Context.hpp index f9d4667f7..ddd7710e1 100644 --- a/include/SFML/Window/Context.hpp +++ b/include/SFML/Window/Context.hpp @@ -117,7 +117,7 @@ public: /// \return Structure containing the settings /// //////////////////////////////////////////////////////////// - const ContextSettings& getSettings() const; + [[nodiscard]] const ContextSettings& getSettings() const; //////////////////////////////////////////////////////////// /// \brief Check whether a given OpenGL extension is available diff --git a/include/SFML/Window/Cursor.hpp b/include/SFML/Window/Cursor.hpp index 7db18bc50..e5a9bf28c 100644 --- a/include/SFML/Window/Cursor.hpp +++ b/include/SFML/Window/Cursor.hpp @@ -210,7 +210,7 @@ private: /// \return a reference to the OS-specific implementation /// //////////////////////////////////////////////////////////// - const priv::CursorImpl& getImpl() const; + [[nodiscard]] const priv::CursorImpl& getImpl() const; //////////////////////////////////////////////////////////// // Member data diff --git a/include/SFML/Window/VideoMode.hpp b/include/SFML/Window/VideoMode.hpp index a7041b14e..dfc16a4a2 100644 --- a/include/SFML/Window/VideoMode.hpp +++ b/include/SFML/Window/VideoMode.hpp @@ -94,7 +94,7 @@ public: /// \return True if the video mode is valid for fullscreen mode /// //////////////////////////////////////////////////////////// - bool isValid() const; + [[nodiscard]] bool isValid() const; //////////////////////////////////////////////////////////// // Member data diff --git a/include/SFML/Window/Window.hpp b/include/SFML/Window/Window.hpp index fd16967a2..be9d884f3 100644 --- a/include/SFML/Window/Window.hpp +++ b/include/SFML/Window/Window.hpp @@ -221,7 +221,7 @@ public: /// \return Structure containing the OpenGL context settings /// //////////////////////////////////////////////////////////// - const ContextSettings& getSettings() const; + [[nodiscard]] const ContextSettings& getSettings() const; //////////////////////////////////////////////////////////// /// \brief Enable or disable vertical synchronization diff --git a/include/SFML/Window/WindowBase.hpp b/include/SFML/Window/WindowBase.hpp index f6c213e4b..6955f8bba 100644 --- a/include/SFML/Window/WindowBase.hpp +++ b/include/SFML/Window/WindowBase.hpp @@ -175,7 +175,7 @@ public: /// \return True if the window is open, false if it has been closed /// //////////////////////////////////////////////////////////// - bool isOpen() const; + [[nodiscard]] bool isOpen() const; //////////////////////////////////////////////////////////// /// \brief Pop the next event from the front of the FIFO event queue, if any, and return it @@ -233,7 +233,7 @@ public: /// \see setPosition /// //////////////////////////////////////////////////////////// - Vector2i getPosition() const; + [[nodiscard]] Vector2i getPosition() const; //////////////////////////////////////////////////////////// /// \brief Change the position of the window on screen @@ -260,7 +260,7 @@ public: /// \see setSize /// //////////////////////////////////////////////////////////// - Vector2u getSize() const; + [[nodiscard]] Vector2u getSize() const; //////////////////////////////////////////////////////////// /// \brief Change the size of the rendering region of the window @@ -426,7 +426,7 @@ public: /// \see requestFocus /// //////////////////////////////////////////////////////////// - bool hasFocus() const; + [[nodiscard]] bool hasFocus() const; //////////////////////////////////////////////////////////// /// \brief Get the OS-specific handle of the window @@ -440,7 +440,7 @@ public: /// \return System handle of the window /// //////////////////////////////////////////////////////////// - WindowHandle getNativeHandle() const; + [[nodiscard]] WindowHandle getNativeHandle() const; //////////////////////////////////////////////////////////// /// \brief Create a Vulkan rendering surface diff --git a/src/SFML/Audio/AudioDevice.hpp b/src/SFML/Audio/AudioDevice.hpp index d85b97845..40491d29c 100644 --- a/src/SFML/Audio/AudioDevice.hpp +++ b/src/SFML/Audio/AudioDevice.hpp @@ -331,7 +331,7 @@ private: /// \return The device ID of the currently selected device or `std::nullopt` if none could be found /// //////////////////////////////////////////////////////////// - std::optional getSelectedDeviceId() const; + [[nodiscard]] std::optional getSelectedDeviceId() const; //////////////////////////////////////////////////////////// /// \brief Initialize the audio device and engine diff --git a/src/SFML/Graphics/RenderTextureImpl.hpp b/src/SFML/Graphics/RenderTextureImpl.hpp index 97e7ff7f4..6aabcabe2 100644 --- a/src/SFML/Graphics/RenderTextureImpl.hpp +++ b/src/SFML/Graphics/RenderTextureImpl.hpp @@ -99,7 +99,7 @@ public: /// \return True if the render-texture use sRGB encoding, false otherwise /// //////////////////////////////////////////////////////////// - virtual bool isSrgb() const = 0; + [[nodiscard]] virtual bool isSrgb() const = 0; //////////////////////////////////////////////////////////// /// \brief Update the pixels of the target texture diff --git a/src/SFML/Graphics/RenderTextureImplDefault.hpp b/src/SFML/Graphics/RenderTextureImplDefault.hpp index 71af51f3a..65b99c8b5 100644 --- a/src/SFML/Graphics/RenderTextureImplDefault.hpp +++ b/src/SFML/Graphics/RenderTextureImplDefault.hpp @@ -103,7 +103,7 @@ private: /// \return True if the render-texture use sRGB encoding, false otherwise /// //////////////////////////////////////////////////////////// - bool isSrgb() const override; + [[nodiscard]] bool isSrgb() const override; //////////////////////////////////////////////////////////// /// \brief Update the pixels of the target texture diff --git a/src/SFML/Graphics/RenderTextureImplFBO.hpp b/src/SFML/Graphics/RenderTextureImplFBO.hpp index fd8b65cd1..e2e12ae59 100644 --- a/src/SFML/Graphics/RenderTextureImplFBO.hpp +++ b/src/SFML/Graphics/RenderTextureImplFBO.hpp @@ -128,7 +128,7 @@ private: /// \return True if the render-texture use sRGB encoding, false otherwise /// //////////////////////////////////////////////////////////// - bool isSrgb() const override; + [[nodiscard]] bool isSrgb() const override; //////////////////////////////////////////////////////////// /// \brief Update the pixels of the target texture diff --git a/src/SFML/Window/Android/JoystickImpl.hpp b/src/SFML/Window/Android/JoystickImpl.hpp index 30fb8edba..0ceedcc28 100644 --- a/src/SFML/Window/Android/JoystickImpl.hpp +++ b/src/SFML/Window/Android/JoystickImpl.hpp @@ -78,7 +78,7 @@ public: /// \return Joystick capabilities /// //////////////////////////////////////////////////////////// - JoystickCaps getCapabilities() const; + [[nodiscard]] JoystickCaps getCapabilities() const; //////////////////////////////////////////////////////////// /// \brief Get the joystick identification @@ -86,7 +86,7 @@ public: /// \return Joystick identification /// //////////////////////////////////////////////////////////// - Joystick::Identification getIdentification() const; + [[nodiscard]] Joystick::Identification getIdentification() const; //////////////////////////////////////////////////////////// /// \brief Update the joystick and get its new state diff --git a/src/SFML/Window/Android/WindowImplAndroid.hpp b/src/SFML/Window/Android/WindowImplAndroid.hpp index d87bf5a04..3e35bb0dd 100644 --- a/src/SFML/Window/Android/WindowImplAndroid.hpp +++ b/src/SFML/Window/Android/WindowImplAndroid.hpp @@ -77,7 +77,7 @@ public: /// \return Handle of the window /// //////////////////////////////////////////////////////////// - WindowHandle getNativeHandle() const override; + [[nodiscard]] WindowHandle getNativeHandle() const override; //////////////////////////////////////////////////////////// /// \brief Get the position of the window @@ -85,7 +85,7 @@ public: /// \return Position of the window, in pixels /// //////////////////////////////////////////////////////////// - Vector2i getPosition() const override; + [[nodiscard]] Vector2i getPosition() const override; //////////////////////////////////////////////////////////// /// \brief Change the position of the window on screen @@ -101,7 +101,7 @@ public: /// \return Size of the window, in pixels /// //////////////////////////////////////////////////////////// - Vector2u getSize() const override; + [[nodiscard]] Vector2u getSize() const override; //////////////////////////////////////////////////////////// /// \brief Change the size of the rendering region of the window @@ -201,7 +201,7 @@ public: /// \return True if window has focus, false otherwise /// //////////////////////////////////////////////////////////// - bool hasFocus() const override; + [[nodiscard]] bool hasFocus() const override; static void forwardEvent(const Event& event); static WindowImplAndroid* singleInstance; diff --git a/src/SFML/Window/DRM/WindowImplDRM.hpp b/src/SFML/Window/DRM/WindowImplDRM.hpp index 5babf76be..a19d0c1b2 100644 --- a/src/SFML/Window/DRM/WindowImplDRM.hpp +++ b/src/SFML/Window/DRM/WindowImplDRM.hpp @@ -71,7 +71,7 @@ public: /// \return Handle of the window /// //////////////////////////////////////////////////////////// - WindowHandle getNativeHandle() const override; + [[nodiscard]] WindowHandle getNativeHandle() const override; //////////////////////////////////////////////////////////// /// \brief Get the position of the window @@ -79,7 +79,7 @@ public: /// \return Position of the window, in pixels /// //////////////////////////////////////////////////////////// - Vector2i getPosition() const override; + [[nodiscard]] Vector2i getPosition() const override; //////////////////////////////////////////////////////////// /// \brief Change the position of the window on screen @@ -95,7 +95,7 @@ public: /// \return Size of the window, in pixels /// //////////////////////////////////////////////////////////// - Vector2u getSize() const override; + [[nodiscard]] Vector2u getSize() const override; //////////////////////////////////////////////////////////// /// \brief Change the size of the rendering region of the window @@ -195,7 +195,7 @@ public: /// \return True if window has focus, false otherwise /// //////////////////////////////////////////////////////////// - bool hasFocus() const override; + [[nodiscard]] bool hasFocus() const override; protected: //////////////////////////////////////////////////////////// diff --git a/src/SFML/Window/GlContext.hpp b/src/SFML/Window/GlContext.hpp index 17669bed4..8666dca20 100644 --- a/src/SFML/Window/GlContext.hpp +++ b/src/SFML/Window/GlContext.hpp @@ -197,7 +197,7 @@ public: /// \return Structure containing the settings /// //////////////////////////////////////////////////////////// - const ContextSettings& getSettings() const; + [[nodiscard]] const ContextSettings& getSettings() const; //////////////////////////////////////////////////////////// /// \brief Activate or deactivate the context as the current target for rendering diff --git a/src/SFML/Window/JoystickManager.hpp b/src/SFML/Window/JoystickManager.hpp index 585b3ddf4..201c7b798 100644 --- a/src/SFML/Window/JoystickManager.hpp +++ b/src/SFML/Window/JoystickManager.hpp @@ -70,7 +70,7 @@ public: /// \return Capabilities of the joystick /// //////////////////////////////////////////////////////////// - const JoystickCaps& getCapabilities(unsigned int joystick) const; + [[nodiscard]] const JoystickCaps& getCapabilities(unsigned int joystick) const; //////////////////////////////////////////////////////////// /// \brief Get the current state of an open joystick @@ -80,7 +80,7 @@ public: /// \return Current state of the joystick /// //////////////////////////////////////////////////////////// - const JoystickState& getState(unsigned int joystick) const; + [[nodiscard]] const JoystickState& getState(unsigned int joystick) const; //////////////////////////////////////////////////////////// /// \brief Get the identification for an open joystick @@ -90,7 +90,7 @@ public: /// \return Identification for the joystick /// //////////////////////////////////////////////////////////// - const Joystick::Identification& getIdentification(unsigned int joystick) const; + [[nodiscard]] const Joystick::Identification& getIdentification(unsigned int joystick) const; //////////////////////////////////////////////////////////// /// \brief Update the state of all the joysticks diff --git a/src/SFML/Window/SensorManager.hpp b/src/SFML/Window/SensorManager.hpp index 7478586d0..50bc1c021 100644 --- a/src/SFML/Window/SensorManager.hpp +++ b/src/SFML/Window/SensorManager.hpp @@ -89,7 +89,7 @@ public: /// \return True if the sensor is enabled, false otherwise /// //////////////////////////////////////////////////////////// - bool isEnabled(Sensor::Type sensor) const; + [[nodiscard]] bool isEnabled(Sensor::Type sensor) const; //////////////////////////////////////////////////////////// /// \brief Get the current value of a sensor @@ -99,7 +99,7 @@ public: /// \return Current value of the sensor /// //////////////////////////////////////////////////////////// - Vector3f getValue(Sensor::Type sensor) const; + [[nodiscard]] Vector3f getValue(Sensor::Type sensor) const; //////////////////////////////////////////////////////////// /// \brief Update the state of all the sensors diff --git a/src/SFML/Window/Unix/JoystickImpl.hpp b/src/SFML/Window/Unix/JoystickImpl.hpp index 843b983c5..f2d496b99 100644 --- a/src/SFML/Window/Unix/JoystickImpl.hpp +++ b/src/SFML/Window/Unix/JoystickImpl.hpp @@ -83,7 +83,7 @@ public: /// \return Joystick capabilities /// //////////////////////////////////////////////////////////// - JoystickCaps getCapabilities() const; + [[nodiscard]] JoystickCaps getCapabilities() const; //////////////////////////////////////////////////////////// /// \brief Get the joystick identification @@ -91,7 +91,7 @@ public: /// \return Joystick identification /// //////////////////////////////////////////////////////////// - Joystick::Identification getIdentification() const; + [[nodiscard]] Joystick::Identification getIdentification() const; //////////////////////////////////////////////////////////// /// \brief Update the joystick and get its new state diff --git a/src/SFML/Window/Unix/WindowImplX11.hpp b/src/SFML/Window/Unix/WindowImplX11.hpp index b095b1cae..33222bbcf 100644 --- a/src/SFML/Window/Unix/WindowImplX11.hpp +++ b/src/SFML/Window/Unix/WindowImplX11.hpp @@ -79,7 +79,7 @@ public: /// \return Handle of the window /// //////////////////////////////////////////////////////////// - WindowHandle getNativeHandle() const override; + [[nodiscard]] WindowHandle getNativeHandle() const override; //////////////////////////////////////////////////////////// /// \brief Get the position of the window @@ -87,7 +87,7 @@ public: /// \return Position of the window, in pixels /// //////////////////////////////////////////////////////////// - Vector2i getPosition() const override; + [[nodiscard]] Vector2i getPosition() const override; //////////////////////////////////////////////////////////// /// \brief Change the position of the window on screen @@ -103,7 +103,7 @@ public: /// \return Size of the window, in pixels /// //////////////////////////////////////////////////////////// - Vector2u getSize() const override; + [[nodiscard]] Vector2u getSize() const override; //////////////////////////////////////////////////////////// /// \brief Change the size of the rendering region of the window @@ -203,7 +203,7 @@ public: /// \return True if window has focus, false otherwise /// //////////////////////////////////////////////////////////// - bool hasFocus() const override; + [[nodiscard]] bool hasFocus() const override; protected: //////////////////////////////////////////////////////////// diff --git a/src/SFML/Window/Win32/JoystickImpl.hpp b/src/SFML/Window/Win32/JoystickImpl.hpp index 649383cd4..57d7e509f 100644 --- a/src/SFML/Window/Win32/JoystickImpl.hpp +++ b/src/SFML/Window/Win32/JoystickImpl.hpp @@ -101,7 +101,7 @@ public: /// \return Joystick capabilities /// //////////////////////////////////////////////////////////// - JoystickCaps getCapabilities() const; + [[nodiscard]] JoystickCaps getCapabilities() const; //////////////////////////////////////////////////////////// /// \brief Get the joystick identification @@ -109,7 +109,7 @@ public: /// \return Joystick identification /// //////////////////////////////////////////////////////////// - Joystick::Identification getIdentification() const; + [[nodiscard]] Joystick::Identification getIdentification() const; //////////////////////////////////////////////////////////// /// \brief Update the joystick and get its new state @@ -169,7 +169,7 @@ public: /// \return Joystick capabilities /// //////////////////////////////////////////////////////////// - JoystickCaps getCapabilitiesDInput() const; + [[nodiscard]] JoystickCaps getCapabilitiesDInput() const; //////////////////////////////////////////////////////////// /// \brief Update the joystick and get its new state (DInput, Buffered) diff --git a/src/SFML/Window/Win32/WindowImplWin32.hpp b/src/SFML/Window/Win32/WindowImplWin32.hpp index 267b35b28..c7b26ae64 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.hpp +++ b/src/SFML/Window/Win32/WindowImplWin32.hpp @@ -83,7 +83,7 @@ public: /// \return Handle of the window /// //////////////////////////////////////////////////////////// - WindowHandle getNativeHandle() const override; + [[nodiscard]] WindowHandle getNativeHandle() const override; //////////////////////////////////////////////////////////// /// \brief Get the position of the window @@ -91,7 +91,7 @@ public: /// \return Position of the window, in pixels /// //////////////////////////////////////////////////////////// - Vector2i getPosition() const override; + [[nodiscard]] Vector2i getPosition() const override; //////////////////////////////////////////////////////////// /// \brief Change the position of the window on screen @@ -107,7 +107,7 @@ public: /// \return Size of the window, in pixels /// //////////////////////////////////////////////////////////// - Vector2u getSize() const override; + [[nodiscard]] Vector2u getSize() const override; //////////////////////////////////////////////////////////// /// \brief Change the size of the rendering region of the window @@ -187,7 +187,7 @@ public: /// \return True if window has focus, false otherwise /// //////////////////////////////////////////////////////////// - bool hasFocus() const override; + [[nodiscard]] bool hasFocus() const override; protected: //////////////////////////////////////////////////////////// diff --git a/src/SFML/Window/WindowImpl.hpp b/src/SFML/Window/WindowImpl.hpp index 19ae80ad9..fe2341f6f 100644 --- a/src/SFML/Window/WindowImpl.hpp +++ b/src/SFML/Window/WindowImpl.hpp @@ -151,7 +151,7 @@ public: /// \return Handle of the window /// //////////////////////////////////////////////////////////// - virtual WindowHandle getNativeHandle() const = 0; + [[nodiscard]] virtual WindowHandle getNativeHandle() const = 0; //////////////////////////////////////////////////////////// /// \brief Get the position of the window @@ -159,7 +159,7 @@ public: /// \return Position of the window, in pixels /// //////////////////////////////////////////////////////////// - virtual Vector2i getPosition() const = 0; + [[nodiscard]] virtual Vector2i getPosition() const = 0; //////////////////////////////////////////////////////////// /// \brief Get the minimum window rendering region size @@ -167,7 +167,7 @@ public: /// \return Minimum size /// //////////////////////////////////////////////////////////// - std::optional getMinimumSize() const; + [[nodiscard]] std::optional getMinimumSize() const; //////////////////////////////////////////////////////////// /// \brief Get the maximum window rendering region size @@ -175,7 +175,7 @@ public: /// \return Maximum size /// //////////////////////////////////////////////////////////// - std::optional getMaximumSize() const; + [[nodiscard]] std::optional getMaximumSize() const; //////////////////////////////////////////////////////////// /// \brief Change the position of the window on screen @@ -191,7 +191,7 @@ public: /// \return Size of the window, in pixels /// //////////////////////////////////////////////////////////// - virtual Vector2u getSize() const = 0; + [[nodiscard]] virtual Vector2u getSize() const = 0; //////////////////////////////////////////////////////////// /// \brief Change the size of the rendering region of the window @@ -291,7 +291,7 @@ public: /// \return True if window has focus, false otherwise /// //////////////////////////////////////////////////////////// - virtual bool hasFocus() const = 0; + [[nodiscard]] virtual bool hasFocus() const = 0; //////////////////////////////////////////////////////////// /// \brief Create a Vulkan rendering surface diff --git a/src/SFML/Window/iOS/JoystickImpl.hpp b/src/SFML/Window/iOS/JoystickImpl.hpp index 931715a52..27108a3d4 100644 --- a/src/SFML/Window/iOS/JoystickImpl.hpp +++ b/src/SFML/Window/iOS/JoystickImpl.hpp @@ -78,7 +78,7 @@ public: /// \return Joystick capabilities /// //////////////////////////////////////////////////////////// - JoystickCaps getCapabilities() const; + [[nodiscard]] JoystickCaps getCapabilities() const; //////////////////////////////////////////////////////////// /// \brief Get the joystick identification @@ -86,7 +86,7 @@ public: /// \return Joystick identification /// //////////////////////////////////////////////////////////// - Joystick::Identification getIdentification() const; + [[nodiscard]] Joystick::Identification getIdentification() const; //////////////////////////////////////////////////////////// /// \brief Update the joystick and get its new state diff --git a/src/SFML/Window/iOS/WindowImplUIKit.hpp b/src/SFML/Window/iOS/WindowImplUIKit.hpp index da1837451..0c94d3783 100644 --- a/src/SFML/Window/iOS/WindowImplUIKit.hpp +++ b/src/SFML/Window/iOS/WindowImplUIKit.hpp @@ -72,7 +72,7 @@ public: /// \return Handle of the window /// //////////////////////////////////////////////////////////// - WindowHandle getNativeHandle() const override; + [[nodiscard]] WindowHandle getNativeHandle() const override; //////////////////////////////////////////////////////////// /// \brief Get the position of the window @@ -80,7 +80,7 @@ public: /// \return Position of the window, in pixels /// //////////////////////////////////////////////////////////// - Vector2i getPosition() const override; + [[nodiscard]] Vector2i getPosition() const override; //////////////////////////////////////////////////////////// /// \brief Change the position of the window on screen @@ -96,7 +96,7 @@ public: /// \return Size of the window, in pixels /// //////////////////////////////////////////////////////////// - Vector2u getSize() const override; + [[nodiscard]] Vector2u getSize() const override; //////////////////////////////////////////////////////////// /// \brief Change the size of the rendering region of the window @@ -196,7 +196,7 @@ public: /// \return True if window has focus, false otherwise /// //////////////////////////////////////////////////////////// - bool hasFocus() const override; + [[nodiscard]] bool hasFocus() const override; //////////////////////////////////////////////////////////// /// \brief Notify an event @@ -212,7 +212,7 @@ public: /// \return Pointer to the window's view /// //////////////////////////////////////////////////////////// - SFView* getGlView() const; + [[nodiscard]] SFView* getGlView() const; //////////////////////////////////////////////////////////// /// \brief Show or hide the virtual keyboard diff --git a/src/SFML/Window/macOS/JoystickImpl.hpp b/src/SFML/Window/macOS/JoystickImpl.hpp index d998a1a10..a6961aab5 100644 --- a/src/SFML/Window/macOS/JoystickImpl.hpp +++ b/src/SFML/Window/macOS/JoystickImpl.hpp @@ -88,7 +88,7 @@ public: /// \return Joystick capabilities /// //////////////////////////////////////////////////////////// - JoystickCaps getCapabilities() const; + [[nodiscard]] JoystickCaps getCapabilities() const; //////////////////////////////////////////////////////////// /// \brief Get the joystick identification @@ -96,7 +96,7 @@ public: /// \return Joystick identification /// //////////////////////////////////////////////////////////// - Joystick::Identification getIdentification() const; + [[nodiscard]] Joystick::Identification getIdentification() const; //////////////////////////////////////////////////////////// /// \brief Update the joystick and get its new state diff --git a/src/SFML/Window/macOS/WindowImplCocoa.hpp b/src/SFML/Window/macOS/WindowImplCocoa.hpp index 8ac007634..f39936369 100644 --- a/src/SFML/Window/macOS/WindowImplCocoa.hpp +++ b/src/SFML/Window/macOS/WindowImplCocoa.hpp @@ -243,7 +243,7 @@ public: /// \return Handle of the window /// //////////////////////////////////////////////////////////// - WindowHandle getNativeHandle() const override; + [[nodiscard]] WindowHandle getNativeHandle() const override; //////////////////////////////////////////////////////////// /// \brief Get the position of the window @@ -251,7 +251,7 @@ public: /// \return Position of the window, in pixels /// //////////////////////////////////////////////////////////// - Vector2i getPosition() const override; + [[nodiscard]] Vector2i getPosition() const override; //////////////////////////////////////////////////////////// /// \brief Change the position of the window on screen @@ -267,7 +267,7 @@ public: /// \return Size of the window, in pixels /// //////////////////////////////////////////////////////////// - Vector2u getSize() const override; + [[nodiscard]] Vector2u getSize() const override; //////////////////////////////////////////////////////////// /// \brief Change the size of the rendering region of the window @@ -367,7 +367,7 @@ public: /// \return True if window has focus, false otherwise /// //////////////////////////////////////////////////////////// - bool hasFocus() const override; + [[nodiscard]] bool hasFocus() const override; protected: //////////////////////////////////////////////////////////// diff --git a/test/Audio/SoundSource.test.cpp b/test/Audio/SoundSource.test.cpp index 41c78fd0d..e69425756 100644 --- a/test/Audio/SoundSource.test.cpp +++ b/test/Audio/SoundSource.test.cpp @@ -22,13 +22,13 @@ class SoundSource : public sf::SoundSource { } - void* getSound() const override + [[nodiscard]] void* getSound() const override { return {}; } public: - Status getStatus() const override + [[nodiscard]] Status getStatus() const override { return {}; } diff --git a/test/System/FileInputStream.test.cpp b/test/System/FileInputStream.test.cpp index 1fb1c896a..61cc7ecd2 100644 --- a/test/System/FileInputStream.test.cpp +++ b/test/System/FileInputStream.test.cpp @@ -50,7 +50,7 @@ public: TemporaryFile& operator=(const TemporaryFile&) = delete; // Return the randomly generated path. - const std::filesystem::path& getPath() const + [[nodiscard]] const std::filesystem::path& getPath() const { return m_path; }