Add workaround for MSVC vs. CapPtr constructor

This commit is contained in:
Nathaniel Filardo
2021-04-07 16:58:28 +01:00
committed by Nathaniel Wesley Filardo
parent d9ee19a16c
commit e31751fc94
2 changed files with 18 additions and 0 deletions

View File

@@ -112,8 +112,22 @@ namespace snmalloc
/**
* all other constructions must be explicit
*
* Unfortunately, MSVC gets confused if an Allocator is instantiated in a
* way that never needs initialization (as our sandbox test does, for
* example) and, in that case, declares this constructor unreachable,
* presumably after some heroic feat of inlining that has also lost any
* semblance of context. See the blocks tagged "CapPtr-vs-MSVC" for where
* this has been observed.
*/
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable : 4702)
#endif
explicit CapPtr(T* p) : unsafe_capptr(p) {}
#ifdef _MSC_VER
# pragma warning(pop)
#endif
/**
* Allow static_cast<>-s that preserve bounds but vary the target type.

View File

@@ -19,6 +19,8 @@ namespace
/**
* Helper for Alloc that is never used as a thread-local allocator and so is
* always initialised.
*
* CapPtr-vs-MSVC triggering; xref CapPtr's constructor
*/
bool never_init(void*)
{
@@ -26,6 +28,8 @@ namespace
}
/**
* Helper for Alloc that never needs lazy initialisation.
*
* CapPtr-vs-MSVC triggering; xref CapPtr's constructor
*/
void* no_op_init(function_ref<void*(void*)>)
{