public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/43978]  New: dereferencing pointer ¡®<anonymous>¡¯ does break strict-aliasing rules
@ 2010-05-03 18:47 musiphil at bawi dot org
  2010-05-03 18:48 ` [Bug c++/43978] " musiphil at bawi dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: musiphil at bawi dot org @ 2010-05-03 18:47 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3697 bytes --]

I get this warning while compiling the program below with g++-4.4.3:

$ g++ -O2 -Wall test.cc
test.cc: In function ¡®int main()¡¯:
test:8: warning: dereferencing pointer ¡®<anonymous>¡¯ does break
strict-aliasing
rules
/usr/include/c++/4.4/bits/stl_list.h:214: note: initialized from here

I don't see anything suspicious in the following program, but there
should be a reason for the warning. I asked on comp.lang.c++.moderated:
http://groups.google.com/group/comp.lang.c++.moderated/msg/fa12790662f5279d
but I couldn't get a satisfactory explanation, and someone suggested this
might be a bug of gcc.

I have searched for an existing report of this bug and found many similar
ones, but the sample codes didn't look very relevant to this problem, or
the others compiled fine without the warning. Sorry if this is a duplicate;
please feel free to mark this as a duplicate and point me to the existing
one in that case.

/*  1 */ #include <list>
/*  2 */
/*  3 */ struct X
/*  4 */ {
/*  5 */    struct P
/*  6 */    {
/*  7 */        const void* p;
/*  8 */        bool operator==(const P& o) const { return p == o.p; }
/*  9 */    };
/* 10 */
/* 11 */    typedef std::list<P> PL;
/* 12 */
/* 13 */    struct I
/* 14 */    {
/* 15 */        PL::const_iterator itr;
/* 16 */        bool operator==(I o) const { return *itr == *o.itr; }
/* 17 */        bool operator!=(I o) const { return !(*this == o); }
/* 18 */        I& operator++() { ++itr; return *this; }
/* 19 */    };
/* 20 */
/* 21 */    PL list;
/* 22 */
/* 23 */    I begin() const { I i = {list.begin()}; return i; }
/* 24 */    I end()   const { I i = {list.end()};   return i; }
/* 25 */ };
/* 26 */
/* 27 */ int main()
/* 28 */ {
/* 29 */    X x;
/* 30 */    for (X::I it = x.begin(); it != x.end(); ++it) { }
/* 31 */ }

Line 214 of /usr/include/c++/4.4/bits/stl_list.h looks like this:

/* 182 */   /**
/* 183 */    *  @brief A list::const_iterator.
/* 184 */    *
/* 185 */    *  All the functions are op overloads.
/* 186 */   */
/* 187 */   template<typename _Tp>
/* 188 */     struct _List_const_iterator
/* 189 */     {
/* ... */
/* 210 */       // Must downcast from List_node_base to _List_node to get to
/* 211 */       // _M_data.
/* 212 */       reference
/* 213 */       operator*() const
/* 214 */       { return static_cast<_Node*>(_M_node)->_M_data; }
/* ... */
/* 260 */     };

$ g++ -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-4ubuntu5'
--with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared
--enable-multiarch --enable-linker-build-id --with-system-zlib
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls
--enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc
--enable-targets=all --disable-werror --with-arch-32=i486 --with-tune=generic
--enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu
--target=i486-linux-gnu
Thread model: posix
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5)

$ uname -a
Linux localhost 2.6.32-21-generic #32-Ubuntu SMP Fri Apr 16 08:10:02 UTC 2010
i686 GNU/Linux


-- 
           Summary: dereferencing pointer ¡®<anonymous>¡¯ does break strict-
                    aliasing rules
           Product: gcc
           Version: 4.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: musiphil at bawi dot org


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/43978] dereferencing pointer ¡®<anonymous>¡¯ does break strict-aliasing rules
  2010-05-03 18:47 [Bug c++/43978] New: dereferencing pointer ¡®<anonymous>¡¯ does break strict-aliasing rules musiphil at bawi dot org
  2010-05-03 18:48 ` [Bug c++/43978] " musiphil at bawi dot org
@ 2010-05-03 18:48 ` musiphil at bawi dot org
  2010-05-03 19:47 ` paolo dot carlini at oracle dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: musiphil at bawi dot org @ 2010-05-03 18:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from musiphil at bawi dot org  2010-05-03 18:48 -------
Created an attachment (id=20550)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20550&action=view)
the preprocessed file


-- 


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/43978] dereferencing pointer ¡®<anonymous>¡¯ does break strict-aliasing rules
  2010-05-03 18:47 [Bug c++/43978] New: dereferencing pointer ¡®<anonymous>¡¯ does break strict-aliasing rules musiphil at bawi dot org
@ 2010-05-03 18:48 ` musiphil at bawi dot org
  2010-05-03 18:48 ` musiphil at bawi dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: musiphil at bawi dot org @ 2010-05-03 18:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from musiphil at bawi dot org  2010-05-03 18:48 -------
