2017-04-07 17:21 GMT+02:00 David Grayson <[email protected]>:
>> type1 *foo(const type1 *my_const_ptr)
>> {
>> union {
>>   type1 *t1;
>>   const type1 *ct1;
>> } v;
>> v.ct1 = my_const_ptr;
>> return v.t1;
>> }
>
> Yes, that is sad, and it seems like just a matter of time before a C++
> compiler looks at the code above and reasons that the write to ct1 can be
> optimized away because there is no code that ever reads from ct1.  Thus the
> read from t1 will be recognized as undefined behavior (probably called a
> poison value in LLVM) and anything could happen.

LOL  ... if a compiler modifies a technical valid language construct,
and produces by this optimization something it needs to warn about,
then the compiler has a bug.  And well, you should be sad to use such
a compiler, as it is broken in many aspects.


> What was the problem with Mateusz's patch?  I think people are implying it
> results in compiler warnings, but I thought casting a pointer to a pointer
> usually doesn't give any warnings.

The problem is that you seems to see an UB, where actually none is.
Please try read a bit about C++, compatibility to C, and what, and how
a union on pointer types are treated in a union (especially the part
about integer scalars & pointers).

~Kai

PS: As you already recognized, yes the issue is to avoid warnings OP
doesn't expect them.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to