From 2834fa5f05eac155b8083fea638631b926fa64b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20D=C3=ADaz=20M=C3=A1s?= Date: Mon, 7 Mar 2022 19:12:01 +0100 Subject: [PATCH] Use [[maybe_unused]] --- samples/geotag.cpp | 1 - samples/xmpsample.cpp | 21 +++++++-------------- src/CMakeLists.txt | 1 - src/bmffimage.cpp | 1 - src/convert.cpp | 1 - src/crwimage_int.cpp | 7 ++----- src/preview.cpp | 1 - src/types.cpp | 1 - src/unused.h | 8 -------- src/value.cpp | 4 +--- 10 files changed, 10 insertions(+), 36 deletions(-) delete mode 100644 src/unused.h diff --git a/samples/geotag.cpp b/samples/geotag.cpp index 2a18be4f..8351b91e 100644 --- a/samples/geotag.cpp +++ b/samples/geotag.cpp @@ -22,7 +22,6 @@ // g++ geotag.cpp -o geotag -lexiv2 -lexpat #include -#include "unused.h" #include #include diff --git a/samples/xmpsample.cpp b/samples/xmpsample.cpp index 2b57ca01..173e9eb6 100644 --- a/samples/xmpsample.cpp +++ b/samples/xmpsample.cpp @@ -21,7 +21,6 @@ // Sample/test for high level XMP classes. See also addmoddel.cpp #include -#include "unused.h" #include #include @@ -77,26 +76,22 @@ try { assert(xmpData["Xmp.dc.one"].toInt64() == -1); assert(xmpData["Xmp.dc.one"].value().ok()); - const Exiv2::Value &getv1 = xmpData["Xmp.dc.one"].value(); - UNUSED(getv1); + [[maybe_unused]] const Exiv2::Value &getv1 = xmpData["Xmp.dc.one"].value(); assert(isEqual(getv1.toFloat(), -1)); assert(getv1.ok()); assert(getv1.toRational() == Exiv2::Rational(-1, 1)); assert(getv1.ok()); - const Exiv2::Value &getv2 = xmpData["Xmp.dc.two"].value(); - UNUSED(getv2); + [[maybe_unused]] const Exiv2::Value &getv2 = xmpData["Xmp.dc.two"].value(); assert(isEqual(getv2.toFloat(), 3.1415f)); assert(getv2.ok()); assert(getv2.toInt64() == 3); assert(getv2.ok()); - Exiv2::Rational R = getv2.toRational(); - UNUSED(R); + [[maybe_unused]] Exiv2::Rational R = getv2.toRational(); assert(getv2.ok()); assert(isEqual(static_cast(R.first) / R.second, 3.1415f )); - const Exiv2::Value &getv3 = xmpData["Xmp.dc.three"].value(); - UNUSED(getv3); + [[maybe_unused]] const Exiv2::Value &getv3 = xmpData["Xmp.dc.three"].value(); assert(isEqual(getv3.toFloat(), 5.0f/7.0f)); assert(getv3.ok()); assert(getv3.toInt64() == 0); // long(5.0 / 7.0) @@ -104,10 +99,9 @@ try { assert(getv3.toRational() == Exiv2::Rational(5, 7)); assert(getv3.ok()); - const Exiv2::Value &getv6 = xmpData["Xmp.dc.six"].value(); - UNUSED(getv6); + [[maybe_unused]] const Exiv2::Value &getv6 = xmpData["Xmp.dc.six"].value(); assert(getv6.toInt64() == 0); - assert(getv6.ok()); + assert(getv6.ok()^); assert(getv6.toFloat() == 0.0f); assert(getv6.ok()); assert(getv6.toRational() == Exiv2::Rational(0, 1)); @@ -117,8 +111,7 @@ try { getv7.toInt64(); // this should fail assert(!getv7.ok()); - const Exiv2::Value &getv8 = xmpData["Xmp.dc.eight"].value(); - UNUSED(getv8); + [[maybe_unused]] const Exiv2::Value &getv8 = xmpData["Xmp.dc.eight"].value(); assert(getv8.toInt64() == 1); assert(getv8.ok()); assert(getv8.toFloat() == 1.0f); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6b4a8587..405f13e0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -34,7 +34,6 @@ add_library( exiv2lib_int OBJECT tiffimage_int.cpp tiffimage_int.hpp tiffvisitor_int.cpp tiffvisitor_int.hpp tifffwd_int.hpp - unused.h utils.hpp utils.cpp ) diff --git a/src/bmffimage.cpp b/src/bmffimage.cpp index 61f92dda..5d20eb4e 100644 --- a/src/bmffimage.cpp +++ b/src/bmffimage.cpp @@ -14,7 +14,6 @@ #include "tiffimage.hpp" #include "tiffimage_int.hpp" #include "types.hpp" -#include "unused.h" // + standard includes #include diff --git a/src/convert.cpp b/src/convert.cpp index 0c5224ab..1ae175ad 100644 --- a/src/convert.cpp +++ b/src/convert.cpp @@ -16,7 +16,6 @@ #include "xmp_exiv2.hpp" #include "futils.hpp" #include "convert.hpp" -#include "unused.h" // + standard includes #include diff --git a/src/crwimage_int.cpp b/src/crwimage_int.cpp index 7d9274ce..b2cf42e2 100644 --- a/src/crwimage_int.cpp +++ b/src/crwimage_int.cpp @@ -3,7 +3,6 @@ #include "crwimage_int.hpp" #include "canonmn_int.hpp" #include "i18n.h" // NLS support. -#include "unused.h" #include "error.hpp" #include "enforce.hpp" @@ -592,8 +591,7 @@ namespace Exiv2::Internal { { CrwDirs crwDirs; CrwMap::loadStack(crwDirs, crwDir); - uint16_t rootDirectory = crwDirs.top().crwDir_; - UNUSED(rootDirectory); + [[maybe_unused]] uint16_t rootDirectory = crwDirs.top().crwDir_; assert(rootDirectory == 0x0000); crwDirs.pop(); if (!pRootDir_) { @@ -671,8 +669,7 @@ namespace Exiv2::Internal { if (pRootDir_) { CrwDirs crwDirs; CrwMap::loadStack(crwDirs, crwDir); - uint16_t rootDirectory = crwDirs.top().crwDir_; - UNUSED(rootDirectory); + [[maybe_unused]] uint16_t rootDirectory = crwDirs.top().crwDir_; assert(rootDirectory == 0x0000); crwDirs.pop(); pRootDir_->remove(crwDirs, crwTagId); diff --git a/src/preview.cpp b/src/preview.cpp index 44c79751..e885960c 100644 --- a/src/preview.cpp +++ b/src/preview.cpp @@ -18,7 +18,6 @@ #include "jpgimage.hpp" #include "tiffimage.hpp" #include "tiffimage_int.hpp" -#include "unused.h" // ***************************************************************************** namespace { diff --git a/src/types.cpp b/src/types.cpp index 97e65b37..1dd66936 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -6,7 +6,6 @@ #include "futils.hpp" #include "i18n.h" // for _exvGettext #include "safe_op.hpp" -#include "unused.h" // + standard includes #include diff --git a/src/unused.h b/src/unused.h deleted file mode 100644 index fd2fc86e..00000000 --- a/src/unused.h +++ /dev/null @@ -1,8 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later - -#ifndef UNUSED_H -#define UNUSED_H - -#define UNUSED(x) (void)(x) - -#endif // UNUSED_H diff --git a/src/value.cpp b/src/value.cpp index b7edb3b3..cf61b351 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -6,7 +6,6 @@ #include "enforce.hpp" #include "error.hpp" #include "convert.hpp" -#include "unused.h" // + standard includes #include @@ -451,8 +450,7 @@ namespace Exiv2 { std::string c = value_; if (charsetId() == unicode) { c = value_.substr(8); - const size_t sz = c.size(); - UNUSED(sz); + [[maybe_unused]] const size_t sz = c.size(); if (byteOrder_ == littleEndian && byteOrder == bigEndian) { convertStringCharset(c, "UCS-2LE", "UCS-2BE"); assert(c.size() == sz);