public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/55449] New: [4.4.3] pure virtual call only with -O1/2/3 (boost::optional)
@ 2012-11-23 15:44 mendola at gmail dot com
  2012-11-23 16:06 ` [Bug c++/55449] " redi at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: mendola at gmail dot com @ 2012-11-23 15:44 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 55449
           Summary: [4.4.3] pure virtual call only with -O1/2/3
                    (boost::optional)
    Classification: Unclassified
           Product: gcc
           Version: 4.4.3
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: mendola@gmail.com


Created attachment 28765
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28765
test case + preprocessor output

The following code generates a pure virtual method call only when compiled with
-O1/O2/O3, the same code seems working without error with gcc 4.7.3.

The code is inlined in here and I have attached an archive containing the
preprocessor output as well.

Consider that it doesn't crash if:

- Remove the noncopyable from  B
  or
- Remove one of the two segments in the extra scope in main
  or
- Remove the try { } catch 

I have tried with boost 1.40, 1.50 and 1.52 

#include <boost/optional.hpp>
#include <boost/noncopyable.hpp>

class B : boost::noncopyable { //if the noncopyable is removed works
 public:
  virtual size_t bar() const = 0;
};

class D : public B {
 public:
  D()
  :theBar(foo(10))
  {  }

  virtual size_t bar() const {
    return theBar;
  }
 private:
  static size_t foo(const boost::optional<size_t> a) {
    if (a) { //if this is a.is_initialized() then it works
      return a.get();
    }
    return 2;
  }
  const size_t theBar;
};

class Foo {
 public:
  Foo(const B& b)
  :theBar(b.bar() * b.bar())
  { }
 private:
  const size_t theBar;
};

int main()
{
  {  //if this section is removed works
    D d;
    try {
      Foo myCompound(d);
    } catch(...) {}
  }
  {
    D d;
    try {
      Foo myCompound(d);
    } catch(...) {}
  }
}


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

end of thread, other threads:[~2012-11-24 17:49 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-23 15:44 [Bug c++/55449] New: [4.4.3] pure virtual call only with -O1/2/3 (boost::optional) mendola at gmail dot com
2012-11-23 16:06 ` [Bug c++/55449] " redi at gcc dot gnu.org
2012-11-23 16:11 ` paolo.carlini at oracle dot com
2012-11-24  6:28 ` mendola at gmail dot com
2012-11-24  6:37 ` pinskia at gcc dot gnu.org
2012-11-24  6:57 ` mendola at gmail dot com
2012-11-24  9:43 ` paolo.carlini at oracle dot com
2012-11-24 12:03 ` redi at gcc dot gnu.org
2012-11-24 12:25 ` mendola at gmail dot com
2012-11-24 14:21 ` redi at gcc dot gnu.org
2012-11-24 17:49 ` mendola at gmail dot com

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