diff --git a/include/components/config_parser.hpp b/include/components/config_parser.hpp index 68f343a8..2fc38a19 100644 --- a/include/components/config_parser.hpp +++ b/include/components/config_parser.hpp @@ -88,6 +88,11 @@ struct line_t { class config_parser { public: config_parser(const logger& logger, string&& file, string&& bar); + /** + * This prevents passing a temporary logger to the constructor because that would be UB, as the temporary would be + * destroyed once the constructor returns. + */ + config_parser(logger&& logger, string&& file, string&& bar) = delete; /** * \brief Performs the parsing of the main config file m_file diff --git a/tests/unit_tests/components/config_parser.cpp b/tests/unit_tests/components/config_parser.cpp index 5aa7c43e..921815bb 100644 --- a/tests/unit_tests/components/config_parser.cpp +++ b/tests/unit_tests/components/config_parser.cpp @@ -33,8 +33,8 @@ class TestableConfigParser : public config_parser { */ class ConfigParser : public ::testing::Test { protected: - unique_ptr parser = - make_unique(logger(loglevel::NONE), "/dev/zero", "TEST"); + const logger l = logger(loglevel::NONE); + unique_ptr parser = make_unique(l, "/dev/zero", "TEST"); }; // ParseLineTest {{{