C++17 std::launder and aliasing
Jakub Jelinek
jakub@redhat.com
Mon Oct 24 11:47:00 GMT 2016
On Mon, Oct 24, 2016 at 01:38:13PM +0200, Richard Biener wrote:
> Certainly a possibility - though points-to information is _not_ affected
> by launder semantics. std::launder only is a memory optimization
> barrier for aliasing accesses (I believe even TBAA is valid as it
> constrains the types that can be instantiated at the place). For that
> to work you'd have to instead make it have a VDEF and (optionally)
> add special code to the stmt_may_use/clobber alias helpers.
I guess the question is if std::launder affects just the returned pointer,
or something else too.
struct A {
virtual int f();
virtual int g() { return 2; }
};
struct B : A {
virtual int f() { new (this) A; return 1; }
virtual int g() { return 1; }
};
int A::f() { new (this) B; return 2; }
static_assert(sizeof(B) == sizeof(A), "");
int main() {
A a;
int b = a.f();
int c = std::launder(&a)->g();
int d = a.g(); // Is this UB?
int e = std::launder(&a)->f();
if(b != 2 || c != 1 || d != 1 || f != 1)
std::abort();
}
Jakub
More information about the Libstdc++
mailing list