diff --git a/include/boost/redis/config.hpp b/include/boost/redis/config.hpp index 98bb7624..d23fc404 100644 --- a/include/boost/redis/config.hpp +++ b/include/boost/redis/config.hpp @@ -162,7 +162,7 @@ struct config { * * UNIX domain sockets can't be used with Sentinel. */ - std::string unix_socket; + std::string unix_socket{}; /** @brief (Deprecated) Username used for authentication during connection establishment. * @@ -212,7 +212,7 @@ struct config { * cfg.setup.hello("my_username", "my_password"); * @endcode */ - std::string password; + std::string password{}; /** @brief (Deprecated) Client name parameter to use during connection establishment. * diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 385914b6..9631a701 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -52,6 +52,7 @@ boost_redis_make_test(test_generic_flat_response) boost_redis_make_test(test_read_buffer) boost_redis_make_test(test_subscription_tracker) boost_redis_make_test(test_push_parser) +boost_redis_make_test(test_config) # Tests that require a real Redis server if (BOOST_REDIS_INTEGRATION_TESTS) diff --git a/test/Jamfile b/test/Jamfile index 3ddb1be7..91e1529c 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -91,6 +91,7 @@ local tests = test_read_buffer test_subscription_tracker test_push_parser + test_config ; # Build and run the tests diff --git a/test/test_config.cpp b/test/test_config.cpp new file mode 100644 index 00000000..a43982c1 --- /dev/null +++ b/test/test_config.cpp @@ -0,0 +1,55 @@ +// +// Copyright (c) 2025 Marcelo Zimbres Silva (mzimbres@gmail.com), +// Ruben Perez Hidalgo (rubenperez038 at gmail dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#include + +#include + +#if !defined(__cpp_designated_initializers) || (__cpp_designated_initializers < 201707L) + +#include + +BOOST_PRAGMA_MESSAGE("test_config skipped because designated initializers are not supported"); + +int main() { } + +#else + +#include + +using namespace boost::redis; + +namespace { + +// A config object can be created using designated initializers. +// No initializer is missing +void test_designated_initializers_config() +{ + // Most members have initializers + config cfg1{ + .addr = {"127.0.0.1", "2000"}, + .use_setup = true, + }; + + // The ones included above have, too + config cfg2{.unix_socket = "/tmp/sock"}; + + // Sentinel config has them, too + sentinel_config sent_cfg{.addresses = {{"127.0.0.1", "1000"}}}; +} + +} // namespace + +int main() +{ + test_designated_initializers_config(); + + return boost::report_errors(); +} + +#endif