From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4095 invoked by alias); 6 Oct 2010 19:44:21 -0000 Received: (qmail 4085 invoked by uid 22791); 6 Oct 2010 19:44:21 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,MISSING_MID,TW_BJ,TW_CX,TW_DC,TW_GX X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 06 Oct 2010 19:44:16 +0000 From: "muravev at yandex dot ru" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/41874] Incorrect "dereferencing type-punned pointer will break strict-aliasing rules" warning X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: muravev at yandex dot ru X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Date: Wed, 06 Oct 2010 19:44:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-10/txt/msg00563.txt.bz2 Message-ID: <20101006194400.pd3u8-uJgRkFmurJPIIHUhtaqd30s5oWHEmcuHjgmD0@z> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D41874 --- Comment #9 from Ilya Murav'jov 2010-10-06 19= :43:30 UTC --- I've come across another weird warning emission in g++ 4.4: $ cat test.cc #include struct interface_type { virtual interface_type* clone(void* storage) const { return ::new (storage) interface_type(); } }; struct poly_base { poly_base(const interface_type& x) { x.clone(data); } typedef char storage_t[100]; storage_t data; }; struct instance_t: interface_type {}; int main() { instance_t pi; poly_base p1(pi); interface_type* ptr =3D (interface_type*)(p1.data); poly_base p2(*ptr); } $ g++ -O3 -Wstrict-aliasing test.cc -o /dev/null test.cc: In function =E2=80=98int main()=E2=80=99: test.cc:12: warning: dereferencing pointer =E2=80=98ptr=E2=80=99 does break= strict-aliasing rules test.cc:25: note: initialized from here $ g++ -v Using built-in specs. Target: i486-linux-gnu Configured with: ../src/configure -v --with-pkgversion=3D'Ubuntu 4.4.1-4ubu= ntu9' --with-bugurl=3Dfile:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=3Dc,c++,fortran,objc,obj-c++ --prefix=3D/usr --enable-sh= ared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=3D/usr/lib --without-included-gettext --enable-threads=3Dposix --with-gxx-include-dir=3D/usr/include/c++/4.4 --program-suffix=3D-4.4 --ena= ble-nls --enable-clocale=3Dgnu --enable-libstdcxx-debug --enable-objc-gc --enable-targets=3Dall --disable-werror --with-arch-32=3Di486 --with-tune= =3Dgeneric --enable-checking=3Drelease --build=3Di486-linux-gnu --host=3Di486-linux-gnu --target=3Di486-linux-gnu Thread model: posix gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu9) I get this only in g++ 4.4, g++ 4.5 does not warn. I want to note that this is a different type of warning about strict-aliasi= ng rules, likely a more serious one. Can anyone tell what a difference between "warning: dereferencing type-punned pointer will break strict-aliasing rule= s" and "warning: dereferencing pointer =E2=80=98ptr=E2=80=99 does break strict= -aliasing rules"?