From c6fd8f4d8330cb3c6b3e549e599c2eff25560fd7 Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Wed, 22 Nov 2017 22:23:09 -0500 Subject: [PATCH] A few warning fixes --- include/CLI/App.hpp | 4 ++-- include/CLI/Error.hpp | 16 +++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/CLI/App.hpp b/include/CLI/App.hpp index db144319..3b653086 100644 --- a/include/CLI/App.hpp +++ b/include/CLI/App.hpp @@ -1511,13 +1511,13 @@ inline std::string simple(const App *app, const Error &e) { if(app->get_help_ptr() != nullptr) header += "Run with " + app->get_help_ptr()->single_name() + " for more information.\n"; return header; -}; +} inline std::string help(const App *app, const Error &e) { std::string header = std::string("ERROR: ") + e.get_name() + ": " + e.what() + "\n"; header += app->help(); return header; -}; +} } // namespace FailureMessage diff --git a/include/CLI/Error.hpp b/include/CLI/Error.hpp index 22a6f564..3e9f3b57 100644 --- a/include/CLI/Error.hpp +++ b/include/CLI/Error.hpp @@ -6,23 +6,25 @@ #include #include #include +#include + +namespace CLI { // Use one of these on all error classes #define CLI11_ERROR_DEF(parent, name) \ protected: \ - name(std::string name, std::string msg, int exit_code) : parent(name, msg, exit_code) {} \ - name(std::string name, std::string msg, ExitCodes exit_code) : parent(name, msg, exit_code) {} \ + name(std::string name, std::string msg, int exit_code) : parent(std::move(name), std::move(msg), exit_code) {} \ + name(std::string name, std::string msg, ExitCodes exit_code) \ + : parent(std::move(name), std::move(msg), exit_code) {} \ \ public: \ - name(std::string msg, ExitCodes exit_code) : parent(#name, msg, exit_code) {} \ - name(std::string msg, int exit_code) : parent(#name, msg, exit_code) {} + name(std::string msg, ExitCodes exit_code) : parent(#name, std::move(msg), exit_code) {} \ + name(std::string msg, int exit_code) : parent(#name, std::move(msg), exit_code) {} // This is added after the one above if a class is used directly and builds its own message #define CLI11_ERROR_SIMPLE(name) \ name(std::string msg) : name(#name, msg, ExitCodes::name) {} -namespace CLI { - /// These codes are part of every error in CLI. They can be obtained from e using e.exit_code or as a quick shortcut, /// int values from e.get_error_code(). enum class ExitCodes { @@ -63,7 +65,7 @@ class Error : public std::runtime_error { std::string get_name() const { return name; } Error(std::string name, std::string msg, int exit_code = static_cast(ExitCodes::BaseClass)) - : runtime_error(msg), exit_code(exit_code), name(name) {} + : runtime_error(msg), exit_code(exit_code), name(std::move(name)) {} Error(std::string name, std::string msg, ExitCodes exit_code) : Error(name, msg, static_cast(exit_code)) {} };