The attached Triple.i, when compiled with `g++ -c -O2 -Wstrict-aliasing Triple.i`, returns: Triple.i: In function 'void setOSName(const StringRef&)': Triple.i:9: warning: dereferencing pointer '<anonymous>' does break strict-aliasing rules Triple.i:9: note: initialized from here Line 9 is: if (LHSKind == TwineKind) return static_cast<const Twine *>(LHS)->LHSKind; I believe the warning is incorrect since when LHSKind == TwineKind, LHS is only assigned a Twine*. There's no aliasing through the void*. (And in this subprogram, LHSKind is in fact never ==TwineKind.) The warning goes away if I delete the __builtin_expect. $ g++ -v Using built-in specs. Target: i386-apple-darwin9 Configured with: ../gcc-4.4.1/configure --prefix=/opt/local --build=i386-apple-darwin9 --enable-languages=c,c++,objc,obj-c++,java,fortran --libdir=/opt/local/lib/gcc44 --includedir=/opt/local/include/gcc44 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-4.4 --with-gxx-include-dir=/opt/local/include/gcc44/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local Thread model: posix gcc version 4.4.1 (GCC)
Created attachment 18908 [details] File with incorrect strict-aliasing warning
> There's no aliasing through the void*. This is not true. In fact aliasing is not about what the type of the pointers are but what the dynamic type of what the pointer points to and the access type. But that is not the issue here though.
Works on the trunk.
The test case from attachment 18908 [details] compiles with just a -Wunused-parameter warning on trunk. Resolving as fixed. t.c: In function ‘Twine operator+(const Twine&, const Twine&)’: t.c:16:63: warning: unused parameter ‘RHS’ [-Wunused-parameter] inline Twine operator + (const Twine & LHS, const Twine & RHS) { ^~~