The following very simple program is giving me a warning with g++ 4.4.2 with
-Wall (or -Wstrict-aliasing=1, 2 or 3).  I don't think it should be giving the
warning, so I think this is a bug. 

Replacing std::complex with a simple user-defined complex-like class makes the
warning go away, so maybe there is a bug in the complex class? 

Also, replacing the virtual inheritance with normal inheritance makes the
warning go away.  

Likewise removing the A class and moving the virtual inheritance to C : virtual
public B.

Or if I make the argument of foo a reference.

===========================================================
#include <complex>

struct A { 
    virtual int value() const=0; 
};

struct B : virtual public A { 
    bool isOne() const { return A::value() == 1; } 
};

struct C : public B { 
    int value() const { return 1; } 
};

struct D {
    void foo(std::complex<float> x) const; // foo is extern
};

void callFoo()
{
    C c;
    D d;
    if (c.isOne()) d.foo(0);
}
===========================================================


The warning produced is:

>g++-4 -c -O2 -Wstrict-aliasing foo.cpp 
foo.cpp: In function ‘void callFoo()’:
foo.cpp:9: warning: dereferencing pointer ‘<anonymous>’ does break
strict-aliasing rules
foo.cpp:9: note: initialized from here

This appears to me to be different from similar bugs: 41838, 39390 which
reference the same warning, but maybe it is related.


-- 
           Summary: spurious strict-aliasing warning
           Product: gcc
           Version: 4.4.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: michael at jarvis dot net
 GCC build triplet: i686-apple-darwin9
  GCC host triplet: i686-apple-darwin9
GCC target triplet: i686-apple-darwin9


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

Reply via email to