===================================================================
@@ -7828,15 +7828,20 @@ build_new_method_call_1 (tree instance, tree fns,
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);
+ {
+ /* These 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))
===================================================================
@@ -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" }
+};