Skip to content

Commit 5aa7759

Browse files
authored
Don't apply the MSVC workaround for clang or gcc
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]>
1 parent 97ba0be commit 5aa7759

File tree

1 file changed

+12
-79
lines changed

1 file changed

+12
-79
lines changed

include/cpp2util.h

Lines changed: 12 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ constexpr auto gcc_clang_msvc_min_versions(
368368
}
369369

370370

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

26032603
template<typename T>
2604-
constexpr auto contains(range<T> const& r, auto const& t)
2604+
constexpr auto contains(range<T> const& r, T const& t)
26052605
-> bool
26062606
{
26072607
if (r.empty()) {
@@ -2711,64 +2711,6 @@ inline auto fopen( const char* filename, const char* mode ) {
27112711

27122712

27132713

2714-
2715-
//-----------------------------------------------------------------------
2716-
//
2717-
// "Unchecked" opt-outs for safety checks
2718-
//
2719-
//-----------------------------------------------------------------------
2720-
//
2721-
2722-
CPP2_FORCE_INLINE constexpr auto unchecked_cmp_less(auto&& t, auto&& u)
2723-
-> decltype(auto)
2724-
requires requires {CPP2_FORWARD(t) < CPP2_FORWARD(u);}
2725-
{
2726-
return CPP2_FORWARD(t) < CPP2_FORWARD(u);
2727-
}
2728-
2729-
CPP2_FORCE_INLINE constexpr auto unchecked_cmp_less_eq(auto&& t, auto&& u)
2730-
-> decltype(auto)
2731-
requires requires {CPP2_FORWARD(t) <= CPP2_FORWARD(u);}
2732-
{
2733-
return CPP2_FORWARD(t) <= CPP2_FORWARD(u);
2734-
}
2735-
2736-
CPP2_FORCE_INLINE constexpr auto unchecked_cmp_greater(auto&& t, auto&& u)
2737-
-> decltype(auto)
2738-
requires requires {CPP2_FORWARD(t) > CPP2_FORWARD(u);}
2739-
{
2740-
return CPP2_FORWARD(t) > CPP2_FORWARD(u);
2741-
}
2742-
2743-
CPP2_FORCE_INLINE constexpr auto unchecked_cmp_greater_eq(auto&& t, auto&& u)
2744-
-> decltype(auto)
2745-
requires requires {CPP2_FORWARD(t) >= CPP2_FORWARD(u);}
2746-
{
2747-
return CPP2_FORWARD(t) >= CPP2_FORWARD(u);
2748-
}
2749-
2750-
CPP2_FORCE_INLINE constexpr auto unchecked_div(auto&& t, auto&& u)
2751-
-> decltype(auto)
2752-
requires requires {CPP2_FORWARD(t) / CPP2_FORWARD(u);}
2753-
{
2754-
return CPP2_FORWARD(t) / CPP2_FORWARD(u);
2755-
}
2756-
2757-
CPP2_FORCE_INLINE constexpr auto unchecked_dereference(auto&& p)
2758-
-> decltype(auto)
2759-
requires requires {*CPP2_FORWARD(p);}
2760-
{
2761-
return *CPP2_FORWARD(p);
2762-
}
2763-
2764-
CPP2_FORCE_INLINE constexpr auto unchecked_subscript(auto&& a, auto&& b)
2765-
-> decltype(auto)
2766-
requires requires {CPP2_FORWARD(a)[b];}
2767-
{
2768-
return CPP2_FORWARD(a)[b];
2769-
}
2770-
2771-
27722714
namespace impl {
27732715

27742716
//-----------------------------------------------------------------------
@@ -2787,8 +2729,7 @@ CPP2_FORCE_INLINE constexpr auto cmp_mixed_signedness_check() -> void
27872729
{
27882730
static_assert(
27892731
program_violates_type_safety_guarantee<T, U>,
2790-
"comparing bool values using < <= >= > is unsafe and not allowed - are you missing parentheses?"
2791-
);
2732+
"comparing bool values using < <= >= > is unsafe and not allowed - are you missing parentheses?");
27922733
}
27932734
else if constexpr (
27942735
std::is_integral_v<T> &&
@@ -2804,22 +2745,20 @@ CPP2_FORCE_INLINE constexpr auto cmp_mixed_signedness_check() -> void
28042745
// static_assert to reject the comparison is the right way to go.
28052746
static_assert(
28062747
program_violates_type_safety_guarantee<T, U>,
2807-
"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'"
2748+
"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'"
28082749
);
28092750
}
28102751
}
28112752

28122753

2813-
CPP2_FORCE_INLINE constexpr auto cmp_less(auto&& t, auto&& u)
2814-
-> decltype(auto)
2754+
CPP2_FORCE_INLINE constexpr auto cmp_less(auto&& t, auto&& u) -> decltype(auto)
28152755
requires requires {CPP2_FORWARD(t) < CPP2_FORWARD(u);}
28162756
{
28172757
cmp_mixed_signedness_check<CPP2_TYPEOF(t), CPP2_TYPEOF(u)>();
28182758
return CPP2_FORWARD(t) < CPP2_FORWARD(u);
28192759
}
28202760

2821-
CPP2_FORCE_INLINE constexpr auto cmp_less(auto&& t, auto&& u)
2822-
-> decltype(auto)
2761+
CPP2_FORCE_INLINE constexpr auto cmp_less(auto&& t, auto&& u) -> decltype(auto)
28232762
{
28242763
static_assert(
28252764
program_violates_type_safety_guarantee<decltype(t), decltype(u)>,
@@ -2829,16 +2768,14 @@ CPP2_FORCE_INLINE constexpr auto cmp_less(auto&& t, auto&& u)
28292768
}
28302769

28312770

2832-
CPP2_FORCE_INLINE constexpr auto cmp_less_eq(auto&& t, auto&& u)
2833-
-> decltype(auto)
2771+
CPP2_FORCE_INLINE constexpr auto cmp_less_eq(auto&& t, auto&& u) -> decltype(auto)
28342772
requires requires {CPP2_FORWARD(t) <= CPP2_FORWARD(u);}
28352773
{
28362774
cmp_mixed_signedness_check<CPP2_TYPEOF(t), CPP2_TYPEOF(u)>();
28372775
return CPP2_FORWARD(t) <= CPP2_FORWARD(u);
28382776
}
28392777

2840-
CPP2_FORCE_INLINE constexpr auto cmp_less_eq(auto&& t, auto&& u)
2841-
-> decltype(auto)
2778+
CPP2_FORCE_INLINE constexpr auto cmp_less_eq(auto&& t, auto&& u) -> decltype(auto)
28422779
{
28432780
static_assert(
28442781
program_violates_type_safety_guarantee<decltype(t), decltype(u)>,
@@ -2848,16 +2785,14 @@ CPP2_FORCE_INLINE constexpr auto cmp_less_eq(auto&& t, auto&& u)
28482785
}
28492786

28502787

2851-
CPP2_FORCE_INLINE constexpr auto cmp_greater(auto&& t, auto&& u)
2852-
-> decltype(auto)
2788+
CPP2_FORCE_INLINE constexpr auto cmp_greater(auto&& t, auto&& u) -> decltype(auto)
28532789
requires requires {CPP2_FORWARD(t) > CPP2_FORWARD(u);}
28542790
{
28552791
cmp_mixed_signedness_check<CPP2_TYPEOF(t), CPP2_TYPEOF(u)>();
28562792
return CPP2_FORWARD(t) > CPP2_FORWARD(u);
28572793
}
28582794

2859-
CPP2_FORCE_INLINE constexpr auto cmp_greater(auto&& t, auto&& u)
2860-
-> decltype(auto)
2795+
CPP2_FORCE_INLINE constexpr auto cmp_greater(auto&& t, auto&& u) -> decltype(auto)
28612796
{
28622797
static_assert(
28632798
program_violates_type_safety_guarantee<decltype(t), decltype(u)>,
@@ -2867,16 +2802,14 @@ CPP2_FORCE_INLINE constexpr auto cmp_greater(auto&& t, auto&& u)
28672802
}
28682803

28692804

2870-
CPP2_FORCE_INLINE constexpr auto cmp_greater_eq(auto&& t, auto&& u)
2871-
-> decltype(auto)
2805+
CPP2_FORCE_INLINE constexpr auto cmp_greater_eq(auto&& t, auto&& u) -> decltype(auto)
28722806
requires requires {CPP2_FORWARD(t) >= CPP2_FORWARD(u);}
28732807
{
28742808
cmp_mixed_signedness_check<CPP2_TYPEOF(t), CPP2_TYPEOF(u)>();
28752809
return CPP2_FORWARD(t) >= CPP2_FORWARD(u);
28762810
}
28772811

2878-
CPP2_FORCE_INLINE constexpr auto cmp_greater_eq(auto&& t, auto&& u)
2879-
-> decltype(auto)
2812+
CPP2_FORCE_INLINE constexpr auto cmp_greater_eq(auto&& t, auto&& u) -> decltype(auto)
28802813
{
28812814
static_assert(
28822815
program_violates_type_safety_guarantee<decltype(t), decltype(u)>,

0 commit comments

Comments
 (0)