public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/62003] New: Possible bug in std::complex
@ 2014-08-03 22:38 wilczak at ii dot uj.edu.pl
  2014-08-04  9:27 ` [Bug c++/62003] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: wilczak at ii dot uj.edu.pl @ 2014-08-03 22:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62003

            Bug ID: 62003
           Summary: Possible bug in std::complex
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wilczak at ii dot uj.edu.pl

Dear MinGW users,
I have found a strange behaviour of std::complex class with double template
parameter. The program given below causes segfault (gcc-4.8.1-4, Windows) when
compiled with -O1 or -O2 flag. 

The output of the program is given below (note that the second column equal to
e=v.end() should be constant).

No errors when:
- typedef Complex=double
- parameter -O0 is used
- volatile added to definition of iterator 'e' 
volatile Vector::iterator e = u.end();
- type of variable 'p' is changed to double instead of Complex 

Daniel Wilczak

// ###########################
// Output

0x3f19b0 0x3f1a40 (0,0)
0x3f19c0 0x3f1a40 (0,0)
0x3f19d0 0x3f1a40 (0,0)
0x3f19e0 0 (0,0)
0x3f19f0 0 (0,0)
0x3f1a00 0x40000000 (0,0)
0x3f1a10 0 (0,0)
0x3f1a20 0 (0,0)
0x3f1a30 0x1 (0,0)
0x3f1a40 0x405064 (2.06124e-309,3.4598e-307)
0x3f1a50 0x6fcc43c0 (0,4.24399e-314)
0x3f1a60 0x4038dd (2.04322e-317,3.711e+261)
0x3f1a70 0x28fee8 (1.73018e-307,2.47437e+261)

// ###########################
// The program 

#include <iostream>
#include <complex>

template<class T>
struct V{
  typedef T* iterator;
  iterator begin() { return data; }
  iterator end() { return data+capacity; }
  V(unsigned c) : capacity(c) { data = new T[c]; }
  ~V(){ delete[] data; }
  T *data;
  unsigned capacity;
};

int main()
{
  typedef std::complex<double> Complex;
  typedef V<Complex> Vector;
  Vector u(9);
  Vector::iterator j = u.begin();
  Vector::iterator e = u.end();
  for(; j!=e; ++j) {
    Complex p(2.,0.);
    Complex q = *j;
    Complex z = q*p;
    std::cout << j << " " << e << " " << z << std::endl;
  }
  return 0;
}


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

end of thread, other threads:[~2014-08-04 11:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-03 22:38 [Bug c++/62003] New: Possible bug in std::complex wilczak at ii dot uj.edu.pl
2014-08-04  9:27 ` [Bug c++/62003] " redi at gcc dot gnu.org
2014-08-04 11:31 ` wilczak at ii dot uj.edu.pl
2014-08-04 11:33 ` redi at gcc dot gnu.org
2014-08-04 11:38 ` wilczak at ii dot uj.edu.pl

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