[libcxx-commits] [PATCH] D82627: Fix CFI issues in <future>

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jul 17 08:15:52 PDT 2020


ldionne added a comment.

In D82627#2156893 <https://reviews.llvm.org/D82627#2156893>, @eugenis wrote:

> @HAPPY 
>  I'm not an expert, but I've heard that such casts are UB somewhere.
>  Looking at  [basic.life] 6.8/6 in c++17
>
> > Before the lifetime of an object has started but after the storage which the object will occupy has been allocated [...] any pointer that represents the address of the storage location where the object will be or was located may be used but only in limited ways. [...] 
> >  The program has undefined behavior if:
> >  [...]
> > 
> > - the pointer is used as the operand of a static_cast (8.2.9), except when the conversion is to pointer to cv void, or to pointer to cv void and subsequently to pointer to cv char, cv unsigned char, or cv std::byte (21.2.1),[...]


That's a good find. However, in this case, what we do is not a `static_cast`. It's a C-style cast from an unrelated type (`std::aligned_storage<...>::type`) to `__base*` (for example in the expression `(__base*)&__buf_`), which is actually equivalent to a `reinterpret_cast` unless I'm mistaken. Do you agree?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82627/new/

https://reviews.llvm.org/D82627





More information about the libcxx-commits mailing list