From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2310 invoked by alias); 3 Aug 2014 22:38:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 2282 invoked by uid 48); 3 Aug 2014 22:37:54 -0000 From: "wilczak at ii dot uj.edu.pl" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/62003] New: Possible bug in std::complex Date: Sun, 03 Aug 2014 22:38:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: wilczak at ii dot uj.edu.pl X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-08/txt/msg00147.txt.bz2 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 #include template 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 Complex; typedef V 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; }