Commit c6fd8f4d8330cb3c6b3e549e599c2eff25560fd7
Committed by
Henry Schreiner
1 parent
1286a122
A few warning fixes
Showing
2 changed files
with
11 additions
and
9 deletions
include/CLI/App.hpp
| @@ -1511,13 +1511,13 @@ inline std::string simple(const App *app, const Error &e) { | @@ -1511,13 +1511,13 @@ inline std::string simple(const App *app, const Error &e) { | ||
| 1511 | if(app->get_help_ptr() != nullptr) | 1511 | if(app->get_help_ptr() != nullptr) |
| 1512 | header += "Run with " + app->get_help_ptr()->single_name() + " for more information.\n"; | 1512 | header += "Run with " + app->get_help_ptr()->single_name() + " for more information.\n"; |
| 1513 | return header; | 1513 | return header; |
| 1514 | -}; | 1514 | +} |
| 1515 | 1515 | ||
| 1516 | inline std::string help(const App *app, const Error &e) { | 1516 | inline std::string help(const App *app, const Error &e) { |
| 1517 | std::string header = std::string("ERROR: ") + e.get_name() + ": " + e.what() + "\n"; | 1517 | std::string header = std::string("ERROR: ") + e.get_name() + ": " + e.what() + "\n"; |
| 1518 | header += app->help(); | 1518 | header += app->help(); |
| 1519 | return header; | 1519 | return header; |
| 1520 | -}; | 1520 | +} |
| 1521 | 1521 | ||
| 1522 | } // namespace FailureMessage | 1522 | } // namespace FailureMessage |
| 1523 | 1523 |
include/CLI/Error.hpp
| @@ -6,23 +6,25 @@ | @@ -6,23 +6,25 @@ | ||
| 6 | #include <exception> | 6 | #include <exception> |
| 7 | #include <stdexcept> | 7 | #include <stdexcept> |
| 8 | #include <string> | 8 | #include <string> |
| 9 | +#include <utility> | ||
| 10 | + | ||
| 11 | +namespace CLI { | ||
| 9 | 12 | ||
| 10 | // Use one of these on all error classes | 13 | // Use one of these on all error classes |
| 11 | #define CLI11_ERROR_DEF(parent, name) \ | 14 | #define CLI11_ERROR_DEF(parent, name) \ |
| 12 | protected: \ | 15 | protected: \ |
| 13 | - name(std::string name, std::string msg, int exit_code) : parent(name, msg, exit_code) {} \ | ||
| 14 | - name(std::string name, std::string msg, ExitCodes exit_code) : parent(name, msg, exit_code) {} \ | 16 | + name(std::string name, std::string msg, int exit_code) : parent(std::move(name), std::move(msg), exit_code) {} \ |
| 17 | + name(std::string name, std::string msg, ExitCodes exit_code) \ | ||
| 18 | + : parent(std::move(name), std::move(msg), exit_code) {} \ | ||
| 15 | \ | 19 | \ |
| 16 | public: \ | 20 | public: \ |
| 17 | - name(std::string msg, ExitCodes exit_code) : parent(#name, msg, exit_code) {} \ | ||
| 18 | - name(std::string msg, int exit_code) : parent(#name, msg, exit_code) {} | 21 | + name(std::string msg, ExitCodes exit_code) : parent(#name, std::move(msg), exit_code) {} \ |
| 22 | + name(std::string msg, int exit_code) : parent(#name, std::move(msg), exit_code) {} | ||
| 19 | 23 | ||
| 20 | // This is added after the one above if a class is used directly and builds its own message | 24 | // This is added after the one above if a class is used directly and builds its own message |
| 21 | #define CLI11_ERROR_SIMPLE(name) \ | 25 | #define CLI11_ERROR_SIMPLE(name) \ |
| 22 | name(std::string msg) : name(#name, msg, ExitCodes::name) {} | 26 | name(std::string msg) : name(#name, msg, ExitCodes::name) {} |
| 23 | 27 | ||
| 24 | -namespace CLI { | ||
| 25 | - | ||
| 26 | /// These codes are part of every error in CLI. They can be obtained from e using e.exit_code or as a quick shortcut, | 28 | /// These codes are part of every error in CLI. They can be obtained from e using e.exit_code or as a quick shortcut, |
| 27 | /// int values from e.get_error_code(). | 29 | /// int values from e.get_error_code(). |
| 28 | enum class ExitCodes { | 30 | enum class ExitCodes { |
| @@ -63,7 +65,7 @@ class Error : public std::runtime_error { | @@ -63,7 +65,7 @@ class Error : public std::runtime_error { | ||
| 63 | std::string get_name() const { return name; } | 65 | std::string get_name() const { return name; } |
| 64 | 66 | ||
| 65 | Error(std::string name, std::string msg, int exit_code = static_cast<int>(ExitCodes::BaseClass)) | 67 | Error(std::string name, std::string msg, int exit_code = static_cast<int>(ExitCodes::BaseClass)) |
| 66 | - : runtime_error(msg), exit_code(exit_code), name(name) {} | 68 | + : runtime_error(msg), exit_code(exit_code), name(std::move(name)) {} |
| 67 | 69 | ||
| 68 | Error(std::string name, std::string msg, ExitCodes exit_code) : Error(name, msg, static_cast<int>(exit_code)) {} | 70 | Error(std::string name, std::string msg, ExitCodes exit_code) : Error(name, msg, static_cast<int>(exit_code)) {} |
| 69 | }; | 71 | }; |