re PR c++/51474 ([c++0x] ICE with pure virtual function in initialization of non...
authorPaolo Carlini <paolo.carlini@oracle.com>
Wed, 19 Mar 2014 18:21:52 +0000 (18:21 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Wed, 19 Mar 2014 18:21:52 +0000 (18:21 +0000)
/cp
2014-03-19  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/51474
* call.c (build_new_method_call_1): Handle pure virtuals called by
NSDMIs too.

/testsuite
2014-03-19  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/51474
* g++.dg/cpp0x/nsdmi-virtual2.C: New.

From-SVN: r208686

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/nsdmi-virtual2.C [new file with mode: 0644]

index 3cf6858..655f6d4 100644 (file)
@@ -1,3 +1,9 @@
+2014-03-19  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/51474
+       * call.c (build_new_method_call_1): Handle pure virtuals called by
+       NSDMIs too.
+
 2014-03-17  Adam Butcher  <adam@jessamine.co.uk>
 
        PR c++/60390
index 184e922..877f6d9 100644 (file)
@@ -7828,15 +7828,20 @@ build_new_method_call_1 (tree instance, tree fns, vec<tree, va_gc> **args,
          if (!(flags & LOOKUP_NONVIRTUAL)
              && DECL_PURE_VIRTUAL_P (fn)
              && instance == current_class_ref
-             && (DECL_CONSTRUCTOR_P (current_function_decl)
-                 || DECL_DESTRUCTOR_P (current_function_decl))
              && (complain & tf_warning))
-           /* This is not an error, it is runtime undefined
-              behavior.  */
-           warning (0, (DECL_CONSTRUCTOR_P (current_function_decl) ?
-                     "pure virtual %q#D called from constructor"
-                     : "pure virtual %q#D called from destructor"),
-                    fn);
+           {
+             /* This is not an error, it is runtime undefined
+                behavior.  */
+             if (!current_function_decl)
+               warning (0, "pure virtual %q#D called from "
+                        "non-static data member initializer", fn);
+             else if (DECL_CONSTRUCTOR_P (current_function_decl)
+                      || DECL_DESTRUCTOR_P (current_function_decl))
+               warning (0, (DECL_CONSTRUCTOR_P (current_function_decl)
+                            ? "pure virtual %q#D called from constructor"
+                            : "pure virtual %q#D called from destructor"),
+                        fn);
+           }
 
          if (TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE
              && is_dummy_object (instance))
index c40bddb..d0f56cd 100644 (file)
@@ -1,3 +1,8 @@
+2014-03-19  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/51474
+       * g++.dg/cpp0x/nsdmi-virtual2.C: New.
+
 2014-03-19  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR testsuite/60590
diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-virtual2.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-virtual2.C
new file mode 100644 (file)
index 0000000..157854c
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/51474
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+  virtual int foo() = 0;
+  int i = foo();  // { dg-warning "pure virtual" }
+};