stdlaunder Questions
0
std::launder intentionally obfuscates the origin of a pointer for the abstract machine / the compiler so that source and result may have different lifetimes and types. When used for e.g. (static) v...
Lepus asked 30/10, 2023 at 14:23
0
This question results from thinking about my answer in Given two objects of different types and their relative location in memory, can I derive a pointer to one object from a pointer to the other?....
Amethist asked 26/4, 2023 at 22:4
1
Solved
The following code example is from cppreference on std::launder:
alignas(Y) std::byte s[sizeof(Y)];
Y* q = new(&s) Y{2};
const int f = reinterpret_cast<Y*>(&s)->z; // Class member ...
Phallus asked 7/8, 2022 at 18:47
0
std::launder has a precondition that all bytes reachable from the would-be-returned pointer are reachable through the passed pointer.
My understanding is that this is meant to allow compiler optimi...
Foreleg asked 21/1, 2022 at 20:43
3
Solved
P0137 introduces the function template std::launder and makes many, many changes to the standard in the sections concerning unions, lifetime, and pointers.
What is the problem this paper is solvin...
Cecum asked 8/9, 2016 at 4:16
2
Solved
Basic.life/8 tells us that we can use the storage occupied by an object to create a new one after its lifetime has ended and use its original name to refer to it unless:
the type of the original ...
Caseworm asked 21/9, 2021 at 22:59
0
One of the preconditions on std::launder requires that object is within its lifetime. I assume that it is a necessary condition for being able to dereference the element. Does it mean, that if I ob...
Illfavored asked 24/3, 2021 at 15:14
1
Solved
I've just read
What is the purpose of std::launder?
and frankly, I am left scratching my head.
Let's start with the second example in @NicolBolas' accepted answer:
aligned_storage<sizeof(int), ...
Hemangioma asked 12/2, 2021 at 17:51
2
Solved
This is a code example from the C++20 spec ([basic.life]/8):
struct C {
int i;
void f();
const C& operator=( const C& );
};
const C& C::operator=( const C& other) {
if ( this...
Stackhouse asked 2/6, 2020 at 18:16
1
[1]
Are there any cases in which the addition of p0593r6 into C++20 (§ 6.7.2.11 Object model [intro.object]) made std::launder not necessary, where the same use case in C++17 required std::launder...
Beuthen asked 31/5, 2020 at 10:12
1
This is the part of the example that I don't understand:
struct Y
{
int z;
};
int main()
{
alignas(Y) std::byte s[sizeof(Y)];
Y *q = new (&s) Y{2};
const int f = reinterpret_cast<Y *>...
Counterreply asked 26/3, 2020 at 15:22
1
The std::launder function requires that every byte that would be reachable through the result is reachable through the argument. "Reachable" is defined as follows:
A byte of storage is reachable...
Arsenault asked 12/8, 2019 at 17:11
1
This question is a follow-up to: Is adding to a "char *" pointer UB, when it doesn't actually point to a char array?
In CWG 1314, CWG affirmed that it is legal to perform pointer ari...
Cranial asked 8/4, 2019 at 17:8
1
I wanted to write my own "small vector" type, and the first hurdle has been figuring out how to implement the on-stack storage.
I stumbled upon std::aligned_storage, which seems purpose-designed f...
Narvaez asked 11/3, 2019 at 1:37
1
Solved
It is like std::optional, but doesn't store an extra bool. User has to make sure to access only after initializing.
template<class T>
union FakeOptional { //Could be a normal struct in which...
Detonator asked 18/1, 2019 at 18:52
2
Solved
The current draft standard (and presumably C++17) say in [basic.compound/4]:
[ Note: An array object and its first element are not pointer-interconvertible, even though they have the same address....
Beaver asked 27/7, 2018 at 7:17
1
Solved
According to this answer, since C++17, even if a pointer has the right address and the right type dereferencing it can cause undefined behaviour.
alignas(int) unsigned char buffer[2*sizeof(int)];...
Kazimir asked 2/1, 2018 at 20:14
1
© 2022 - 2024 — McMap. All rights reserved.