This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug optimization/12815] New: Code compiled with optimization behaves unexpectedly


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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

           Summary: Code compiled with optimization behaves unexpectedly
           Product: gcc
           Version: 3.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: boris at kolpackov dot net
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-gnu-linux
  GCC host triplet: i686-gnu-linux
GCC target triplet: i686-gnu-linux

$ cat >test.cpp
#include <typeinfo>
#include <iostream>

using std::cerr;
using std::endl;

bool
operator== (std::type_info const* pa, std::type_info const& b)
{
  return *pa == b;
}

struct A
{
  virtual
  ~A () {}
};

struct APtr
{
  APtr (A* p)
      : p_ (p)
  {
  }

  A&
  operator* () const
  {
    return *p_;
  }

private:
  A* p_;
};

int
main ()
{
  APtr ap (new A);
  
  for(bool cont__ = true; cont__;)
  {
    cerr << "outer: cont__ " << cont__ << endl;
    
    for(std::type_info const* const exp__ ((&typeid (*ap)));
        cont__;
        cont__ = false)
    {
      cerr << "inner: cont__ " << cont__ << endl;
      
      if(cont__ &&
         exp__ == (typeid (int)) &&
         (cont__ = false, true))
      {
        cerr << "condition" << endl;        
      }
    }
  }
}

$ g++ --version
g++ (GCC) 3.3.2 (Debian)

$ g++ ./test.cpp
$ ./a.out
outer: cont__ 1
inner: cont__ 1
$ g++ -O ./test.cpp
$ ./a.out # will result in infinite loop
outer: cont__ 1
inner: cont__ 1
inner: cont__ 1
inner: cont__ 1
inner: cont__ 1
inner: cont__ 1
inner: cont__ 1
^C
$


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]