Skip to content

Commit

Permalink
Enable /clr C++20 support (#3194)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanTLavavej authored Nov 8, 2022
1 parent c873cf0 commit ea09254
Show file tree
Hide file tree
Showing 155 changed files with 619 additions and 631 deletions.
11 changes: 4 additions & 7 deletions stl/inc/__msvc_all_public_headers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,16 @@
#include <__msvc_cxx_stdatomic.hpp>
#include <atomic>
#include <barrier>
#include <latch>
#include <semaphore>
#include <stop_token>
#endif // _M_CEE_PURE

#ifndef _M_CEE
#include <condition_variable>
#include <execution>
#include <future>
#include <latch>
#include <mutex>
#include <semaphore>
#include <shared_mutex>
#include <stop_token>
#include <thread>
#endif // _M_CEE
#endif // _M_CEE_PURE

// Non-Core C Wrapper Headers
#include <ccomplex>
Expand Down
14 changes: 14 additions & 0 deletions stl/inc/algorithm
Original file line number Diff line number Diff line change
Expand Up @@ -932,10 +932,17 @@ namespace ranges {
// We've trimmed matching prefixes and matching suffixes.
// Now we need to compare each range's prefix to the other range's suffix.

#ifdef _M_CEE // TRANSITION, VSO-1663257
const auto _ProjectedPred = [&](auto&& _Left, auto&& _Right) -> bool {
return _STD invoke(_Pred, _STD invoke(_Proj1, _STD forward<decltype(_Left)>(_Left)),
_STD invoke(_Proj2, _STD forward<decltype(_Right)>(_Right)));
};
#else // ^^^ workaround / no workaround vvv
const auto _ProjectedPred = [&]<class _Ty1, class _Ty2>(_Ty1&& _Left, _Ty2&& _Right) -> bool {
return _STD invoke(_Pred, _STD invoke(_Proj1, _STD forward<_Ty1>(_Left)),
_STD invoke(_Proj2, _STD forward<_Ty2>(_Right)));
};
#endif // ^^^ no workaround ^^^

const _TrimResult _Res = _Trim_completely(_First1, _Final1, _First2, _Final2, _ProjectedPred);

Expand Down Expand Up @@ -1021,10 +1028,17 @@ namespace ranges {
// We've trimmed matching prefixes and matching suffixes.
// Now we need to compare each range's prefix to the other range's suffix.

#ifdef _M_CEE // TRANSITION, VSO-1663257
const auto _ProjectedPred = [&](auto&& _Left, auto&& _Right) -> bool {
return _STD invoke(_Pred, _STD invoke(_Proj1, _STD forward<decltype(_Left)>(_Left)),
_STD invoke(_Proj2, _STD forward<decltype(_Right)>(_Right)));
};
#else // ^^^ workaround / no workaround vvv
const auto _ProjectedPred = [&]<class _Ty1, class _Ty2>(_Ty1&& _Left, _Ty2&& _Right) -> bool {
return _STD invoke(_Pred, _STD invoke(_Proj1, _STD forward<_Ty1>(_Left)),
_STD invoke(_Proj2, _STD forward<_Ty2>(_Right)));
};
#endif // ^^^ no workaround ^^^

const _TrimResult _Res = _Trim_completely(_First1, _Final1, _First2, _Final2, _ProjectedPred);

Expand Down
14 changes: 10 additions & 4 deletions stl/inc/chrono
Original file line number Diff line number Diff line change
Expand Up @@ -5358,7 +5358,13 @@ namespace chrono {

const _Allowed_bit _Mod = _Modifier == 'E' ? _E_mod : _O_mod;

if (auto _It = _RANGES find(_Table, _Type, &_Table_entry::_Type); _It != _STD end(_Table)) {
#ifdef _M_CEE // TRANSITION, VSO-1664341
constexpr auto _Get_table_entry_type = [](const _Table_entry& _Entry) { return _Entry._Type; };
#else // ^^^ workaround / no workaround vvv
constexpr auto _Get_table_entry_type = &_Table_entry::_Type;
#endif // ^^^ no workaround ^^^

if (auto _It = _RANGES find(_Table, _Type, _Get_table_entry_type); _It != _STD end(_Table)) {
if (_It->_Allowed & _Mod) {
return;
}
Expand Down Expand Up @@ -5679,10 +5685,10 @@ namespace chrono {
return;
}

constexpr bool _Is_ymd =
_Is_any_of_v<_Ty, year_month_day, year_month_day_last, year_month_weekday, year_month_weekday_last>;

const auto _Validate = [&] {
constexpr bool _Is_ymd =
_Is_any_of_v<_Ty, year_month_day, year_month_day_last, year_month_weekday, year_month_weekday_last>;

switch (_Spec._Type) {
case 'a':
case 'A':
Expand Down
3 changes: 2 additions & 1 deletion stl/inc/cmath
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#include <cstdlib>
#include <xtr1common>

#if !defined(_M_CEE) && !defined(__clang__) && !defined(__CUDACC__) && !defined(__INTEL_COMPILER)
#if !defined(__clang__) && !defined(__CUDACC__) && !defined(__INTEL_COMPILER) \
&& !defined(_M_CEE) // TRANSITION, VSO-1663104
#define _HAS_CMATH_INTRINSICS 1
#else // ^^^ intrinsics available ^^^ / vvv intrinsics unavailable vvv
#define _HAS_CMATH_INTRINSICS 0
Expand Down
6 changes: 3 additions & 3 deletions stl/inc/condition_variable
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ _STL_DISABLE_CLANG_WARNINGS
#pragma push_macro("new")
#undef new

#ifdef _M_CEE
#error <condition_variable> is not supported when compiling with /clr or /clr:pure.
#endif // _M_CEE
#ifdef _M_CEE_PURE
#error <condition_variable> is not supported when compiling with /clr:pure.
#endif // _M_CEE_PURE

_STD_BEGIN
template <class _Lock>
Expand Down
5 changes: 5 additions & 0 deletions stl/inc/format
Original file line number Diff line number Diff line change
Expand Up @@ -1952,7 +1952,12 @@ public:
_NODISCARD size_t _Estimate_required_capacity() const noexcept {
using _CharT = typename _Context::char_type;
size_t _Result = 0;
#ifdef _M_CEE // TRANSITION, VSO-1663257
const auto _Visitor = [&_Result](const auto _Arg) noexcept {
using _ArgTy = remove_const_t<decltype(_Arg)>;
#else // ^^^ workaround / no workaround vvv
const auto _Visitor = [&_Result]<class _ArgTy>(const _ArgTy _Arg) noexcept {
#endif // ^^^ no workaround ^^^
if constexpr (is_same_v<_ArgTy, basic_string_view<_CharT>>) {
_Result += _Arg.size();
} else if constexpr (is_same_v<_ArgTy, const _CharT*>) {
Expand Down
6 changes: 3 additions & 3 deletions stl/inc/future
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include <yvals_core.h>
#if _STL_COMPILER_PREPROCESSOR

#ifdef _M_CEE
#error <future> is not supported when compiling with /clr or /clr:pure.
#endif // _M_CEE
#ifdef _M_CEE_PURE
#error <future> is not supported when compiling with /clr:pure.
#endif // _M_CEE_PURE

#ifdef _RESUMABLE_FUNCTIONS_SUPPORTED
#include <experimental/resumable>
Expand Down
8 changes: 8 additions & 0 deletions stl/inc/iterator
Original file line number Diff line number Diff line change
Expand Up @@ -1355,9 +1355,15 @@ public:
_RANGES iter_swap(_Left._Current, _Right.base());
}

#if _ITERATOR_DEBUG_LEVEL != 0
template <common_with<_Iter> _Other>
friend constexpr void _Same_sequence(
const counted_iterator& _Left, const counted_iterator<_Other>& _Right) noexcept {
#ifdef _M_CEE // TRANSITION, VSO-1665606
(void) _Left;
(void) _Right;
#else // ^^^ workaround / no workaround vvv

// Per N4901 [counted.iterator]/3, two counted_iterators x and y refer to elements of the same sequence iff
// for some integer n, next(x.base(), x.count() + n) and next(y.base(), y.count() + n)
// "refer to the same (possibly past-the-end) element".
Expand All @@ -1377,7 +1383,9 @@ public:
"counted_iterators are from different ranges");
}
}
#endif // ^^^ no workaround ^^^
}
#endif // _ITERATOR_DEBUG_LEVEL != 0

template <common_with<_Iter> _Other>
friend constexpr void _Verify_range(const counted_iterator& _Left, const counted_iterator<_Other>& _Right) {
Expand Down
8 changes: 4 additions & 4 deletions stl/inc/memory_resource
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ _EMIT_STL_WARNING(STL4038, "The contents of <memory_resource> are available only
#include <xpolymorphic_allocator.h>
#include <xutility>

#ifndef _M_CEE
#ifndef _M_CEE_PURE
#include <mutex>
#endif // _M_CEE
#endif // _M_CEE_PURE

#pragma pack(push, _CRT_PACKING)
#pragma warning(push, _STL_WARNING_LEVEL)
Expand Down Expand Up @@ -565,7 +565,7 @@ namespace pmr {
pmr::vector<_Pool> _Pools{}; // pools in order of increasing block size
};

#ifndef _M_CEE
#ifndef _M_CEE_PURE
_EXPORT_STD class synchronized_pool_resource : public unsynchronized_pool_resource {
public:
using unsynchronized_pool_resource::unsynchronized_pool_resource;
Expand All @@ -589,7 +589,7 @@ namespace pmr {
private:
mutable mutex _Mtx;
};
#endif // _M_CEE
#endif // _M_CEE_PURE

_EXPORT_STD class monotonic_buffer_resource : public _Identity_equal_resource {
public:
Expand Down
6 changes: 0 additions & 6 deletions stl/inc/mutex
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ _STL_DISABLE_CLANG_WARNINGS
#undef new

_STD_BEGIN
// mutex and recursive_mutex are not supported under /clr
#ifndef _M_CEE
_EXPORT_STD class condition_variable;
_EXPORT_STD class condition_variable_any;

Expand Down Expand Up @@ -103,7 +101,6 @@ public:
recursive_mutex(const recursive_mutex&) = delete;
recursive_mutex& operator=(const recursive_mutex&) = delete;
};
#endif // _M_CEE

_EXPORT_STD struct adopt_lock_t { // indicates adopt lock
explicit adopt_lock_t() = default;
Expand Down Expand Up @@ -563,8 +560,6 @@ void(call_once)(once_flag& _Once, _Fn&& _Fx, _Args&&... _Ax) noexcept(
#undef _WINDOWS_API
#undef _RENAME_WINDOWS_API

// condition_variable, timed_mutex, and recursive_timed_mutex are not supported under /clr
#ifndef _M_CEE
_EXPORT_STD enum class cv_status { // names for wait returns
no_timeout,
timeout
Expand Down Expand Up @@ -930,7 +925,6 @@ private:
unsigned int _My_locked;
thread::id _My_owner;
};
#endif // _M_CEE
_STD_END
#pragma pop_macro("new")
_STL_RESTORE_CLANG_WARNINGS
Expand Down
7 changes: 1 addition & 6 deletions stl/inc/shared_mutex
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
#error <shared_mutex> is not supported when compiling with /clr:pure.
#endif // _M_CEE_PURE

#include <condition_variable>
#include <mutex>
#include <xthreads.h>
#ifndef _M_CEE
#include <condition_variable>
#endif // _M_CEE

#pragma pack(push, _CRT_PACKING)
#pragma warning(push, _STL_WARNING_LEVEL)
Expand Down Expand Up @@ -71,8 +69,6 @@ private:
_Smtx_t _Myhandle;
};

// shared_timed_mutex is not supported under /clr
#ifndef _M_CEE
_EXPORT_STD class shared_timed_mutex { // class for mutual exclusion shared across threads
private:
using _Read_cnt_t = unsigned int;
Expand Down Expand Up @@ -230,7 +226,6 @@ private:
_Read_cnt_t _Readers;
bool _Writing;
};
#endif // _M_CEE

_EXPORT_STD template <class _Mutex>
class shared_lock { // shareable lock
Expand Down
17 changes: 7 additions & 10 deletions stl/inc/xlocinfo
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,9 @@ public:
static _Locinfo& __CLRCALL_PURE_OR_CDECL _Locinfo_Addcats(_Locinfo*, int, const char*);

__CLR_OR_THIS_CALL _Locinfo(const char* _Pch = "C")
#ifndef _M_CEE
#ifndef _M_CEE_PURE
: _Lock(_LOCK_LOCALE)
#endif // _M_CEE

#endif // _M_CEE_PURE
{
if (_Pch) {
_Locinfo_ctor(this, _Pch);
Expand All @@ -241,10 +240,9 @@ public:
}

__CLR_OR_THIS_CALL _Locinfo(int _Cat, const char* _Pch)
#ifndef _M_CEE
#ifndef _M_CEE_PURE
: _Lock(_LOCK_LOCALE)
#endif // _M_CEE

#endif // _M_CEE_PURE
{
if (_Pch) {
_Locinfo_ctor(this, _Cat, _Pch);
Expand Down Expand Up @@ -373,12 +371,11 @@ public:
_Locinfo& operator=(const _Locinfo&) = delete;

private:
#ifdef _M_CEE
#ifdef _M_CEE_PURE
_EmptyLockit _Empty_lock; // to maintain same size

#else // _M_CEE
#else // _M_CEE_PURE
_Lockit _Lock; // thread lock, because global locale is altered
#endif // _M_CEE
#endif // _M_CEE_PURE

_Yarn<char> _Days; // weekday names
_Yarn<char> _Months; // month names
Expand Down
12 changes: 9 additions & 3 deletions stl/inc/xthreads.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,15 @@ _INLINE_VAR constexpr size_t _Cnd_internal_imp_alignment = 4;
#endif // _WIN64
#endif // _CRT_WINDOWS

using _Mtx_t = struct _Mtx_internal_imp_t*;

using _Cnd_t = struct _Cnd_internal_imp_t*;
#ifdef _M_CEE // avoid warning LNK4248: unresolved typeref token for '_Mtx_internal_imp_t'; image may not run
using _Mtx_t = void*;
using _Cnd_t = void*;
#else // ^^^ defined(_M_CEE) / !defined(_M_CEE) vvv
struct _Mtx_internal_imp_t;
struct _Cnd_internal_imp_t;
using _Mtx_t = _Mtx_internal_imp_t*;
using _Cnd_t = _Cnd_internal_imp_t*;
#endif // ^^^ !defined(_M_CEE) ^^^

enum { _Thrd_success, _Thrd_nomem, _Thrd_timedout, _Thrd_busy, _Thrd_error };

Expand Down
25 changes: 13 additions & 12 deletions stl/inc/yvals.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,14 @@ extern "C++" class _CRTIMP2_PURE_IMPORT _Lockit { // lock while object in existe
int _Locktype;
};

#ifdef _M_CEE
#ifdef _M_CEE_PURE
class _CRTIMP2_PURE_IMPORT _EmptyLockit { // empty lock class used for bin compat
private:
int _Locktype;
};
#endif // _M_CEE_PURE

#ifdef _M_CEE
#ifndef _PREPARE_CONSTRAINED_REGIONS
#ifdef _M_CEE_PURE
#define _PREPARE_CONSTRAINED_REGIONS 1
Expand Down Expand Up @@ -437,11 +439,6 @@ class _CRTIMP2_PURE_IMPORT _EmptyLockit { // empty lock class used for bin compa

#define _END_LOCINFO() _END_LOCK()

#define _RELIABILITY_CONTRACT \
[System::Runtime::ConstrainedExecution::ReliabilityContract( \
System::Runtime::ConstrainedExecution::Consistency::WillNotCorruptState, \
System::Runtime::ConstrainedExecution::Cer::Success)]

#else // _M_CEE
#define _BEGIN_LOCK(_Kind) \
{ \
Expand All @@ -454,8 +451,6 @@ class _CRTIMP2_PURE_IMPORT _EmptyLockit { // empty lock class used for bin compa
_Locinfo _VarName;

#define _END_LOCINFO() }

#define _RELIABILITY_CONTRACT
#endif // _M_CEE

#ifdef _CRTBLD
Expand All @@ -479,6 +474,16 @@ class _CRTIMP2_PURE_IMPORT _Init_locks { // initialize mutexes
static void __cdecl _Init_locks_ctor(_Init_locks*) noexcept;
static void __cdecl _Init_locks_dtor(_Init_locks*) noexcept;
};

#ifdef _M_CEE
#define _RELIABILITY_CONTRACT \
[System::Runtime::ConstrainedExecution::ReliabilityContract( \
System::Runtime::ConstrainedExecution::Consistency::WillNotCorruptState, \
System::Runtime::ConstrainedExecution::Cer::Success)]
#else // _M_CEE
#define _RELIABILITY_CONTRACT
#endif // _M_CEE

#endif // _CRTBLD

#if _HAS_EXCEPTIONS
Expand Down Expand Up @@ -519,10 +524,6 @@ class _CRTIMP2_PURE_IMPORT _Init_locks { // initialize mutexes
#endif // _HAS_EXCEPTIONS
_STD_END

#ifndef _RELIABILITY_CONTRACT
#define _RELIABILITY_CONTRACT
#endif // _RELIABILITY_CONTRACT

#pragma pop_macro("new")
_STL_RESTORE_CLANG_WARNINGS
#pragma warning(pop)
Expand Down
Loading

0 comments on commit ea09254

Please sign in to comment.