Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions tests/std/include/is_permissive.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#pragma once

#include <yvals_core.h>

namespace detail {
constexpr bool permissive() {
return false;
}

template <class>
struct PermissiveTestBase {
static constexpr bool permissive() {
return true;
}
};

template <class T>
struct PermissiveTest : PermissiveTestBase<T> {
static constexpr bool test() {
return permissive();
}
};
} // namespace detail

template <class T>
_INLINE_VAR constexpr bool is_permissive_v = detail::PermissiveTest<T>::test();

_INLINE_VAR constexpr bool is_permissive = is_permissive_v<int>;
23 changes: 2 additions & 21 deletions tests/std/include/range_algorithm_support.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,15 @@
#include <type_traits>
#include <utility>

#include <is_permissive.hpp>

#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)

namespace ranges = std::ranges;

template <class>
inline constexpr bool always_false = false;

namespace detail {
constexpr bool permissive() {
return false;
}

template <class>
struct DependentBase {
static constexpr bool permissive() {
return true;
}
};

template <class T>
struct Derived : DependentBase<T> {
static constexpr bool test() {
return permissive();
}
};
} // namespace detail
constexpr bool is_permissive = detail::Derived<int>::test();

template <class T>
inline constexpr T* nullptr_to = nullptr;

Expand Down
42 changes: 11 additions & 31 deletions tests/std/include/test_mdspan_support.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <utility>
#include <vector>

#include <is_permissive.hpp>

enum class IsExplicit : bool { no, yes };
enum class IsNothrow : bool { no, yes };

Expand Down Expand Up @@ -173,7 +175,7 @@ constexpr bool check_accessor_policy_requirements() {
return true;
}