Created an attachment (id=20549)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20549&action=view)
the source file that triggers the warning


-- 


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/43978] dereferencing pointer ¡®<anonymous>¡¯ does break strict-aliasing rules
  2010-05-03 18:47 [Bug c++/43978] New: dereferencing pointer ¡®<anonymous>¡¯ does break strict-aliasing rules musiphil at bawi dot org
  2010-05-03 18:48 ` [Bug c++/43978] " musiphil at bawi dot org
  2010-05-03 18:48 ` musiphil at bawi dot org
@ 2010-05-03 19:47 ` paolo dot carlini at oracle dot com
  2010-05-03 19:53 ` paolo dot carlini at oracle dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: paolo dot carlini at oracle dot com @ 2010-05-03 19:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from paolo dot carlini at oracle dot com  2010-05-03 19:47 -------
Richard, can you have a look? It is the same as 42032?


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu dot
                   |                            |org


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/43978] dereferencing pointer ¡®<anonymous>¡¯ does break strict-aliasing rules
  2010-05-03 18:47 [Bug c++/43978] New: dereferencing pointer ¡®<anonymous>¡¯ does break strict-aliasing rules musiphil at bawi dot org
                   ` (2 preceding siblings ...)
  2010-05-03 19:47 ` paolo dot carlini at oracle dot com
@ 2010-05-03 19:53 ` paolo dot carlini at oracle dot com
  2010-05-04  9:59 ` rguenth at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: paolo dot carlini at oracle dot com @ 2010-05-03 19:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from paolo dot carlini at oracle dot com  2010-05-03 19:53 -------
For sure cannot be reproduced with 4.5 and mainline.


-- 


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/43978] dereferencing pointer ¡®<anonymous>¡¯ does break strict-aliasing rules
  2010-05-03 18:47 [Bug c++/43978] New: dereferencing pointer ¡®<anonymous>¡¯ does break strict-aliasing rules musiphil at bawi dot org
                   ` (3 preceding siblings ...)
  2010-05-03 19:53 ` paolo dot carlini at oracle dot com
@ 2010-05-04  9:59 ` rguenth at gcc dot gnu dot org
  2010-05-04 10:01 ` rguenth at gcc dot gnu dot org
  2010-05-04 12:06 ` paolo dot carlini at oracle dot com
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-05-04  9:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from rguenth at gcc dot gnu dot org  2010-05-04 09:59 -------
(In reply to comment #4)
> For sure cannot be reproduced with 4.5 and mainline.

Because we removed the code that emitted this warning.


-- 


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/43978] dereferencing pointer ¡®<anonymous>¡¯ does break strict-aliasing rules
  2010-05-03 18:47 [Bug c++/43978] New: dereferencing pointer ¡®<anonymous>¡¯ does break strict-aliasing rules musiphil at bawi dot org
                   ` (4 preceding siblings ...)
  2010-05-04  9:59 ` rguenth at gcc dot gnu dot org
@ 2010-05-04 10:01 ` rguenth at gcc dot gnu dot org
  2010-05-04 12:06 ` paolo dot carlini at oracle dot com
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-05-04 10:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from rguenth at gcc dot gnu dot org  2010-05-04 10:01 -------
(In reply to comment #3)
> Richard, can you have a look? It is the same as 42032?

I am pretty sure it is.


-- 


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/43978] dereferencing pointer ¡®<anonymous>¡¯ does break strict-aliasing rules
  2010-05-03 18:47 [Bug c++/43978] New: dereferencing pointer ¡®<anonymous>¡¯ does break strict-aliasing rules musiphil at bawi dot org
                   ` (5 preceding siblings ...)
  2010-05-04 10:01 ` rguenth at gcc dot gnu dot org
@ 2010-05-04 12:06 ` paolo dot carlini at oracle dot com
  6 siblings, 0 replies; 8+ messages in thread
From: paolo dot carlini at oracle dot com @ 2010-05-04 12:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from paolo dot carlini at oracle dot com  2010-05-04 12:05 -------
Ok, let's resolve it as duplicate, then.

*** This bug has been marked as a duplicate of 42032 ***


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-05-04 12:06 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-03 18:47 [Bug c++/43978] New: dereferencing pointer ¡®<anonymous>¡¯ does break strict-aliasing rules musiphil at bawi dot org
2010-05-03 18:48 ` [Bug c++/43978] " musiphil at bawi dot org
2010-05-03 18:48 ` musiphil at bawi dot org
2010-05-03 19:47 ` paolo dot carlini at oracle dot com
2010-05-03 19:53 ` paolo dot carlini at oracle dot com
2010-05-04  9:59 ` rguenth at gcc dot gnu dot org
2010-05-04 10:01 ` rguenth at gcc dot gnu dot org
2010-05-04 12:06 ` paolo dot carlini at oracle dot com

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