Skip to content

Commit 47cd703

Browse files
misccomnatsuharaStephanTLavavej
authored
Prepare the constexpr machinery needed for string and vector (#1546)
Co-authored-by: Miya Natsuhara <[email protected]> Co-authored-by: Stephan T. Lavavej <[email protected]>
1 parent c7b1405 commit 47cd703

File tree

8 files changed

+306
-194
lines changed

8 files changed

+306
-194
lines changed

stl/inc/regex

+1-1
Original file line numberDiff line numberDiff line change
@@ -2466,7 +2466,7 @@ public:
24662466
_MyRe = nullptr;
24672467

24682468
#if _ITERATOR_DEBUG_LEVEL == 2
2469-
this->_Orphan_me();
2469+
this->_Orphan_me_v2();
24702470
#endif // _ITERATOR_DEBUG_LEVEL
24712471

24722472
return *this;

stl/inc/xmemory

+271-164
Large diffs are not rendered by default.

stl/inc/xutility

+14-6
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,26 @@ _NODISCARD constexpr void* _Voidify_iter(_Iter _It) noexcept {
131131

132132
// FUNCTION TEMPLATE construct_at
133133
#if _HAS_CXX20
134-
template <class _Ty, class... _Types>
135-
_CONSTEXPR20_DYNALLOC auto construct_at(_Ty* const _Location, _Types&&... _Args) noexcept(
136-
noexcept(::new (_Voidify_iter(_Location)) _Ty(_STD forward<_Types>(_Args)...))) // strengthened
137-
-> decltype(::new (_Voidify_iter(_Location)) _Ty(_STD forward<_Types>(_Args)...)) {
134+
template <class _Ty, class... _Types,
135+
class = void_t<decltype(::new (_STD declval<void*>()) _Ty(_STD declval<_Types>()...))>>
136+
_CONSTEXPR20_DYNALLOC _Ty* construct_at(_Ty* const _Location, _Types&&... _Args) noexcept(
137+
noexcept(::new (_Voidify_iter(_Location)) _Ty(_STD forward<_Types>(_Args)...))) /* strengthened */ {
138138
return ::new (_Voidify_iter(_Location)) _Ty(_STD forward<_Types>(_Args)...);
139139
}
140140
#endif // _HAS_CXX20
141141

142142
// FUNCTION TEMPLATE _Construct_in_place
143143
template <class _Ty, class... _Types>
144-
void _Construct_in_place(_Ty& _Obj, _Types&&... _Args) noexcept(is_nothrow_constructible_v<_Ty, _Types...>) {
145-
::new (_Voidify_iter(_STD addressof(_Obj))) _Ty(_STD forward<_Types>(_Args)...);
144+
_CONSTEXPR20_DYNALLOC void _Construct_in_place(_Ty& _Obj, _Types&&... _Args) noexcept(
145+
is_nothrow_constructible_v<_Ty, _Types...>) {
146+
#ifdef __cpp_lib_constexpr_dynamic_alloc
147+
if (_STD is_constant_evaluated()) {
148+
_STD construct_at(_STD addressof(_Obj), _STD forward<_Types>(_Args)...);
149+
} else
150+
#endif // __cpp_lib_constexpr_dynamic_alloc
151+
{
152+
::new (_Voidify_iter(_STD addressof(_Obj))) _Ty(_STD forward<_Types>(_Args)...);
153+
}
146154
}
147155

148156
// FUNCTION TEMPLATE _Default_construct_in_place

stl/inc/yvals_core.h

+9-3
Original file line numberDiff line numberDiff line change
@@ -1190,10 +1190,9 @@
11901190
#define __cpp_lib_constexpr_algorithms 201806L
11911191
#define __cpp_lib_constexpr_complex 201711L
11921192

1193-
#if defined(__cpp_constexpr_dynamic_alloc) \
1194-
&& defined(__clang__) // TRANSITION, MSVC support for constexpr dynamic allocation
1193+
#ifdef __cpp_constexpr_dynamic_alloc
11951194
#define __cpp_lib_constexpr_dynamic_alloc 201907L
1196-
#endif // defined(__cpp_constexpr_dynamic_alloc) && defined(__clang__)
1195+
#endif // __cpp_constexpr_dynamic_alloc
11971196

11981197
#define __cpp_lib_constexpr_functional 201907L
11991198
#define __cpp_lib_constexpr_iterator 201811L
@@ -1284,6 +1283,13 @@
12841283
#define _CONSTEXPR20_DYNALLOC inline
12851284
#endif
12861285

1286+
// Functions that became constexpr in C++20 via P0980R1 or P1004R2
1287+
#if defined(__cpp_lib_constexpr_dynamic_alloc) && !defined(__clang__) // TRANSITION:LLVM-48606
1288+
#define _CONSTEXPR20_CONTAINER constexpr
1289+
#else
1290+
#define _CONSTEXPR20_CONTAINER inline
1291+
#endif
1292+
12871293
#ifdef _RTC_CONVERSION_CHECKS_ENABLED
12881294
#ifndef _ALLOW_RTCc_IN_STL
12891295
#error /RTCc rejects conformant code, so it is not supported by the C++ Standard Library. Either remove this \

tests/libcxx/expected_results.txt

-9
Original file line numberDiff line numberDiff line change
@@ -310,18 +310,9 @@ std/language.support/support.limits/support.limits.general/format.version.pass.c
310310
std/utilities/format/format.error/format.error.pass.cpp FAIL
311311

312312
# C++20 P0784R7 "More constexpr containers"
313-
std/utilities/memory/allocator.traits/allocator.traits.members/allocate.pass.cpp:0 FAIL
314-
std/utilities/memory/allocator.traits/allocator.traits.members/allocate_hint.pass.cpp:0 FAIL
315313
std/utilities/memory/allocator.traits/allocator.traits.members/construct.pass.cpp FAIL
316-
std/utilities/memory/allocator.traits/allocator.traits.members/deallocate.pass.cpp:0 FAIL
317314
std/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp FAIL
318-
std/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp:0 FAIL
319-
std/utilities/memory/allocator.traits/allocator.traits.members/select_on_container_copy_construction.pass.cpp:0 FAIL
320-
std/utilities/memory/default.allocator/allocator.globals/eq.pass.cpp:0 FAIL
321315
std/utilities/memory/specialized.algorithms/specialized.construct/construct_at.pass.cpp FAIL
322-
std/utilities/memory/specialized.algorithms/specialized.destroy/destroy.pass.cpp:0 FAIL
323-
std/utilities/memory/specialized.algorithms/specialized.destroy/destroy_at.pass.cpp:0 FAIL
324-
std/utilities/memory/specialized.algorithms/specialized.destroy/destroy_n.pass.cpp:0 FAIL
325316

326317
# C++20 P0896R4 "<ranges>"
327318
std/language.support/support.limits/support.limits.general/algorithm.version.pass.cpp FAIL

tests/libcxx/skipped_tests.txt

-9
Original file line numberDiff line numberDiff line change
@@ -310,18 +310,9 @@ language.support\support.limits\support.limits.general\format.version.pass.cpp
310310
utilities\format\format.error\format.error.pass.cpp
311311

312312
# C++20 P0784R7 "More constexpr containers"
313-
utilities\memory\allocator.traits\allocator.traits.members\allocate.pass.cpp
314-
utilities\memory\allocator.traits\allocator.traits.members\allocate_hint.pass.cpp
315313
utilities\memory\allocator.traits\allocator.traits.members\construct.pass.cpp
316-
utilities\memory\allocator.traits\allocator.traits.members\deallocate.pass.cpp
317314
utilities\memory\allocator.traits\allocator.traits.members\destroy.pass.cpp
318-
utilities\memory\allocator.traits\allocator.traits.members\max_size.pass.cpp
319-
utilities\memory\allocator.traits\allocator.traits.members\select_on_container_copy_construction.pass.cpp
320-
utilities\memory\default.allocator\allocator.globals\eq.pass.cpp
321315
utilities\memory\specialized.algorithms\specialized.construct\construct_at.pass.cpp
322-
utilities\memory\specialized.algorithms\specialized.destroy\destroy.pass.cpp
323-
utilities\memory\specialized.algorithms\specialized.destroy\destroy_at.pass.cpp
324-
utilities\memory\specialized.algorithms\specialized.destroy\destroy_n.pass.cpp
325316

326317
# C++20 P0896R4 "<ranges>"
327318
language.support\support.limits\support.limits.general\algorithm.version.pass.cpp

tests/std/tests/P0784R7_library_support_for_more_constexpr_containers/test.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ void test_array(const T& val) {
227227
}
228228

229229
#ifdef __cpp_lib_constexpr_dynamic_alloc
230+
#ifndef __EDG__ // TRANSITION, VSO-1269976
230231
template <class T>
231232
struct storage_for {
232233
union {
@@ -244,9 +245,11 @@ constexpr void test_compiletime() {
244245
assert(s.object == 42);
245246
destroy_at(&s.object);
246247

248+
#ifdef __cpp_lib_concepts
247249
ranges::construct_at(&s.object, 1729);
248250
assert(s.object == 1729);
249251
ranges::destroy_at(&s.object);
252+
#endif // __cpp_lib_concepts
250253
}
251254

252255
struct nontrivial {
@@ -262,12 +265,15 @@ constexpr void test_compiletime() {
262265
assert(s.object.x == 42);
263266
destroy_at(&s.object);
264267

268+
#ifdef __cpp_lib_concepts
265269
ranges::construct_at(&s.object, 1729);
266270
assert(s.object.x == 1729);
267271
ranges::destroy_at(&s.object);
272+
#endif // __cpp_lib_concepts
268273
}
269274
}
270275
static_assert((test_compiletime(), true));
276+
#endif // __EDG__
271277

272278
template <class T>
273279
struct A {
@@ -286,6 +292,7 @@ struct nontrivial_A {
286292
};
287293

288294
constexpr void test_compiletime_destroy_variants() {
295+
#ifndef __EDG__ // TRANSITION, VSO-1270011
289296
{
290297
allocator<A<int>> alloc{};
291298
A<int>* a = alloc.allocate(10);
@@ -304,6 +311,7 @@ constexpr void test_compiletime_destroy_variants() {
304311
destroy(a, a + 10);
305312
alloc.deallocate(a, 10);
306313
}
314+
#endif // __EDG__
307315
#ifdef __cpp_lib_concepts
308316
{
309317
allocator<A<int>> alloc{};
@@ -385,6 +393,7 @@ constexpr void test_compiletime_destroy_variants() {
385393
}
386394
static_assert((test_compiletime_destroy_variants(), true));
387395

396+
#ifndef __EDG__ // TRANSITION, VSO-1269976
388397
template <class T, bool Construct = false, bool Destroy = false>
389398
struct Alloc {
390399
using value_type = T;
@@ -498,6 +507,7 @@ constexpr void test_compiletime_allocator_traits() {
498507
}
499508
}
500509
static_assert((test_compiletime_allocator_traits(), true));
510+
#endif // __EDG__
501511

502512
constexpr void test_compiletime_allocator() {
503513
{

tests/std/tests/VSO_0157762_feature_test_macros/test.compile.pass.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,7 @@ STATIC_ASSERT(__cpp_lib_constexpr_complex == 201711L);
411411
#endif
412412
#endif
413413

414-
#if _HAS_CXX20 && defined(__cpp_constexpr_dynamic_alloc) \
415-
&& defined(__clang__) // TRANSITION, MSVC support for constexpr dynamic allocation
414+
#if _HAS_CXX20 && defined(__cpp_constexpr_dynamic_alloc)
416415
#ifndef __cpp_lib_constexpr_dynamic_alloc
417416
#error __cpp_lib_constexpr_dynamic_alloc is not defined
418417
#elif __cpp_lib_constexpr_dynamic_alloc != 201907L

0 commit comments

Comments
 (0)