I am talking about consteval context. See

Portable-Cpp-Guideline/README.md at main · trcrsired/Portable-Cpp-Guideline (github.com)

 

 

Also see explanations:

https://youtu.be/OZxP5D8UiZ4?si=CGym2iIoUHLc1hnW&t=917

 

void * my_some_allocate(::std::size_t n) noexcept;

void * my_some_deallocate(void* ptr,::std::size_t n) noexcept;

 

constexpr void* my_some_allocate_constexpr(::std::size_t n) noexcept

{

                if consteval

                {

                                return ::operator new(n); // DOES NOT WORK!!

                }

                else

                {

                                return my_some_allocate(n);

                }

}

 

constexpr void* my_some_allocate_constexpr(void* ptr,::std::size_t n) noexcept

{

                if consteval

                {

                                return ::operator delete(n); // DOES NOT WORK!!

                }

                else

                {

                                return my_some_deallocate(ptr,n);

                }

}

 

template<typename T>

constexpr void* my_some_allocate_type_constexpr(::std::size_t n) noexcept

{

                if consteval

                {

                                return ::std::allocator<T>::allocate(n); // works but NOT freestanding!!

                }

                else

                {

                                return my_some_allocate(n*sizeof(T));

                }

}

 

template<typename T>

constexpr void my_some_allocate_type_constexpr(T *ptr,::std::size_t n) noexcept

{

                if consteval

                {

                                return ::std::allocator<T>::deallocate(ptr,n); // works but NOT freestanding!!

                }

                else

                {

                                return my_some_deallocate(ptr,n*sizeof(T));

                }

}

 

 

 

template<typename T>

constexpr void* my_some_allocate_type_constexpr2(::std::size_t n) noexcept

{

                if consteval

                {

                                return static_cast<T>(::operator new(n*sizeof(T))); // Not working

                }

                else

                {

                                return my_some_allocate(n*sizeof(T));

                }

}

 

template<typename T>

constexpr void my_some_allocate_type_constexpr2(T *ptr,::std::size_t n) noexcept

{

                if consteval

                {

                                ::operator delete(ptr,n*sizeof(T)); // Not working

                }

                else

                {

                                my_some_deallocate(ptr,n*sizeof(T));

                }

}

 

/*

https://github.com/microsoft/STL/issues/4002

 

*/

 

 

Regarding std::addressof:

 

Prior to C++23, std::addressof was unavailable, implying that obtaining the address of an object within a freestanding constexpr context was not possible.

 

Sent from Mail for Windows

 

 

 

Sent from Mail for Windows

 

From: trtaab trtaab
Sent: Saturday, September 2, 2023 15:35
To: std-proposals@lists.isocpp.org
Subject: RE: PR: std::allocator<T>::allocate is not freestanding

 

BTW:

::std::allocator_traits<T>::allocate with a hint has the same issues too.

Sent from Mail for Windows

 

From: trtaab trtaab
Sent: Saturday, September 2, 2023 15:22
To: std-proposals@lists.isocpp.org
Subject: PR: std::allocator<T>::allocate is not freestanding

 

Currently there is no way to allocate memory at constexpr context in freestanding environment. This desperately needs a fix.

 

N4958 does not mark std::allocator<T> as freestanding so there is no way to allocate memory in freestanding.

 

This is std::addressof situation 2.0

 

 

Sent from Mail for Windows