From 07f5cb24f1d75aad6c27eafd83863a78a37f16cb Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 27 Jul 2020 22:40:16 -0700 Subject: [PATCH] [clang-tidy] use nodiscard (#234) Found with modernize-use-nodiscard Signed-off-by: Rosen Penev --- include/cxxopts.hpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/include/cxxopts.hpp b/include/cxxopts.hpp index dade761..ae95343 100644 --- a/include/cxxopts.hpp +++ b/include/cxxopts.hpp @@ -45,6 +45,12 @@ THE SOFTWARE. #define CXXOPTS_HAS_OPTIONAL #endif +#if __cplusplus >= 201603L +#define CXXOPTS_NODISCARD [[nodiscard]] +#else +#define CXXOPTS_NODISCARD +#endif + #ifndef CXXOPTS_VECTOR_DELIMITER #define CXXOPTS_VECTOR_DELIMITER ',' #endif @@ -330,6 +336,7 @@ namespace cxxopts { } + CXXOPTS_NODISCARD const char* what() const noexcept override { @@ -933,6 +940,7 @@ namespace cxxopts public: using abstract_value::abstract_value; + CXXOPTS_NODISCARD std::shared_ptr clone() const { @@ -1019,28 +1027,34 @@ namespace cxxopts OptionDetails(OptionDetails&& rhs) = default; + CXXOPTS_NODISCARD const String& description() const { return m_desc; } - const Value& value() const { + CXXOPTS_NODISCARD + const Value& + value() const { return *m_value; } + CXXOPTS_NODISCARD std::shared_ptr make_storage() const { return m_value->clone(); } + CXXOPTS_NODISCARD const std::string& short_name() const { return m_short; } + CXXOPTS_NODISCARD const std::string& long_name() const { @@ -1101,6 +1115,7 @@ namespace cxxopts m_value->parse(); } + CXXOPTS_NODISCARD size_t count() const noexcept { @@ -1108,6 +1123,7 @@ namespace cxxopts } // TODO: maybe default options should count towards the number of arguments + CXXOPTS_NODISCARD bool has_default() const noexcept { @@ -1157,15 +1173,15 @@ namespace cxxopts { } - const - std::string& + CXXOPTS_NODISCARD + const std::string& key() const { return m_key; } - const - std::string& + CXXOPTS_NODISCARD + const std::string& value() const { return m_value;