diff --git a/proxy.h b/proxy.h index 97b77c1..0623c2d 100644 --- a/proxy.h +++ b/proxy.h @@ -463,6 +463,7 @@ consteval bool is_reflection_type_well_formed() { } return false; } +struct empty_proxy_base {}; template struct facade_conv_traits_impl : inapplicable_traits {}; template requires(conv_traits::applicable && ...) @@ -470,6 +471,8 @@ struct facade_conv_traits_impl : applicable_traits { using conv_meta = composite_meta::meta...>; using indirect_accessor = composite_accessor; using direct_accessor = composite_accessor; + using base = std::conditional_t>, empty_proxy_base, direct_accessor>; template static constexpr bool conv_applicable_ptr = @@ -616,7 +619,7 @@ concept proxiable = facade && sizeof(P) <= F::constraints.max_size && details::facade_traits::template refl_applicable_ptr

; template -class proxy : public details::facade_traits::direct_accessor { +class proxy : public details::facade_traits::base { static_assert(facade); friend struct details::proxy_helper; using _Traits = details::facade_traits; @@ -1171,14 +1174,13 @@ struct facade_impl { } template struct upward_conversion_dispatch { - using Base = proxy; template - Base operator()(T&& value) - noexcept(std::is_nothrow_convertible_v) - requires(std::is_convertible_v) - { return static_cast(std::forward(value)); } + proxy operator()(T&& value) + noexcept(std::is_nothrow_convertible_v>) + requires(std::is_convertible_v>) + { return static_cast>(std::forward(value)); } ___PRO_DEF_MEM_ACCESSOR_TEMPLATE( - ___PRO_DEF_UPWARD_CONVERSION_ACCESSOR, operator Base) + ___PRO_DEF_UPWARD_CONVERSION_ACCESSOR, operator proxy) }; #undef ___PRO_DEF_UPWARD_CONVERSION_ACCESSOR diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1c4d552..2bdfb5b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -29,7 +29,7 @@ target_include_directories(msft_proxy_tests PRIVATE .) target_link_libraries(msft_proxy_tests PRIVATE msft_proxy) target_link_libraries(msft_proxy_tests PRIVATE gtest_main) -if (MSVC) +if(MSVC) target_compile_options(msft_proxy_tests PRIVATE /W4 /WX) else() target_compile_options(msft_proxy_tests PRIVATE -Wall -Wextra -Wpedantic -Werror) @@ -38,7 +38,7 @@ endif() include(GoogleTest) gtest_discover_tests(msft_proxy_tests) -if(NOT MSVC) +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") add_executable(msft_proxy_freestanding_tests freestanding/proxy_freestanding_tests.cpp) target_include_directories(msft_proxy_freestanding_tests PRIVATE .) target_compile_features(msft_proxy_freestanding_tests PRIVATE cxx_std_20) diff --git a/tests/proxy_creation_tests.cpp b/tests/proxy_creation_tests.cpp index 41688d4..a7d2d59 100644 --- a/tests/proxy_creation_tests.cpp +++ b/tests/proxy_creation_tests.cpp @@ -46,13 +46,25 @@ struct TestMemFn0 : pro::facade_builder ::build {}; struct TestMemFn0_Normal { void MemFn0(int) noexcept {} }; static_assert(pro::proxiable); +#ifdef __NVCOMPILER +#pragma diag_suppress declared_but_not_referenced +#endif // __NVCOMPILER struct TestMemFn0_Unsupproted { void MemFn1(int) noexcept {} }; +#ifdef __NVCOMPILER +#pragma diag_default declared_but_not_referenced +#endif // __NVCOMPILER static_assert(!pro::proxiable); struct TestMemFn0_MissingNoexcept { void MemFn0(int) {} }; static_assert(!pro::proxiable); struct TestMemFn0_ArgumentConvertible { void MemFn0(std::int64_t&&) noexcept {} }; static_assert(pro::proxiable); +#ifdef __NVCOMPILER +#pragma diag_suppress declared_but_not_referenced +#endif // __NVCOMPILER struct TestMemFn0_ArgumentNotMatch { void MemFn0(int&) noexcept {} }; +#ifdef __NVCOMPILER +#pragma diag_default declared_but_not_referenced +#endif // __NVCOMPILER static_assert(!pro::proxiable); struct TestMemFn0_ReturnTypeNotMatch { std::string MemFn0(int) noexcept { return {}; } }; static_assert(pro::proxiable); diff --git a/tests/proxy_lifetime_tests.cpp b/tests/proxy_lifetime_tests.cpp index e77b0d7..8351c3c 100644 --- a/tests/proxy_lifetime_tests.cpp +++ b/tests/proxy_lifetime_tests.cpp @@ -978,7 +978,7 @@ TEST(ProxyLifetimeTests, Test_DirectConvension_Lvalue) { { pro::proxy p{ std::in_place_type, &tracker }; expected_ops.emplace_back(1, utils::LifetimeOperationType::kValueConstruction); - auto session = static_cast(p); + auto session = utils::LifetimeTracker::Session{p}; ASSERT_TRUE(p.has_value()); ASSERT_EQ(ToString(*p), "Session 1"); ASSERT_EQ(to_string(session), "Session 2"); @@ -996,7 +996,7 @@ TEST(ProxyLifetimeTests, Test_DirectConvension_Rvalue) { { pro::proxy p{ std::in_place_type, &tracker }; expected_ops.emplace_back(1, utils::LifetimeOperationType::kValueConstruction); - auto session = static_cast(std::move(p)); + auto session = utils::LifetimeTracker::Session{std::move(p)}; ASSERT_FALSE(p.has_value()); ASSERT_EQ(to_string(session), "Session 2"); expected_ops.emplace_back(2, utils::LifetimeOperationType::kMoveConstruction); diff --git a/tests/proxy_traits_tests.cpp b/tests/proxy_traits_tests.cpp index 4eba588..6008e09 100644 --- a/tests/proxy_traits_tests.cpp +++ b/tests/proxy_traits_tests.cpp @@ -199,6 +199,8 @@ struct BadFacade_MissingConventionTypes { #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-const-variable" +#elif defined(__NVCOMPILER) +#pragma diag_suppress declared_but_not_referenced #endif // __clang__ static constexpr auto constraints = pro::proxiable_ptr_constraints{ .max_size = 2 * sizeof(void*), @@ -209,6 +211,8 @@ struct BadFacade_MissingConventionTypes { }; #ifdef __clang__ #pragma clang diagnostic pop +#elif defined(__NVCOMPILER) +#pragma diag_default declared_but_not_referenced #endif // __clang__ }; static_assert(!pro::facade); @@ -242,7 +246,13 @@ static_assert(!pro::facade); struct BadFacade_BadConstraints_UnexpectedType { using convention_types = std::tuple<>; using reflection_types = std::tuple<>; +#ifdef __NVCOMPILER +#pragma diag_suppress declared_but_not_referenced +#endif // __NVCOMPILER static constexpr auto constraints = 0; +#ifdef __NVCOMPILER +#pragma diag_default declared_but_not_referenced +#endif // __NVCOMPILER }; static_assert(!pro::facade); @@ -275,21 +285,24 @@ static_assert(!pro::facade); struct BadFacade_BadConstraints_NotConstant { using convention_types = std::tuple<>; using reflection_types = std::tuple<>; - static inline const auto constraints = pro::proxiable_ptr_constraints{ - .max_size = 2 * sizeof(void*), - .max_align = alignof(void*), - .copyability = pro::constraint_level::none, - .relocatability = pro::constraint_level::nothrow, - .destructibility = pro::constraint_level::nothrow, - }; + static const pro::proxiable_ptr_constraints constraints; }; static_assert(!pro::facade); +const pro::proxiable_ptr_constraints BadFacade_BadConstraints_NotConstant::constraints{ + .max_size = 2 * sizeof(void*), + .max_align = alignof(void*), + .copyability = pro::constraint_level::none, + .relocatability = pro::constraint_level::nothrow, + .destructibility = pro::constraint_level::nothrow, +}; struct BadFacade_MissingReflectionTypes { using convention_types = std::tuple<>; #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-const-variable" +#elif defined(__NVCOMPILER) +#pragma diag_suppress declared_but_not_referenced #endif // __clang__ static constexpr auto constraints = pro::proxiable_ptr_constraints{ .max_size = 2 * sizeof(void*), @@ -300,6 +313,8 @@ struct BadFacade_MissingReflectionTypes { }; #ifdef __clang__ #pragma clang diagnostic pop +#elif defined(__NVCOMPILER) +#pragma diag_default declared_but_not_referenced #endif // __clang__ }; static_assert(!pro::facade);