olli
Anonymous
Anonymous
cast
Anonymous
but this is not made for C++
Anonymous
it is made for C
olli
Anonymous
Which cast?
reinterpret cast into a uint32_t* then dereference this
olli
Remember alias rules exist for casts as well
olli
Anonymous
put this value inside the result.u32
Anonymous
olli
olli
Which of the rules applies?
olli
To make it valid
Anonymous
Anonymous
adhering to the C++ standard still nothing
olli
Do you think g++ is 100% ISO conform?
Anonymous
both pointed at types of uint32_t and uint8_t are similar
Anonymous
and you can send it in as a uint8_t* which he did
Anonymous
so if you are super anal about it you can go:
result.u32 = *((uint32_t*) data);
BinaryByter
ub doesnt mean that it HAS to break
Anonymous
olli
Anonymous
there is NO warning
Anonymous
still in C++
Anonymous
same file i sent here
Dima
BinaryByter
ub doesnt have to be warned for
Anonymous
Anonymous
Anonymous
see i even added -fsanitize
Anonymous
then find me a compiler which says it is undefined
Anonymous
it is easy for people who never wrote the C++ compiler to claim it is undefined but until you can physically prove it with ANY compiler
Anonymous
we have to say it is defined as the only compilations shown say it is defined
BinaryByter
in that case, the compiler either didn't catch it or isn't standard compliant
Anonymous
G++ is standard compilant
BinaryByter
no compiler is
olli
BinaryByter
no C++ compiler is*
olli
BinaryByter
clang might actually catch that UB
BinaryByter
but its still not compliant
Anonymous
Anonymous
what is that?
Anonymous
IT IS DEFINED
Anonymous
it is all local scoped
Anonymous
there is no strict aliasing as he uses array accesses
Anonymous
and copies those over
Anonymous
olli
what is that?
Please show me the section in the standard that makes it well defined
Anonymous
this is under local scope
BinaryByter
Anonymous
https://isocpp.org/files/papers/n4296.pdf
section 3.3.7
Anonymous
3.3.3 Block scope
[basic.scope.block]
1
A name declared in a block (6.3) is local to that block; it has
block scope
. Its potential scope begins at its
point of declaration (3.3.2) and ends at the end of its block. A variable declared at block scope is a
local
variable
.
2
The potential scope of a function parameter name (including one appearing in a
lambda-declarator
) or of
a function-local predefined variable in a function definition (8.4) begins at its point of declaration. If the
function has a
function-try-block
the potential scope of a parameter or of a function-local predefined variable
ends at the end of the last associated handler, otherwise it ends at the end of the outermost block of
the function definition. A parameter name shall not be redeclared in the outermost block of the function
definition nor in the outermost block of any handler associated with a
function-try-block
.
3
The name declared in an
exception-declaration
is local to the
handler
and shall not be redeclared in the
outermost block of the
handler
.
4
Names declared in the
for-init-statement
, the
for-range-declaration
, and in the
condition
of
if
,
while
,
for
,
and
switch
statements are local to the
if
,
while
,
for
, or
switch
statement (including the controlled
statement), and shall not be redeclared in a subsequent condition of that statement nor in the outermost
block (or, for the
if
statement, any of the outermost blocks) of the controlled statement; see 6.4.
my bad 3.3.3
Anonymous
Anonymous
for future reference cppreference is actually not affliated with the C++ standards
BinaryByter
this is not about "names"
@oleg
Anonymous
Anonymous
Anonymous
Anonymous
Anonymous
not found
Anonymous
that one is still being drafted
Anonymous
it is not valid until it is finished the review stage
Anonymous
https://github.com/cplusplus/draft/blob/master/papers/n4659.pdf
just read the first page
Anonymous
olli
Anonymous
Anonymous
everyone can
olli
Where?
olli
Your link also provides only a working draft