This, plus #10714 avoids adding new compile-time warnings in 15.
Fixes a warning added in #10792.
utACK
utACK
utACK a8a602eeece2cfd847a361127fe7f41b26f13c26
219 | @@ -220,7 +220,10 @@ class prevector { 220 | } 221 | } 222 | 223 | - prevector() : _size(0) {} 224 | + prevector() : _size(0) { 225 | + // Explicitly initialize indirect ptr to avoid "used uninitialized" warning 226 | + _union.indirect = nullptr;
I was vaguely concerned that this assignment violates type punning through a union, but (1) some sources say that is permitted anyway (2) the other type is char (for which exceptions to type punning exist) and (3) we'll write to the union again before ever using data in it.
I though type-punning through an union was the only acceptable way to do it?
From IRC: <cfields> sipa: why not use aggregate initialization: prevector() : _size(0), _union{{}} <cfields> or give the union a ctor?
I can't reproduce the warning, so I can't be sure that it satisfies whatever compiler is complaining, but the above compiles fine for me, and I'd think that initializing via a ctor would work otherwise.
@laanwj There is a faction of language wonks/compiler folks that argues that it is never acceptable (except with char) per the language specs; -- and I believe there is nothing in any of the C++ standards that make it clear that its kosher (though sipa tells me apparently C11 has something explicit). Since having no way to do it is not a very realistic position it doesn't reflect the behavior of compilers today. Generally better to avoid it at least where its convenient, or at least be aware that someday it might become non-kosher depending on which evil spirits control the souls of the compiler authors next week. :)
I'm super not convinced this is an issue. If we're really concerned, easiest fix is probably require C11 and turn prevector into C++ wrapper around C. More realistically, gcc explicitly supports this, and I believe many other compilers as well.
utACK
ACK
Please fix typo in the second commit message (initizlie).
OK, took @theuni's version (which has no warnings for me).
Warning from gcc 7.1 is ./prevector.h:450:25: warning:
'*((void*)(&<anonymous>)+8).prevector<28, unsigned char>::_union.prevector<28, unsigned char>::direct_or_indirect::<anonymous>.prevector<28, unsigned char>::direct_or_indirect::<unnamed struct>::indirect'
may be used uninitialized in this function [-Wmaybe-uninitialized]
utACK c73b8be2440e424f304fda22e43240e8b90f9b00