Hi,<div><br></div><div><div>Just spent about an hour to narrow down this.  </div><div><br></div><div>For the program below. clang 3.1 returns "different" unless you optimize it with -O2 or higher.  In gcc 4.2 and VC,  the code always return "same" no matter in -O0 or -O2. </div>
<div><br></div><div>I guess this means clang doesn't do const string consolidation by default. Is there any switch to make clang do this consolidation in -O0?</div><div><br></div><div>Or can Clang dev team can make this consolidate as default?</div>
<div>I hope this make sense. since it's kind of 'de facto' in other compilers, some code was written with this assumption, they know all the keys are from const strings so they do pointer compare instead string compare. There're might be more code relies on this behavior. </div>
<div><br></div><div><div>#include <stdio.h></div><div>#define LAYER_KEY L"Layer"</div><div>struct TEST {</div><div>  const wchar_t* key;</div><div>}gTESTINFO = {</div><div>    LAYER_KEY</div><div>};</div><div>
<br></div><div>int main() {</div><div>    const wchar_t* key = LAYER_KEY;</div><div><br></div><div>    if (gTESTINFO.key == key)</div><div>        printf("same\n");</div><div>    else</div><div>        printf("different\n"); </div>
<div>    return 0;</div><div>}</div></div><div><div><div><div><br></div></div><div>Thanks!</div><div><div><br></div>-- <br>Yingshen(Jonny) Yu<br><br>
</div></div></div></div>