public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/41874]  New: Incorrect "dereferencing type-punned pointer will break strict-aliasing rules" warning
@ 2009-10-30  1:32 jyasskin at gmail dot com
  2009-11-06  9:09 ` [Bug c++/41874] " pinskia at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 15+ messages in thread
From: jyasskin at gmail dot com @ 2009-10-30  1:32 UTC (permalink / raw)
  To: gcc-bugs

$ cat test.cc
#include <new>
struct APInt {
    int i;
};
int main() {
    APInt I;
    char Data[sizeof(APInt)];
    new((void*)Data)APInt();
    *(APInt*)Data = I;
}
$ g++ -O3 -Wstrict-aliasing test.cc -o /dev/null
test.cc: In function 'int main()':
test.cc:9: warning: dereferencing type-punned pointer will break
strict-aliasing rules
test.cc:9: warning: dereferencing type-punned pointer will break
strict-aliasing rules

$ 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) 


The warning goes away if I change "*(APInt*)Data = I;" to "*(APInt*)(void*)Data
= I;" even though an extra cast through void* can't improve the situation wrt
strict-aliasing.


-- 
           Summary: Incorrect "dereferencing type-punned pointer will break
                    strict-aliasing rules" warning
           Product: gcc
           Version: 4.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jyasskin at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41874


^ permalink raw reply	[flat|nested] 15+ messages in thread
[parent not found: <bug-41874-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2022-12-03 22:03 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-30  1:32 [Bug c++/41874] New: Incorrect "dereferencing type-punned pointer will break strict-aliasing rules" warning jyasskin at gmail dot com
2009-11-06  9:09 ` [Bug c++/41874] " pinskia at gcc dot gnu dot org
2009-11-06  9:16 ` rguenther at suse dot de
2009-11-06  9:19 ` pinskia at gcc dot gnu dot org
2009-11-06  9:20 ` rguenth at gcc dot gnu dot org
2010-01-31  9:38 ` fw at deneb dot enyo dot de
2010-01-31 11:18 ` rguenth at gcc dot gnu dot org
     [not found] <bug-41874-4@http.gcc.gnu.org/bugzilla/>
2010-10-05  0:11 ` muravev at yandex dot ru
2010-10-05  4:49 ` fw at gcc dot gnu.org
2010-10-06 19:44 ` muravev at yandex dot ru
2010-10-06 20:57 ` rguenther at suse dot de
2012-10-15  9:27 ` paolo.carlini at oracle dot com
2012-10-15  9:45 ` rguenth at gcc dot gnu.org
2022-01-08 10:49 ` pinskia at gcc dot gnu.org
2022-12-03 22:03 ` jason at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).