std::aligned_storage and [[gnu::may_alias]]

Avi Kivity avi@scylladb.com
Tue Jun 20 21:20:00 GMT 2017


Does std::aligned_storage need a [[gnu::may_alias]] attribute?


According to 
http://en.cppreference.com/w/cpp/language/reinterpret_cast#Type_aliasing, 
it is not legal to cast a char array into another type (that is not a 
relative of char*).


According to the example in 
http://en.cppreference.com/w/cpp/types/aligned_storage, it's perfectly 
all right to cast std::aligned_storage::data to some arbitrary T; and it 
would be hard to find a use for aligned_storage without it.


std::function uses [[gnu::may_alias]] in a situation where 
std::aligned_storage may be used.


Is this a problem in libstdc++, the standard, or my understanding of the 
strict aliasing rules?



More information about the Gcc-help mailing list