-
Notifications
You must be signed in to change notification settings - Fork 1.5k
<xmemory>: Investigate constexpr approach between _Default_allocator_traits::allocate and _Allocate #1532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
From a purely language semantics point of view: MSVC is doing the right thing. The standard states the following are allowed in constant expressions
The expression |
Yes, I think it was perhaps incorrect to say that |
@cdacamar I think you mean the exact opposite - those evaluations are forbidden in a constant expression. For example, "a call to an instance [I am not fond of the use of "instance" here to refer to the result of instantiating a function template] of |
In GH-1369, we will be implementing
is_constant_evaluated()
pathways in both_Default_allocator_traits::allocate
and the global_Allocate
function that is called from that function if not evaluated in aconstexpr
context._Default_allocator_traits::allocate
STL/stl/inc/xmemory
Lines 661 to 673 in ac4fde7
_Allocate
:STL/stl/inc/xmemory
Lines 173 to 198 in ac4fde7
Currently, MSVC cannot handle calling the
_Allocate
function from aconstexpr
context (_Allocate
calls::operator new
which MSVC does not allow in aconstexpr
function, though Clang does if it is reached transitively from an evaluation ofstd::allocator::allocate
), which is why there is theis_constant_evaluated()
block in_Default_allocator_traits::allocate
that instead dispatches tostd::allocator::allocate
(which is permitted by MSVC). Note that_Normal_allocator_traits
is not affected by this issue because it does not attempt the optimization at directly calling_Allocate
and instead always goes through_Alloc::allocate
.It seems like we should either (1) have
_Allocate
be completelyconstexpr
-safe (have validconstexpr
pathways for all supported compilers), or (2) have_Allocate
be a completely non-constexpr function that is just never called inconstexpr
pathways (and in this case, I believe we could also remove theconstexpr
pathways in_Default_allocate_traits
used in_Allocate
,_Deallocate
). This depends on whether MSVC will permit the call to_Allocate
in the future as theconstexpr
dynamic allocation implementation matures (in this case, we could adopt approach (1)). Otherwise, we can look into option (2). Regardless, we should pick one of these options to avoid this code duplication and the logic being split up in this way.Internal Microsoft link only: You can hear more discussion about this issue here: https://msit.microsoftstream.com/video/4740a1ff-0400-b9eb-093e-f1eb3b56cd9a?st=2877
The text was updated successfully, but these errors were encountered: