Questions tagged [stdlaunder]

25 questions
3
votes
0 answers

Can I leave dynamic memory for std::complex uninitialized after allocation?

I have a container library that initializes elements only if they are not "is_trivially_default_constructible". In principle, I use the std::is_trivially_default_constructible trait to determine this. I think this should work if the trait reflects…
alfC
  • 14,261
  • 4
  • 67
  • 118
3
votes
1 answer

std::launder with inplace polymorphic containers

I am doing a somewhat nontrivial project in C++ for the Game Boy Advance, and, being such a limited platform with no memory management at all, I am trying to avoid calls to malloc and dynamic allocation. For this, I have implemented a fair amount…
JoaoBapt
  • 195
  • 1
  • 11
2
votes
0 answers

Does implicit object creation circumvent reachability conditions of std::launder?

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?. My assumption was that the standard currently…
user17732522
  • 53,019
  • 2
  • 56
  • 105
2
votes
1 answer

reachability with std::launder

I'm trying to understand the following snippet from CPP reference. Can someone explain in a little more detail why x2[1] is unreachable from source ? Can't we reach it via &x2[0][0] + 10 for example? int x2[2][10]; auto p2 =…
user3882729
  • 1,339
  • 8
  • 11
2
votes
1 answer

How to get float bit representation without UB in C++?

As far as I know, all 'traditional' ways of doing this, namely reinterpret_cast of a pointer and union with int and float fields are UB as violation of strict aliasing (in C++, not in C). So, how to do it correctly without undefined behavior? Can I…
Amomum
  • 6,217
  • 8
  • 34
  • 62
1
vote
1 answer

std::launder do not work on gcc with -O3 option?

I have code snippet that, I assume, should not produce asserton failure. But with gcc 13.2 with O3 option it fails. So I think it is Undefined Behaviour here. clang and gcc with O0 works fine. And if I change destructor to some other method -…
1
vote
0 answers

When to use std::launder?

I've read a few Q/A about std::launder (What is the purpose of std::launder?, Does this really break strict-aliasing rules?, std::launder reachability rules), but am still unclear whether I am using it correctly in my specific use-case. The…
Jeff G
  • 4,470
  • 2
  • 41
  • 76
1
vote
0 answers

Storage reuse Undefined behaviour

Reading in the cppreference for lifetime, there is the following statement for storage reuse A program is not required to call the destructor of an object to end its lifetime if the object is trivially-destructible or if the program does not rely…
getsoubl
  • 808
  • 10
  • 25
0
votes
1 answer

On std::launder, GCC and clang: why such a different behavior?

I was tinkering with the example given on the cppreference launder web page. The example shown below suggest that either I misunderstood something and introduced UB or that there is a bug somewhere or that clang is to lax or too good. In doit1(), I…
Etienne M
  • 604
  • 3
  • 11
0
votes
0 answers

using std::launder to implement memory buffer

I apologize if this has been answered before, I just fail to find the precise answer to the questions at the end. Here is a simplified version of collection. template struct my_collection { T* buffer_start = nullptr; std::size_t…
1
2