Skip to content

Commit

Permalink
Resolve build issues for NVHPC (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
mingxwa authored Oct 22, 2024
1 parent 2330bbf commit 2d8bcb8
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 18 deletions.
16 changes: 9 additions & 7 deletions proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,13 +463,16 @@ consteval bool is_reflection_type_well_formed() {
}
return false;
}
struct empty_proxy_base {};
template <class F, class... Cs>
struct facade_conv_traits_impl : inapplicable_traits {};
template <class F, class... Cs> requires(conv_traits<Cs>::applicable && ...)
struct facade_conv_traits_impl<F, Cs...> : applicable_traits {
using conv_meta = composite_meta<typename conv_traits<Cs>::meta...>;
using indirect_accessor = composite_accessor<false, F, Cs...>;
using direct_accessor = composite_accessor<true, F, Cs...>;
using base = std::conditional_t<std::is_same_v<direct_accessor,
composite_accessor_impl<>>, empty_proxy_base, direct_accessor>;

template <class P>
static constexpr bool conv_applicable_ptr =
Expand Down Expand Up @@ -616,7 +619,7 @@ concept proxiable = facade<F> && sizeof(P) <= F::constraints.max_size &&
details::facade_traits<F>::template refl_applicable_ptr<P>;

template <class F>
class proxy : public details::facade_traits<F>::direct_accessor {
class proxy : public details::facade_traits<F>::base {
static_assert(facade<F>);
friend struct details::proxy_helper<F>;
using _Traits = details::facade_traits<F>;
Expand Down Expand Up @@ -1171,14 +1174,13 @@ struct facade_impl {
}
template <class F>
struct upward_conversion_dispatch {
using Base = proxy<F>;
template <class T>
Base operator()(T&& value)
noexcept(std::is_nothrow_convertible_v<T, Base>)
requires(std::is_convertible_v<T, Base>)
{ return static_cast<Base>(std::forward<T>(value)); }
proxy<F> operator()(T&& value)
noexcept(std::is_nothrow_convertible_v<T, proxy<F>>)
requires(std::is_convertible_v<T, proxy<F>>)
{ return static_cast<proxy<F>>(std::forward<T>(value)); }
___PRO_DEF_MEM_ACCESSOR_TEMPLATE(
___PRO_DEF_UPWARD_CONVERSION_ACCESSOR, operator Base)
___PRO_DEF_UPWARD_CONVERSION_ACCESSOR, operator proxy<F>)
};
#undef ___PRO_DEF_UPWARD_CONVERSION_ACCESSOR

Expand Down
4 changes: 2 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions tests/proxy_creation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,25 @@ struct TestMemFn0 : pro::facade_builder
::build {};
struct TestMemFn0_Normal { void MemFn0(int) noexcept {} };
static_assert(pro::proxiable<TestMemFn0_Normal*, TestMemFn0>);
#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<TestMemFn0_Unsupproted*, TestMemFn0>);
struct TestMemFn0_MissingNoexcept { void MemFn0(int) {} };
static_assert(!pro::proxiable<TestMemFn0_MissingNoexcept*, TestMemFn0>);
struct TestMemFn0_ArgumentConvertible { void MemFn0(std::int64_t&&) noexcept {} };
static_assert(pro::proxiable<TestMemFn0_ArgumentConvertible*, TestMemFn0>);
#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<TestMemFn0_ArgumentNotMatch*, TestMemFn0>);
struct TestMemFn0_ReturnTypeNotMatch { std::string MemFn0(int) noexcept { return {}; } };
static_assert(pro::proxiable<TestMemFn0_ReturnTypeNotMatch*, TestMemFn0>);
Expand Down
4 changes: 2 additions & 2 deletions tests/proxy_lifetime_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ TEST(ProxyLifetimeTests, Test_DirectConvension_Lvalue) {
{
pro::proxy<TestFacade> p{ std::in_place_type<utils::LifetimeTracker::Session>, &tracker };
expected_ops.emplace_back(1, utils::LifetimeOperationType::kValueConstruction);
auto session = static_cast<utils::LifetimeTracker::Session>(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");
Expand All @@ -996,7 +996,7 @@ TEST(ProxyLifetimeTests, Test_DirectConvension_Rvalue) {
{
pro::proxy<TestFacade> p{ std::in_place_type<utils::LifetimeTracker::Session>, &tracker };
expected_ops.emplace_back(1, utils::LifetimeOperationType::kValueConstruction);
auto session = static_cast<utils::LifetimeTracker::Session>(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);
Expand Down
29 changes: 22 additions & 7 deletions tests/proxy_traits_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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*),
Expand All @@ -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<BadFacade_MissingConventionTypes>);
Expand Down Expand Up @@ -242,7 +246,13 @@ static_assert(!pro::facade<BadFacade_MissingConstraints>);
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<BadFacade_BadConstraints_UnexpectedType>);

Expand Down Expand Up @@ -275,21 +285,24 @@ static_assert(!pro::facade<BadFacade_BadConstraints_BadSize>);
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<BadFacade_BadConstraints_NotConstant>);
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*),
Expand All @@ -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<BadFacade_MissingReflectionTypes>);
Expand Down

0 comments on commit 2d8bcb8

Please sign in to comment.