by satbyy · 10y ago · 0 comments
return *(uint32_t*)f;
should read as: return *(uint32_t*)(&f);
With this change, the code indeed compiles fine (with g++ 5.3.1; not sure of 5.3.0, which the author used)... if no argument values exist such that an invocation of the function or constructor could be an evaluated subexpression of a core constant expression, the program is ill-formed; no diagnostic required.
clang seems to go the extra mile and produces a diagnostic.
Incidentally the pointer cast would violate C++'s aliasing rules and thus invoke undefined behavior.
P.S: The C++14 Standard is available here: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n429... (never mind the "draft" status)
warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
So, you're right indeed.