Skip to content

Commit

Permalink
Don't apply the MSVC workaround for clang or gcc
Browse files Browse the repository at this point in the history
Resolves hsutter#1304 
On Windows, clang defines `_MSC_VER`, so the MSVC workaround needs to not happen when the clang define is set.


Signed-off-by: gregmarr <[email protected]>
  • Loading branch information
gregmarr authored Oct 9, 2024
1 parent 97ba0be commit 5aa7759
Showing 1 changed file with 12 additions and 79 deletions.
91 changes: 12 additions & 79 deletions include/cpp2util.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ constexpr auto gcc_clang_msvc_min_versions(
}


#if defined(_MSC_VER)
#if defined(_MSC_VER) && !defined(__clang_major__) && !defined(__GNUC__)
// MSVC can't handle 'inline constexpr' variables yet in all cases
#define CPP2_CONSTEXPR const
#else
Expand Down Expand Up @@ -2601,7 +2601,7 @@ range(
) -> range<std::common_type_t<T, U>>;

template<typename T>
constexpr auto contains(range<T> const& r, auto const& t)
constexpr auto contains(range<T> const& r, T const& t)
-> bool
{
if (r.empty()) {
Expand Down Expand Up @@ -2711,64 +2711,6 @@ inline auto fopen( const char* filename, const char* mode ) {




//-----------------------------------------------------------------------
//
// "Unchecked" opt-outs for safety checks
//
//-----------------------------------------------------------------------
//

CPP2_FORCE_INLINE constexpr auto unchecked_cmp_less(auto&& t, auto&& u)
-> decltype(auto)
requires requires {CPP2_FORWARD(t) < CPP2_FORWARD(u);}
{
return CPP2_FORWARD(t) < CPP2_FORWARD(u);
}

CPP2_FORCE_INLINE constexpr auto unchecked_cmp_less_eq(auto&& t, auto&& u)
-> decltype(auto)
requires requires {CPP2_FORWARD(t) <= CPP2_FORWARD(u);}
{
return CPP2_FORWARD(t) <= CPP2_FORWARD(u);
}

CPP2_FORCE_INLINE constexpr auto unchecked_cmp_greater(auto&& t, auto&& u)
-> decltype(auto)
requires requires {CPP2_FORWARD(t) > CPP2_FORWARD(u);}
{
return CPP2_FORWARD(t) > CPP2_FORWARD(u);
}

CPP2_FORCE_INLINE constexpr auto unchecked_cmp_greater_eq(auto&& t, auto&& u)
-> decltype(auto)
requires requires {CPP2_FORWARD(t) >= CPP2_FORWARD(u);}
{
return CPP2_FORWARD(t) >= CPP2_FORWARD(u);
}

CPP2_FORCE_INLINE constexpr auto unchecked_div(auto&& t, auto&& u)
-> decltype(auto)
requires requires {CPP2_FORWARD(t) / CPP2_FORWARD(u);}
{
return CPP2_FORWARD(t) / CPP2_FORWARD(u);
}

CPP2_FORCE_INLINE constexpr auto unchecked_dereference(auto&& p)
-> decltype(auto)
requires requires {*CPP2_FORWARD(p);}
{
return *CPP2_FORWARD(p);
}

CPP2_FORCE_INLINE constexpr auto unchecked_subscript(auto&& a, auto&& b)
-> decltype(auto)
requires requires {CPP2_FORWARD(a)[b];}
{
return CPP2_FORWARD(a)[b];
}


namespace impl {

//-----------------------------------------------------------------------
Expand All @@ -2787,8 +2729,7 @@ CPP2_FORCE_INLINE constexpr auto cmp_mixed_signedness_check() -> void
{
static_assert(
program_violates_type_safety_guarantee<T, U>,
"comparing bool values using < <= >= > is unsafe and not allowed - are you missing parentheses?"
);
"comparing bool values using < <= >= > is unsafe and not allowed - are you missing parentheses?");
}
else if constexpr (
std::is_integral_v<T> &&
Expand All @@ -2804,22 +2745,20 @@ CPP2_FORCE_INLINE constexpr auto cmp_mixed_signedness_check() -> void
// static_assert to reject the comparison is the right way to go.
static_assert(
program_violates_type_safety_guarantee<T, U>,
"mixed signed/unsigned comparison is unsafe - prefer using .ssize() instead of .size(), consider using std::cmp_less or similar instead, or consider explicitly casting one of the values to change signedness by using 'as' or 'cpp2::unchecked_narrow'"
"mixed signed/unsigned comparison is unsafe - prefer using .ssize() instead of .size(), consider using std::cmp_less instead, or consider explicitly casting one of the values to change signedness by using 'as' or 'cpp2::unchecked_narrow'"
);
}
}


CPP2_FORCE_INLINE constexpr auto cmp_less(auto&& t, auto&& u)
-> decltype(auto)
CPP2_FORCE_INLINE constexpr auto cmp_less(auto&& t, auto&& u) -> decltype(auto)
requires requires {CPP2_FORWARD(t) < CPP2_FORWARD(u);}
{
cmp_mixed_signedness_check<CPP2_TYPEOF(t), CPP2_TYPEOF(u)>();
return CPP2_FORWARD(t) < CPP2_FORWARD(u);
}

CPP2_FORCE_INLINE constexpr auto cmp_less(auto&& t, auto&& u)
-> decltype(auto)
CPP2_FORCE_INLINE constexpr auto cmp_less(auto&& t, auto&& u) -> decltype(auto)
{
static_assert(
program_violates_type_safety_guarantee<decltype(t), decltype(u)>,
Expand All @@ -2829,16 +2768,14 @@ CPP2_FORCE_INLINE constexpr auto cmp_less(auto&& t, auto&& u)
}


CPP2_FORCE_INLINE constexpr auto cmp_less_eq(auto&& t, auto&& u)
-> decltype(auto)
CPP2_FORCE_INLINE constexpr auto cmp_less_eq(auto&& t, auto&& u) -> decltype(auto)
requires requires {CPP2_FORWARD(t) <= CPP2_FORWARD(u);}
{
cmp_mixed_signedness_check<CPP2_TYPEOF(t), CPP2_TYPEOF(u)>();
return CPP2_FORWARD(t) <= CPP2_FORWARD(u);
}

CPP2_FORCE_INLINE constexpr auto cmp_less_eq(auto&& t, auto&& u)
-> decltype(auto)
CPP2_FORCE_INLINE constexpr auto cmp_less_eq(auto&& t, auto&& u) -> decltype(auto)
{
static_assert(
program_violates_type_safety_guarantee<decltype(t), decltype(u)>,
Expand All @@ -2848,16 +2785,14 @@ CPP2_FORCE_INLINE constexpr auto cmp_less_eq(auto&& t, auto&& u)
}


CPP2_FORCE_INLINE constexpr auto cmp_greater(auto&& t, auto&& u)
-> decltype(auto)
CPP2_FORCE_INLINE constexpr auto cmp_greater(auto&& t, auto&& u) -> decltype(auto)
requires requires {CPP2_FORWARD(t) > CPP2_FORWARD(u);}
{
cmp_mixed_signedness_check<CPP2_TYPEOF(t), CPP2_TYPEOF(u)>();
return CPP2_FORWARD(t) > CPP2_FORWARD(u);
}

CPP2_FORCE_INLINE constexpr auto cmp_greater(auto&& t, auto&& u)
-> decltype(auto)
CPP2_FORCE_INLINE constexpr auto cmp_greater(auto&& t, auto&& u) -> decltype(auto)
{
static_assert(
program_violates_type_safety_guarantee<decltype(t), decltype(u)>,
Expand All @@ -2867,16 +2802,14 @@ CPP2_FORCE_INLINE constexpr auto cmp_greater(auto&& t, auto&& u)
}


CPP2_FORCE_INLINE constexpr auto cmp_greater_eq(auto&& t, auto&& u)
-> decltype(auto)
CPP2_FORCE_INLINE constexpr auto cmp_greater_eq(auto&& t, auto&& u) -> decltype(auto)
requires requires {CPP2_FORWARD(t) >= CPP2_FORWARD(u);}
{
cmp_mixed_signedness_check<CPP2_TYPEOF(t), CPP2_TYPEOF(u)>();
return CPP2_FORWARD(t) >= CPP2_FORWARD(u);
}

CPP2_FORCE_INLINE constexpr auto cmp_greater_eq(auto&& t, auto&& u)
-> decltype(auto)
CPP2_FORCE_INLINE constexpr auto cmp_greater_eq(auto&& t, auto&& u) -> decltype(auto)
{
static_assert(
program_violates_type_safety_guarantee<decltype(t), decltype(u)>,
Expand Down

0 comments on commit 5aa7759

Please sign in to comment.