public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/2860: incorrectly initialized auto variable
@ 2001-08-11 12:31 gdr
  0 siblings, 0 replies; 2+ messages in thread
From: gdr @ 2001-08-11 12:31 UTC (permalink / raw)
  To: kainz, gcc-bugs, gcc-prs, gdr, jimh, kainz, nobody

Synopsis: incorrectly initialized auto variable

Responsible-Changed-From-To: unassigned->gdr
Responsible-Changed-By: gdr
Responsible-Changed-When: Sat Aug 11 12:31:42 2001
Responsible-Changed-Why:
    Analyzed.
State-Changed-From-To: open->closed
State-Changed-By: gdr
State-Changed-When: Sat Aug 11 12:31:42 2001
State-Changed-Why:
    Fixed in GCC-3.0.1

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=2860&database=gcc


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

* c++/2860: incorrectly initialized auto variable
@ 2001-05-17 17:46 kainz
  0 siblings, 0 replies; 2+ messages in thread
From: kainz @ 2001-05-17 17:46 UTC (permalink / raw)
  To: gcc-gnats; +Cc: jimh

>Number:         2860
>Category:       c++
>Synopsis:       incorrectly initialized auto variable
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Thu May 17 17:46:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Florian Kainz
>Release:        gcc version 3.0 20010514 (prerelease)
>Organization:
>Environment:
% g++ -v
Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.0/specs
Configured with: ../gcc-20010514/configure --enable-threads --prefix=/usr/local --enable-languages=c,c++
Thread model: posix
gcc version 3.0 20010514 (prerelease)
>Description:
-O3 appears to (incorrectly) optimize away part
of the initialization code for an auto variable.
>How-To-Repeat:
Compile the program below with

    g++ -O3 xxx.C

and run the resulting executable;
it should print:

    a1: 1, 2, 3, 4
    a2: 1.5, 2.5, 3.5, 4.5

Instead, it prints:

    a1: 1, 2, 3, 4
    a2: 1.4013e-45, 2.8026e-45, 3.5, 4.5

//
// xxx.C
//

#include <iostream>

template <class T>
struct Vec2
{
    T x, y;
    Vec2 ()                     {}
    Vec2 (T a, T b)             {x = a; y = b;}
    Vec2 (const Vec2 &v)        {x = v.x; y = v.y;}
};

typedef Vec2 <int>    V2i;
typedef Vec2 <float>  V2f;

template <class T>
struct Box
{
    T min;
    T max;
    Box(const T& minT, const T& maxT) {min = minT; max = maxT;}
};

typedef Box <V2i> Box2i;
typedef Box <V2f> Box2f;

int
main ()
{
    Box2i a1 (V2i (1, 2),     V2i (3, 4));
    Box2f a2 (V2f (1.5, 2.5), V2f (3.5, 4.5));

    std::cout << "a1: " <<
                 a1.min.x << ", " <<
                 a1.min.y << ", " <<
                 a1.max.x << ", " <<
                 a1.max.y << std::endl;

    std::cout << "a2: " <<
                 a2.min.x << ", " <<
                 a2.min.y << ", " <<
                 a2.max.x << ", " <<
                 a2.max.y << std::endl;
}
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


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

end of thread, other threads:[~2001-08-11 12:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-11 12:31 c++/2860: incorrectly initialized auto variable gdr
  -- strict thread matches above, loose matches on Subject: below --
2001-05-17 17:46 kainz

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