<div dir="ltr"><div style="color:rgb(0,0,0);background-color:rgb(255,255,254)"><div>Hi everyone,</div><div><br></div><div>I am trying to enable -ftrivial-auto-var-init=pattern on various code and noticed inconvenient inconsistency with code like [1].</div><div><br></div><div>According standard, as I understand, only the first member of the union must be initialized and the tail of the second member can stay uninitialized. If we use -ftrivial-auto-var-init=pattern it fills the tail using our pattern. However by default GCC, clang (without -ftrivial-auto-var-init), msvc all initialize entire union with 0s. Not sure if it's just coincidence or guaranteed feature.</div><div><br>So -ftrivial-auto-var-init=pattern breaks such code. Especially bad if you don't know that U is a union and ={} looks good there.<br></div><div><br></div><div>Should we consider giving up here and using zeroes for union tails even with -ftrivial-auto-var-init=pattern?</div><div><br></div><div>1. Example:<br></div><div><span style="color:rgb(0,0,255)">union</span> U {</div><div>    <span style="color:rgb(0,0,255)">  char</span> small[<span style="color:rgb(9,136,90)">2</span>];</div><div>    <span style="color:rgb(0,0,255)">  char</span> large[<span style="color:rgb(9,136,90)">100</span>]; </div><div>};</div><div><span style="color:rgb(0,0,255)">void</span> f(<span style="color:rgb(0,0,255)">void</span>*);</div><div><span style="color:rgb(0,0,255)">void</span> test() {<br></div><div>    <span style="color:rgb(0,0,255)">  union</span> U u = {};</div><div>  f(&u);</div><div>}<br></div></div></div>