It seems so that for optimization levels one or higher, gcc produces wrong code
for the two test files below.
If I compile the same test with -O or -Os everything works fine.
On taking a look into produced assembly, it seems that it wrongly assumes the
assert alway have to raise.

File 1: t1.cpp
      //class.h
      struct K {
       static const unsigned k;
      };

      #include <assert.h>

      int main() {
       assert ( K::k == 1 );
       return 1;
      }

File 2: t2.cpp
      struct K {
       static const unsigned k;
      };

      //class.cpp
      const unsigned K::k = 1;

Then compile both file g++ -o tst t1.cpp t2.cpp -O2


-- 
           Summary: Wrong code in c++ for const members initialized in
                    external file
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ktietz at gcc dot gnu dot org
GCC target triplet: x86_64-pc-mingw32


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

Reply via email to