public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/54325 (wrong error initializing abstract base class)
@ 2012-12-07  5:05 Jason Merrill
  2012-12-07  9:13 ` Matthias Klose
  2012-12-21 11:38 ` Paolo Carlini
  0 siblings, 2 replies; 17+ messages in thread
From: Jason Merrill @ 2012-12-07  5:05 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 311 bytes --]

It's perfectly OK to initialize a base class of abstract type; it's only 
an error to create a full object of such a type.  So this patch moves 
the check from more generic initialization code out into a function 
that's definitely creating a new object.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.7.

[-- Attachment #2: 54325.patch --]
[-- Type: text/x-patch, Size: 2414 bytes --]

commit 6fb305c7c88b07c429e8a39fbd514a417c5b6127
Author: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Fri Dec 7 04:54:27 2012 +0000

    	PR c++/54325
    	* tree.c (build_aggr_init_expr): Don't check for abstract class.
    
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 28ff0f2..ca82f75 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -407,18 +407,13 @@ build_aggr_init_array (tree return_type, tree fn, tree slot, int nargs,
    callable.  */
 
 tree
-build_aggr_init_expr (tree type, tree init, tsubst_flags_t complain)
+build_aggr_init_expr (tree type, tree init, tsubst_flags_t /*complain*/)
 {
   tree fn;
   tree slot;
   tree rval;
   int is_ctor;
 
-  /* Make sure that we're not trying to create an instance of an
-     abstract class.  */
-  if (abstract_virtuals_error_sfinae (NULL_TREE, type, complain))
-    return error_mark_node;
-
   if (TREE_CODE (init) == CALL_EXPR)
     fn = CALL_EXPR_FN (init);
   else if (TREE_CODE (init) == AGGR_INIT_EXPR)
@@ -477,6 +472,11 @@ build_cplus_new (tree type, tree init, tsubst_flags_t complain)
   tree rval = build_aggr_init_expr (type, init, complain);
   tree slot;
 
+  /* Make sure that we're not trying to create an instance of an
+     abstract class.  */
+  if (abstract_virtuals_error_sfinae (NULL_TREE, type, complain))
+    return error_mark_node;
+
   if (TREE_CODE (rval) == AGGR_INIT_EXPR)
     slot = AGGR_INIT_EXPR_SLOT (rval);
   else if (TREE_CODE (rval) == CALL_EXPR
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-pure.C b/gcc/testsuite/g++.dg/cpp0x/initlist-pure.C
new file mode 100644
index 0000000..63c341c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist-pure.C
@@ -0,0 +1,25 @@
+// PR c++/54325
+// { dg-options -std=c++11 }
+
+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;
+}
diff --git a/gcc/testsuite/g++.dg/other/abstract3.C b/gcc/testsuite/g++.dg/other/abstract3.C
index 528b7d7..95e293e 100644
--- a/gcc/testsuite/g++.dg/other/abstract3.C
+++ b/gcc/testsuite/g++.dg/other/abstract3.C
@@ -8,5 +8,5 @@ struct A                  // { dg-message "note" }
 struct B
 {
   A a;           // { dg-error "abstract" }
-  B() : a() {}   // { dg-error "abstract" }
+  B() : a() {}
 };

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

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

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-07  5:05 C++ PATCH for c++/54325 (wrong error initializing abstract base class) Jason Merrill
2012-12-07  9:13 ` Matthias Klose
2012-12-07  9:17   ` Jakub Jelinek
2012-12-07  9:24     ` Matthias Klose
2012-12-07 10:10       ` Paolo Carlini
2012-12-07 14:41         ` Jason Merrill
2012-12-07 13:34   ` Gabriel Dos Reis
2012-12-07 13:39     ` Jakub Jelinek
2012-12-07 13:43       ` Gabriel Dos Reis
2012-12-21 11:38 ` Paolo Carlini
2012-12-22 20:30   ` Jason Merrill
2012-12-22 23:02     ` Paolo Carlini
2012-12-24  4:56       ` Jason Merrill
2012-12-24  8:29         ` Paolo Carlini
2012-12-24  9:27           ` Paolo Carlini
2012-12-26 18:58           ` Jason Merrill
2013-01-02 20:56             ` Jason Merrill

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