public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54325] New: C++11 uniform initialization syntax for argument-less abstract base class constructor fails
@ 2012-08-19 18:29 moritz at bunkus dot org
  2012-09-07 21:35 ` [Bug c++/54325] " drtwox at tpg dot com.au
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: moritz at bunkus dot org @ 2012-08-19 18:29 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 54325
           Summary: C++11 uniform initialization syntax for argument-less
                    abstract base class constructor fails
    Classification: Unclassified
           Product: gcc
           Version: 4.7.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: moritz@bunkus.org


Using {} syntax for base class initialization fails with "cannot allocate an
object of abstract type 'Base'" for abstract base classes with argument-less
constructors. I'll include two code samples. The first one does work with g++
4.6.1 (Ubuntu 11.10), g++ 4.6.3 (Ubuntu 12.04) and clang 3.1 but does NOT work
with g++ 4.7.0 (Ubuntu 12.04) and g++ 4.7.1 (self-compiled). The second one
works with 4.7.0 and 4.7.1 as well.

Example code that does NOT work with 4.7.x but does with older versions/other
compilers:

class Base {
public:
  Base() {};
  virtual ~Base() {};

  virtual void do_stuff() = 0;
};

class Derived: public Base {
public:
  Derived() : Base{} {};
  virtual ~Derived() {};

  virtual void do_stuff() {};
};

int
main() {
  Derived d;

  return 0;
}


Changing Base's constructor to take an additional argument lets it work
suddenly:

class Base {
public:
  int m_dummy;

  Base(int dummy): m_dummy{dummy} {};
  virtual ~Base() {};

  virtual void do_stuff() = 0;
};

class Derived: public Base {
public:
  Derived() : Base{42}  {};
  virtual ~Derived() {};

  virtual void do_stuff() {};
};

int
main() {
  Derived d;

  return 0;
}

$ ~/opt/gcc/4.7.1/bin/g++ -v
Using built-in specs.
COLLECT_GCC=/home/mosu/opt/gcc/4.7.1/bin/g++
COLLECT_LTO_WRAPPER=/home/mosu/opt/gcc/4.7.1/libexec/gcc/x86_64-unknown-linux-gnu/4.7.1/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --enable-checking=release --enable-languages=c,c++
--prefix=/home/mosu/opt/gcc/4.7.1
Thread model: posix
gcc version 4.7.1 (GCC)

Actual error message:

$ ~/opt/gcc/4.7.1/bin/g++ -std=c++11 -o fails fails.cpp
fails.cpp: In constructor ‘Derived::Derived()’:
fails.cpp:11:20: error: cannot allocate an object of abstract type ‘Base’
fails.cpp:1:7: note:   because the following virtual functions are pure within
‘Base’:
fails.cpp:6:16: note:   virtual void Base::do_stuff()


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

end of thread, other threads:[~2013-01-02 21:06 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-19 18:29 [Bug c++/54325] New: C++11 uniform initialization syntax for argument-less abstract base class constructor fails moritz at bunkus dot org
2012-09-07 21:35 ` [Bug c++/54325] " drtwox at tpg dot com.au
2012-10-01 16:56 ` [Bug c++/54325] [4.7/4.8 Regression] " paolo.carlini at oracle dot com
2012-11-19 13:34 ` jakub at gcc dot gnu.org
2012-11-20 19:09 ` paolo.carlini at oracle dot com
2012-11-21  0:41 ` paolo.carlini at oracle dot com
2012-11-21  3:14 ` paolo.carlini at oracle dot com
2012-12-03 15:42 ` rguenth at gcc dot gnu.org
2012-12-07  4:55 ` jason at gcc dot gnu.org
2012-12-07  5:14 ` jason at gcc dot gnu.org
2012-12-07  5:16 ` jason at gcc dot gnu.org
2012-12-27  8:41 ` paolo.carlini at oracle dot com
2013-01-02 20:55 ` jason at gcc dot gnu.org
2013-01-02 20:57 ` jason at gcc dot gnu.org
2013-01-02 21:06 ` jason at gcc dot gnu.org

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