From a20ace20fc4df8849b35744cbb71c1d117a11d04 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 9 Apr 2022 13:25:55 -0700 Subject: [PATCH] clang-tidy: manual clang-tidy fixes clang-tidy has issues applying these. Signed-off-by: Rosen Penev --- include/exiv2/bmffimage.hpp | 2 +- include/exiv2/slice.hpp | 34 +++++++++++++++++----------------- include/exiv2/value.hpp | 3 +-- src/crwimage_int.hpp | 10 ++++------ src/image_int.hpp | 2 +- src/pngchunk_int.hpp | 1 - src/tiffcomposite_int.hpp | 28 ++++++++++++++-------------- src/tiffimage_int.hpp | 7 +++---- 8 files changed, 41 insertions(+), 46 deletions(-) diff --git a/include/exiv2/bmffimage.hpp b/include/exiv2/bmffimage.hpp index 94984a9e..26e9f93b 100644 --- a/include/exiv2/bmffimage.hpp +++ b/include/exiv2/bmffimage.hpp @@ -123,7 +123,7 @@ class EXIV2API BmffImage : public Image { @warning This function should only be called by readMetadata() */ long boxHandler(std::ostream& out, Exiv2::PrintStructureOption option, const long pbox_end, int depth); - [[nodiscard]] std::string indent(int i) const { + [[nodiscard]] static std::string indent(int i) { return std::string(2 * i, ' '); } diff --git a/include/exiv2/slice.hpp b/include/exiv2/slice.hpp index 2068339f..5cca6364 100644 --- a/include/exiv2/slice.hpp +++ b/include/exiv2/slice.hpp @@ -109,14 +109,14 @@ struct ConstSliceBase : SliceBase { /*! * Obtain a constant iterator to the first element in the slice. */ - const_iterator cbegin() const noexcept { + [[nodiscard]] const_iterator cbegin() const noexcept { return storage_.unsafeGetIteratorAt(begin_); } /*! * Obtain a constant iterator to the first beyond the slice. */ - const_iterator cend() const noexcept { + [[nodiscard]] const_iterator cend() const noexcept { return storage_.unsafeGetIteratorAt(end_); } @@ -129,7 +129,7 @@ struct ConstSliceBase : SliceBase { * mutable_slice_base. */ template - slice_type subSlice(size_t begin, size_t end) const { + [[nodiscard]] slice_type subSlice(size_t begin, size_t end) const { this->rangeCheck(begin); // end == size() is a legal value, since end is the first // element beyond the slice @@ -219,8 +219,8 @@ struct MutableSliceBase : public ConstSliceBase { * the appropriate `slice` and call its `subSlice() const`, * which returns the correct type. */ - ConstSliceBase to_const_base() const noexcept { - return ConstSliceBase(this->storage_.data_, this->begin_, this->end_); + [[nodiscard]] ConstSliceBase to_const_base() const noexcept { + return {this->storage_.data_, this->begin_, this->end_}; } using base_type = ConstSliceBase; @@ -281,11 +281,11 @@ struct ContainerStorage { * * @throw whatever container::at() throws */ - const value_type& unsafeAt(size_t index) const { + [[nodiscard]] const value_type& unsafeAt(size_t index) const { return data_.at(index); } - value_type& unsafeAt(size_t index) { + [[nodiscard]] value_type& unsafeAt(size_t index) { return data_.at(index); } @@ -295,19 +295,19 @@ struct ContainerStorage { * * @throw whatever container::begin() and std::advance() throw */ - iterator unsafeGetIteratorAt(size_t index) { + [[nodiscard]] iterator unsafeGetIteratorAt(size_t index) { // we are screwed if the container got changed => try to catch it assert(index <= data_.size()); - iterator it = data_.begin(); + auto it = data_.begin(); std::advance(it, index); return it; } - const_iterator unsafeGetIteratorAt(size_t index) const { + [[nodiscard]] const_iterator unsafeGetIteratorAt(size_t index) const { assert(index <= data_.size()); - const_iterator it = data_.begin(); + auto it = data_.begin(); std::advance(it, index); return it; } @@ -346,11 +346,11 @@ struct PtrSliceStorage { * * @throw nothing */ - value_type& unsafeAt(size_t index) noexcept { + [[nodiscard]] value_type& unsafeAt(size_t index) noexcept { return data_[index]; } - const value_type& unsafeAt(size_t index) const noexcept { + [[nodiscard]] const value_type& unsafeAt(size_t index) const noexcept { return data_[index]; } @@ -360,11 +360,11 @@ struct PtrSliceStorage { * * @throw nothing */ - iterator unsafeGetIteratorAt(size_t index) noexcept { + [[nodiscard]] iterator unsafeGetIteratorAt(size_t index) noexcept { return data_ + index; } - const_iterator unsafeGetIteratorAt(size_t index) const noexcept { + [[nodiscard]] const_iterator unsafeGetIteratorAt(size_t index) const noexcept { return data_ + index; } @@ -462,7 +462,7 @@ struct Slice : public Internal::MutableSliceBase subSlice(size_t begin, size_t end) const { + [[nodiscard]] Slice subSlice(size_t begin, size_t end) const { return this->to_const_base().template subSlice>(begin, end); } }; @@ -534,7 +534,7 @@ struct Slice : public Internal::MutableSliceBase::template subSlice>(begin, end); } - Slice subSlice(size_t begin, size_t end) const { + [[nodiscard]] Slice subSlice(size_t begin, size_t end) const { return this->to_const_base().template subSlice>(begin, end); } }; diff --git a/include/exiv2/value.hpp b/include/exiv2/value.hpp index d7081a0c..df4742c5 100644 --- a/include/exiv2/value.hpp +++ b/include/exiv2/value.hpp @@ -1251,9 +1251,8 @@ class ValueType : public Value { if (static_cast(std::numeric_limits::min()) <= v && v <= static_cast(std::numeric_limits::max())) { return static_cast(std::round(v)); - } else { - return 0; } + return 0; } //! Utility for toInt64, toUint32, etc. diff --git a/src/crwimage_int.hpp b/src/crwimage_int.hpp index 621ad74c..4c09abf8 100644 --- a/src/crwimage_int.hpp +++ b/src/crwimage_int.hpp @@ -371,13 +371,12 @@ class CiffDirectory : public CiffComponent { void doPrint(std::ostream& os, ByteOrder byteOrder, const std::string& prefix) const override; //! See base class comment. A directory is empty if it has no components. - bool doEmpty() const override; + [[nodiscard]] bool doEmpty() const override; // See base class comment [[nodiscard]] CiffComponent* doFindComponent(uint16_t crwTagId, uint16_t crwDir) const override; //@} - private: // DATA Components components_; //!< List of components in this dir UniquePtr m_; // used by recursive doAdd @@ -495,14 +494,14 @@ struct CrwMapping { //@{ //! Default constructor CrwMapping(uint16_t crwTagId, uint16_t crwDir, uint32_t size, uint16_t tag, Internal::IfdId ifdId, - const CrwDecodeFct& toExif, const CrwEncodeFct& fromExif) : + CrwDecodeFct toExif, CrwEncodeFct fromExif) : crwTagId_(crwTagId), crwDir_(crwDir), size_(size), tag_(tag), ifdId_(ifdId), - toExif_(toExif), - fromExif_(fromExif) { + toExif_(std::move(toExif)), + fromExif_(std::move(fromExif)) { } //@} @@ -633,7 +632,6 @@ class CrwMap { //! Encode the thumbnail image static void encode0x2008(const Image& image, const CrwMapping* pCrwMapping, CiffHeader* pHead); - private: // DATA static const CrwMapping crwMapping_[]; //!< Metadata conversion table static const CrwSubDir crwSubDir_[]; //!< Ciff directory hierarchy diff --git a/src/image_int.hpp b/src/image_int.hpp index 1a2fd759..0bf2a8b6 100644 --- a/src/image_int.hpp +++ b/src/image_int.hpp @@ -48,7 +48,7 @@ struct binaryToStringHelper; template std::ostream& operator<<(std::ostream& stream, const binaryToStringHelper& binToStr) { for (size_t i = 0; i < binToStr.buf_.size(); ++i) { - int c = static_cast(binToStr.buf_.at(i)); + auto c = static_cast(binToStr.buf_.at(i)); const bool bTrailingNull = c == 0 && i == binToStr.buf_.size() - 1; if (!bTrailingNull) { if (c < ' ' || c >= 127) { diff --git a/src/pngchunk_int.hpp b/src/pngchunk_int.hpp index d41c68fb..1553758e 100644 --- a/src/pngchunk_int.hpp +++ b/src/pngchunk_int.hpp @@ -25,7 +25,6 @@ class PngChunk { */ enum TxtChunkType { tEXt_Chunk = 0, zTXt_Chunk = 1, iTXt_Chunk = 2 }; - public: /*! @brief Decode PNG IHDR chunk data from a data buffer \em data and return image size to \em outWidth and \em outHeight. diff --git a/src/tiffcomposite_int.hpp b/src/tiffcomposite_int.hpp index b33ba33e..8f2003ef 100644 --- a/src/tiffcomposite_int.hpp +++ b/src/tiffcomposite_int.hpp @@ -1101,6 +1101,20 @@ class TiffIfdMakernote : public TiffComponent { ~TiffIfdMakernote() override; //@} + /*! + @name NOT implemented + + Implementing the copy constructor and assignment operator will require + cloning the header, i.e., clone() functionality on the MnHeader + hierarchy. + */ + //@{ + //! Copy constructor. + TiffIfdMakernote(const TiffIfdMakernote&) = delete; + //! Assignment operator. + TiffIfdMakernote& operator=(const TiffIfdMakernote&) = delete; + //@} + //! @name Manipulators //@{ /*! @@ -1213,20 +1227,6 @@ class TiffIfdMakernote : public TiffComponent { [[nodiscard]] size_t doSizeImage() const override; //@} - /*! - @name NOT implemented - - Implementing the copy constructor and assignment operator will require - cloning the header, i.e., clone() functionality on the MnHeader - hierarchy. - */ - //@{ - //! Copy constructor. - TiffIfdMakernote(const TiffIfdMakernote&) = delete; - //! Assignment operator. - TiffIfdMakernote& operator=(const TiffIfdMakernote&) = delete; - //@} - private: // DATA MnHeader* pHeader_; //!< Makernote header diff --git a/src/tiffimage_int.hpp b/src/tiffimage_int.hpp index 6381512d..4ca1d0f5 100644 --- a/src/tiffimage_int.hpp +++ b/src/tiffimage_int.hpp @@ -115,7 +115,7 @@ class TiffHeader : public TiffHeaderBase { //! @name Creators //@{ //! Default constructor - TiffHeader(ByteOrder byteOrder = littleEndian, uint32_t offset = 0x00000008, bool hasImageTags = true); + explicit TiffHeader(ByteOrder byteOrder = littleEndian, uint32_t offset = 0x00000008, bool hasImageTags = true); //! Destructor ~TiffHeader() override = default; //@} @@ -371,13 +371,12 @@ class OffsetWriter { //! Data structure for the offset list. struct OffsetData { //! Default constructor - OffsetData() { - } + OffsetData() = default; //! Constructor OffsetData(uint32_t origin, ByteOrder byteOrder) : origin_(origin), byteOrder_(byteOrder) { } // DATA - uint32_t origin_{0}; //!< Origin address + uint32_t origin_{}; //!< Origin address uint32_t target_{}; //!< Target address ByteOrder byteOrder_{littleEndian}; //!< Byte order to use to encode target address };