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?