namespace details {
namespace detail {
template <size_t... Extents, class Fn>
constexpr void check_members_with_mixed_extents(Fn&& fn) {
auto select_extent = [](size_t e) consteval {
Expand Down Expand Up @@ -221,41 +223,19 @@ namespace details {
static_assert(sizeof...(Seq) <= 16, "We don't need more testing.");
}
}
} // namespace details
} // namespace detail

template <class Fn>
constexpr void check_members_with_various_extents(Fn&& fn) {
details::check_members_with_various_extents_impl(std::forward<Fn>(fn), std::make_index_sequence<1>{});
details::check_members_with_various_extents_impl(std::forward<Fn>(fn), std::make_index_sequence<2>{});
details::check_members_with_various_extents_impl(std::forward<Fn>(fn), std::make_index_sequence<4>{});
details::check_members_with_various_extents_impl(std::forward<Fn>(fn), std::make_index_sequence<8>{});
detail::check_members_with_various_extents_impl(std::forward<Fn>(fn), std::make_index_sequence<1>{});
detail::check_members_with_various_extents_impl(std::forward<Fn>(fn), std::make_index_sequence<2>{});
detail::check_members_with_various_extents_impl(std::forward<Fn>(fn), std::make_index_sequence<4>{});
detail::check_members_with_various_extents_impl(std::forward<Fn>(fn), std::make_index_sequence<8>{});
if (!std::is_constant_evaluated()) {
details::check_members_with_various_extents_impl(std::forward<Fn>(fn), std::make_index_sequence<16>{});
detail::check_members_with_various_extents_impl(std::forward<Fn>(fn), std::make_index_sequence<16>{});
}
}

namespace details {
constexpr bool permissive() {
return false;
}

template <class>
struct PermissiveTestBase {
static constexpr bool permissive() {
return true;
}
};

template <class T>
struct PermissiveTest : PermissiveTestBase<T> {
static constexpr bool test() {
return permissive();
}
};
} // namespace details

inline constexpr bool is_permissive = details::PermissiveTest<int>::test();

template <class Mapping>
struct MappingProperties {
Mapping::index_type req_span_size;
Expand All @@ -265,7 +245,7 @@ struct MappingProperties {
};

template <class Mapping>
requires (!details::PermissiveTest<Mapping>::test())
requires (!is_permissive_v<Mapping>)
MappingProperties<Mapping> get_mapping_properties(const Mapping& mapping) {
using IndexType = Mapping::index_type;
constexpr auto rank = Mapping::extents_type::rank();
Expand Down Expand Up @@ -327,7 +307,7 @@ MappingProperties<Mapping> get_mapping_properties(const Mapping& mapping) {
}

template <class Mapping>
requires (details::PermissiveTest<Mapping>::test())
requires (is_permissive_v<Mapping>)
constexpr MappingProperties<Mapping> get_mapping_properties(const Mapping&) {
return {}; // we cannot get properties in '/permissive' mode
}
23 changes: 2 additions & 21 deletions tests/std/tests/P0645R10_text_formatting_args/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <type_traits>
#include <variant>

#include <is_permissive.hpp>

using namespace std;

template <class CharType>
Expand Down Expand Up @@ -265,27 +267,6 @@ void test_lvalue_only_visitation() {
visit_format_arg(lvalue_only_visitor{}, basic_format_arg<Context>{});
}

namespace detail {
constexpr bool permissive() {
return false;
}

template <class>
struct DependentBase {
static constexpr bool permissive() {
return true;
}
};

template <class T>
struct Derived : DependentBase<T> {
static constexpr bool test() {
return permissive();
}
};
} // namespace detail
constexpr bool is_permissive = detail::Derived<int>::test();

template <class Context, class... Args>
concept CanMakeFormatArgs = requires(Args&&... args) { make_format_args<Context>(static_cast<Args&&>(args)...); };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,14 @@
#include <type_traits>
#include <utility>

#include <is_permissive.hpp>

#pragma warning(disable : 4793) // function compiled as native: non-clrcall vcall thunks must be compiled as native

#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)

namespace ranges = std::ranges;

namespace detail {
constexpr bool permissive() {
return false;
}

template <class>
struct DependentBase {
static constexpr bool permissive() {
return true;
}
};

template <class T>
struct Derived : DependentBase<T> {
static constexpr bool test() {
return permissive();
}
};
} // namespace detail
constexpr bool is_permissive = detail::Derived<int>::test();

template <bool>
struct borrowed { // borrowed<true> is a borrowed_range; borrowed<false> is not
int* begin() const;
Expand Down
23 changes: 2 additions & 21 deletions tests/std/tests/P0898R3_concepts/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <type_traits>
#include <utility>

#include <is_permissive.hpp>

#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)

template <class, class = void>
Expand All @@ -32,27 +34,6 @@ constexpr bool is_trait<T, std::void_t<typename T::type>> = true;
template <class>
constexpr bool always_false = false;

namespace detail {
constexpr bool permissive() {
return false;
}

template <class>
struct DependentBase {
static constexpr bool permissive() {
return true;
}
};

template <class T>
struct Derived : DependentBase<T> {
static constexpr bool test() {
return permissive();
}
};
} // namespace detail
constexpr bool is_permissive = detail::Derived<int>::test();

struct IncompleteClass;
union IncompleteUnion;

Expand Down
24 changes: 2 additions & 22 deletions tests/std/tests/P2136R3_invoke_r/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,12 @@
#include <string>
#include <type_traits>

#include <is_permissive.hpp>

#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)

using namespace std;

// TRANSITION, DevCom-1457457
namespace detail {
constexpr bool permissive() {
return false;
}

template <class>
struct DependentBase {
static constexpr bool permissive() {
return true;
}
};

template <class T>
struct Derived : DependentBase<T> {
static constexpr bool test() {
return permissive();
}
};
} // namespace detail
constexpr bool is_permissive = detail::Derived<int>::test();

constexpr int square(int n) {
return n * n;
}
Expand Down
23 changes: 2 additions & 21 deletions tests/std/tests/VSO_0000000_type_traits/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <type_traits>
#include <utility>

#include <is_permissive.hpp>

using namespace std;

#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
Expand Down Expand Up @@ -1268,27 +1270,6 @@ namespace {
template <class T>
constexpr bool is_trait<T, void_t<typename T::type>> = true;

namespace detail {
constexpr bool permissive() {
return false;
}

template <class>
struct DependentBase {
static constexpr bool permissive() {
return true;
}
};

template <class T>
struct Derived : DependentBase<T> {
static constexpr bool test() {
return permissive();
}
};
} // namespace detail
constexpr bool is_permissive = detail::Derived<int>::test();

struct move_only {
move_only() = default;
move_only(move_only&&) = default;
Expand Down