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
* [Bug c++/54325] C++11 uniform initialization syntax for argument-less abstract base class constructor fails
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 ` 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
` (12 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: drtwox at tpg dot com.au @ 2012-09-07 21:35 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54325
drtwox at tpg dot com.au changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |drtwox at tpg dot com.au
--- Comment #1 from drtwox at tpg dot com.au 2012-09-07 21:34:57 UTC ---
The failing example can be simplified somewhat.
class base
{
protected:
base()
{}
};
class derived : public base
{
public:
derived()
: base{} // <-- Note the c++11 curly brace syntax
{}
};
int main()
{
derived d1;
return 0;
}
Output:
$ g++-4.7 -std=c++11 -Wall -Wextra -pedantic curly.cpp -o curly
curly.cpp: In constructor ‘derived::derived()’:
curly.cpp:4:13: error: ‘base::base()’ is protected
curly.cpp:19:24: error: within this context
Replace g++4.7 with g++4.6 or clang++3.1 and it compiles without warnings or
errors.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/54325] [4.7/4.8 Regression] C++11 uniform initialization syntax for argument-less abstract base class constructor fails
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 ` paolo.carlini at oracle dot com
2012-11-19 13:34 ` jakub at gcc dot gnu.org
` (11 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-10-01 16:56 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54325
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2012-10-01
Summary|C++11 uniform |[4.7/4.8 Regression] C++11
|initialization syntax for |uniform initialization
|argument-less abstract base |syntax for argument-less
|class constructor fails |abstract base class
| |constructor fails
Ever Confirmed|0 |1
--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-10-01 16:56:21 UTC ---
Looks like a regression then.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/54325] [4.7/4.8 Regression] C++11 uniform initialization syntax for argument-less abstract base class constructor fails
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
` (10 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-11-19 13:34 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54325
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org,
| |jason at gcc dot gnu.org
Target Milestone|--- |4.7.3
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-11-19 13:33:41 UTC ---
I think this is probably caused by
http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175674 change.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/54325] [4.7/4.8 Regression] C++11 uniform initialization syntax for argument-less abstract base class constructor fails
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
` (2 preceding siblings ...)
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
` (9 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-20 19:09 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54325
--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-11-20 19:08:21 UTC ---
I just tried and r175673 also rejects the reduced code in Comment #1. Let's see
if I can find the exact revision where we regressed.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/54325] [4.7/4.8 Regression] C++11 uniform initialization syntax for argument-less abstract base class constructor fails
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
` (3 preceding siblings ...)
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
` (8 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-21 0:41 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54325
--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-11-21 00:41:19 UTC ---
We regressed with r175639, the implementation of DR 990:
http://gcc.gnu.org/ml/gcc-cvs/2011-06/msg01130.html
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/54325] [4.7/4.8 Regression] C++11 uniform initialization syntax for argument-less abstract base class constructor fails
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
` (4 preceding siblings ...)
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
` (7 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-21 3:14 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54325
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|minor |normal
--- Comment #6 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-11-21 03:14:14 UTC ---
It seems that the build_value_init calls added by r175639 have issues because
it doesn't have the information that the value initialization is happening from
the default constructor of a derived type.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/54325] [4.7/4.8 Regression] C++11 uniform initialization syntax for argument-less abstract base class constructor fails
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
` (5 preceding siblings ...)
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
` (6 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-12-03 15:42 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54325
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |rejects-valid
Priority|P3 |P2
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/54325] [4.7/4.8 Regression] C++11 uniform initialization syntax for argument-less abstract base class constructor fails
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
` (6 preceding siblings ...)
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
` (5 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu.org @ 2012-12-07 4:55 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54325
--- Comment #7 from Jason Merrill <jason at gcc dot gnu.org> 2012-12-07 04:54:42 UTC ---
Author: jason
Date: Fri Dec 7 04:54:27 2012
New Revision: 194284
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=194284
Log:
PR c++/54325
* tree.c (build_aggr_init_expr): Don't check for abstract class.
Added:
trunk/gcc/testsuite/g++.dg/cpp0x/initlist-pure.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/tree.c
trunk/gcc/testsuite/g++.dg/other/abstract3.C
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/54325] [4.7/4.8 Regression] C++11 uniform initialization syntax for argument-less abstract base class constructor fails
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
` (7 preceding siblings ...)
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
` (4 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu.org @ 2012-12-07 5:14 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54325
--- Comment #8 from Jason Merrill <jason at gcc dot gnu.org> 2012-12-07 05:13:42 UTC ---
Author: jason
Date: Fri Dec 7 05:13:33 2012
New Revision: 194290
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=194290
Log:
PR c++/54325
* tree.c (build_aggr_init_expr): Don't check for abstract class.
Added:
branches/gcc-4_7-branch/gcc/testsuite/g++.dg/cpp0x/initlist-pure.C
Modified:
branches/gcc-4_7-branch/gcc/cp/ChangeLog
branches/gcc-4_7-branch/gcc/cp/tree.c
branches/gcc-4_7-branch/gcc/testsuite/g++.dg/other/abstract3.C
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/54325] [4.7/4.8 Regression] C++11 uniform initialization syntax for argument-less abstract base class constructor fails
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
` (8 preceding siblings ...)
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
` (3 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu.org @ 2012-12-07 5:16 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54325
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
AssignedTo|unassigned at gcc dot |jason at gcc dot gnu.org
|gnu.org |
--- Comment #9 from Jason Merrill <jason at gcc dot gnu.org> 2012-12-07 05:15:03 UTC ---
Fixed.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/54325] [4.7/4.8 Regression] C++11 uniform initialization syntax for argument-less abstract base class constructor fails
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
` (9 preceding siblings ...)
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
` (2 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-12-27 8:41 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54325
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |REOPENED
Resolution|FIXED |
--- Comment #10 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-12-27 08:41:13 UTC ---
Let's reopen this: testcase in Comment #1 isn't fixed yet.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/54325] [4.7/4.8 Regression] C++11 uniform initialization syntax for argument-less abstract base class constructor fails
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
` (10 preceding siblings ...)
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
13 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu.org @ 2013-01-02 20:55 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54325
--- Comment #11 from Jason Merrill <jason at gcc dot gnu.org> 2013-01-02 20:54:46 UTC ---
Author: jason
Date: Wed Jan 2 20:54:42 2013
New Revision: 194820
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=194820
Log:
PR c++/54325
* call.c (build_new_method_call_1): Don't use build_value_init for
user-provided default constructors.
Added:
trunk/gcc/testsuite/g++.dg/cpp0x/initlist-protected.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/call.c
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/54325] [4.7/4.8 Regression] C++11 uniform initialization syntax for argument-less abstract base class constructor fails
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
` (11 preceding siblings ...)
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
13 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu.org @ 2013-01-02 20:57 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54325
--- Comment #12 from Jason Merrill <jason at gcc dot gnu.org> 2013-01-02 20:56:37 UTC ---
Author: jason
Date: Wed Jan 2 20:56:29 2013
New Revision: 194821
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=194821
Log:
PR c++/54325
* call.c (build_new_method_call_1): Don't use build_value_init for
user-provided default constructors.
Added:
branches/gcc-4_7-branch/gcc/testsuite/g++.dg/cpp0x/initlist-protected.C
Modified:
branches/gcc-4_7-branch/gcc/cp/ChangeLog
branches/gcc-4_7-branch/gcc/cp/call.c
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/54325] [4.7/4.8 Regression] C++11 uniform initialization syntax for argument-less abstract base class constructor fails
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
` (12 preceding siblings ...)
2013-01-02 20:57 ` jason at gcc dot gnu.org
@ 2013-01-02 21:06 ` jason at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu.org @ 2013-01-02 21:06 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54325
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|REOPENED |RESOLVED
Resolution| |FIXED
--- Comment #13 from Jason Merrill <jason at gcc dot gnu.org> 2013-01-02 21:05:46 UTC ---
Testcase from comment #1 fixed as well.
^ 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).