From 4ab435502731af80726733e20f85f6b3f31015c8 Mon Sep 17 00:00:00 2001 From: sha512sum Date: Thu, 27 Jun 2024 02:14:54 +0000 Subject: [PATCH] Fixes compiler warnings --- CMakeLists.txt | 13 +++++++++- include/cserver/engine/components.hpp | 12 ++++++---- tests/dependencies.cpp | 34 +++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 tests/dependencies.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0cd5883..ae04bb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ target_include_directories( $) target_link_libraries(cserver INTERFACE utempl::utempl ${Boost_LIBRARIES} llhttp ${OPENSSL_LIBRARIES} ) -target_compile_features(cserver INTERFACE cxx_std_20) +target_compile_features(cserver INTERFACE cxx_std_23) install(TARGETS cserver EXPORT cserverTargets @@ -53,3 +53,14 @@ install(FILES "${PROJECT_BINARY_DIR}/cserverConfig.cmake" install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/cserver DESTINATION include) +if(ENABLE_TESTS) + find_package(GTest REQUIRED) + enable_testing() + file(GLOB SOURCES tests/* tests/*/* tests/*/*/*) + add_executable(cserver_tests ${SOURCES}) + target_link_libraries(cserver_tests GTest::gtest_main cserver) + set_property(TARGET cserver_tests PROPERTY CXX_STANDARD 23) + include(GoogleTest) + gtest_discover_tests(cserver_tests) +endif() + diff --git a/include/cserver/engine/components.hpp b/include/cserver/engine/components.hpp index d667b21..907d9a1 100644 --- a/include/cserver/engine/components.hpp +++ b/include/cserver/engine/components.hpp @@ -196,10 +196,14 @@ private: template static consteval auto FindComponentTypeImpl(ComponentConfig...) { if constexpr(static_cast(name) == kBasicTaskProcessorName) { - return [] -> engine::basic::TaskProcessor() - 1> {}(); + return [&] -> engine::basic::TaskProcessor() - 1> { + std::unreachable(); + }(); } else { constexpr auto I = utempl::Find(utempl::Tuple{std::string_view{names}...}, std::string_view{name}); - return [] -> decltype(utempl::Get(utempl::TypeList{})) {}(); + return [&] -> decltype(utempl::Get(utempl::TypeList{})) { + std::unreachable(); + }(); }; }; public: @@ -225,7 +229,7 @@ public: name >{} > - static constexpr auto FindComponent() -> FindComponentType&; + static auto FindComponent() -> FindComponentType&; template < @@ -240,7 +244,7 @@ public: FindComponentName >{} > - static constexpr auto FindComponent() -> T&; + static auto FindComponent() -> T&; template static consteval auto GetDependencies() { diff --git a/tests/dependencies.cpp b/tests/dependencies.cpp new file mode 100644 index 0000000..b6e1d5c --- /dev/null +++ b/tests/dependencies.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +struct SomeComponent { + static constexpr utempl::ConstexprString kName = "some"; + constexpr SomeComponent(auto, auto&) {}; +}; + + +struct SomeOtherComponent { + SomeComponent& component; + static constexpr utempl::ConstexprString kName = "other"; + constexpr SomeOtherComponent(auto, auto& context) : component(context.template FindComponent<"some">()) { + }; +}; + + +TEST(Dependencies, Get) { + constexpr auto dependencies = cserver::ServiceContextBuilder{} + .Append() + .Append() + .Sort() + .GetDependencyGraph(); + using Need = const cserver::DependencyGraph< + cserver::DependencyGraphElement< + utempl::ConstexprString{"some"}, + utempl::Tuple{}>, + cserver::DependencyGraphElement< + utempl::ConstexprString{"other"}, + utempl::Tuple{utempl::ConstexprString{"some"}}>>; + EXPECT_EQ(boost::typeindex::type_id().pretty_name(), + boost::typeindex::type_id().pretty_name()); +};