Commit 07f5cb24f1d75aad6c27eafd83863a78a37f16cb
Committed by
GitHub
1 parent
5f43f4cb
[clang-tidy] use nodiscard (#234)
Found with modernize-use-nodiscard Signed-off-by: Rosen Penev <rosenp@gmail.com>
Showing
1 changed file
with
21 additions
and
5 deletions
include/cxxopts.hpp
| @@ -45,6 +45,12 @@ THE SOFTWARE. | @@ -45,6 +45,12 @@ THE SOFTWARE. | ||
| 45 | #define CXXOPTS_HAS_OPTIONAL | 45 | #define CXXOPTS_HAS_OPTIONAL |
| 46 | #endif | 46 | #endif |
| 47 | 47 | ||
| 48 | +#if __cplusplus >= 201603L | ||
| 49 | +#define CXXOPTS_NODISCARD [[nodiscard]] | ||
| 50 | +#else | ||
| 51 | +#define CXXOPTS_NODISCARD | ||
| 52 | +#endif | ||
| 53 | + | ||
| 48 | #ifndef CXXOPTS_VECTOR_DELIMITER | 54 | #ifndef CXXOPTS_VECTOR_DELIMITER |
| 49 | #define CXXOPTS_VECTOR_DELIMITER ',' | 55 | #define CXXOPTS_VECTOR_DELIMITER ',' |
| 50 | #endif | 56 | #endif |
| @@ -330,6 +336,7 @@ namespace cxxopts | @@ -330,6 +336,7 @@ namespace cxxopts | ||
| 330 | { | 336 | { |
| 331 | } | 337 | } |
| 332 | 338 | ||
| 339 | + CXXOPTS_NODISCARD | ||
| 333 | const char* | 340 | const char* |
| 334 | what() const noexcept override | 341 | what() const noexcept override |
| 335 | { | 342 | { |
| @@ -933,6 +940,7 @@ namespace cxxopts | @@ -933,6 +940,7 @@ namespace cxxopts | ||
| 933 | public: | 940 | public: |
| 934 | using abstract_value<T>::abstract_value; | 941 | using abstract_value<T>::abstract_value; |
| 935 | 942 | ||
| 943 | + CXXOPTS_NODISCARD | ||
| 936 | std::shared_ptr<Value> | 944 | std::shared_ptr<Value> |
| 937 | clone() const | 945 | clone() const |
| 938 | { | 946 | { |
| @@ -1019,28 +1027,34 @@ namespace cxxopts | @@ -1019,28 +1027,34 @@ namespace cxxopts | ||
| 1019 | 1027 | ||
| 1020 | OptionDetails(OptionDetails&& rhs) = default; | 1028 | OptionDetails(OptionDetails&& rhs) = default; |
| 1021 | 1029 | ||
| 1030 | + CXXOPTS_NODISCARD | ||
| 1022 | const String& | 1031 | const String& |
| 1023 | description() const | 1032 | description() const |
| 1024 | { | 1033 | { |
| 1025 | return m_desc; | 1034 | return m_desc; |
| 1026 | } | 1035 | } |
| 1027 | 1036 | ||
| 1028 | - const Value& value() const { | 1037 | + CXXOPTS_NODISCARD |
| 1038 | + const Value& | ||
| 1039 | + value() const { | ||
| 1029 | return *m_value; | 1040 | return *m_value; |
| 1030 | } | 1041 | } |
| 1031 | 1042 | ||
| 1043 | + CXXOPTS_NODISCARD | ||
| 1032 | std::shared_ptr<Value> | 1044 | std::shared_ptr<Value> |
| 1033 | make_storage() const | 1045 | make_storage() const |
| 1034 | { | 1046 | { |
| 1035 | return m_value->clone(); | 1047 | return m_value->clone(); |
| 1036 | } | 1048 | } |
| 1037 | 1049 | ||
| 1050 | + CXXOPTS_NODISCARD | ||
| 1038 | const std::string& | 1051 | const std::string& |
| 1039 | short_name() const | 1052 | short_name() const |
| 1040 | { | 1053 | { |
| 1041 | return m_short; | 1054 | return m_short; |
| 1042 | } | 1055 | } |
| 1043 | 1056 | ||
| 1057 | + CXXOPTS_NODISCARD | ||
| 1044 | const std::string& | 1058 | const std::string& |
| 1045 | long_name() const | 1059 | long_name() const |
| 1046 | { | 1060 | { |
| @@ -1101,6 +1115,7 @@ namespace cxxopts | @@ -1101,6 +1115,7 @@ namespace cxxopts | ||
| 1101 | m_value->parse(); | 1115 | m_value->parse(); |
| 1102 | } | 1116 | } |
| 1103 | 1117 | ||
| 1118 | + CXXOPTS_NODISCARD | ||
| 1104 | size_t | 1119 | size_t |
| 1105 | count() const noexcept | 1120 | count() const noexcept |
| 1106 | { | 1121 | { |
| @@ -1108,6 +1123,7 @@ namespace cxxopts | @@ -1108,6 +1123,7 @@ namespace cxxopts | ||
| 1108 | } | 1123 | } |
| 1109 | 1124 | ||
| 1110 | // TODO: maybe default options should count towards the number of arguments | 1125 | // TODO: maybe default options should count towards the number of arguments |
| 1126 | + CXXOPTS_NODISCARD | ||
| 1111 | bool | 1127 | bool |
| 1112 | has_default() const noexcept | 1128 | has_default() const noexcept |
| 1113 | { | 1129 | { |
| @@ -1157,15 +1173,15 @@ namespace cxxopts | @@ -1157,15 +1173,15 @@ namespace cxxopts | ||
| 1157 | { | 1173 | { |
| 1158 | } | 1174 | } |
| 1159 | 1175 | ||
| 1160 | - const | ||
| 1161 | - std::string& | 1176 | + CXXOPTS_NODISCARD |
| 1177 | + const std::string& | ||
| 1162 | key() const | 1178 | key() const |
| 1163 | { | 1179 | { |
| 1164 | return m_key; | 1180 | return m_key; |
| 1165 | } | 1181 | } |
| 1166 | 1182 | ||
| 1167 | - const | ||
| 1168 | - std::string& | 1183 | + CXXOPTS_NODISCARD |
| 1184 | + const std::string& | ||
| 1169 | value() const | 1185 | value() const |
| 1170 | { | 1186 | { |
| 1171 | return m_value; | 1187 | return m_value; |