Consider these two functions:
int f1()
{
alignas(int) char buf[sizeof(int)] = {};
return *reinterpret_cast<int*>(buf);
}
int f2()
{
alignas(int) char buf[sizeof(int)] = {};
char* ptr = buf;
return *reinterpret_cast<int*>(ptr);
}
GCC warns that the first violates strict-aliasing rules. But the second is OK.
Clang accepts both without complaint.
Is the warning legitimate?
char
or the array ofchar
s and the glvalue is of typeint
; nothing in timsong-cpp.github.io/cppwp/basic.lval#8 covers this case. – Culbreth