re PR c++/83796 (Abstract classes allowed to be instantiated when initialised as...
authorPaolo Carlini <paolo.carlini@oracle.com>
Thu, 1 Feb 2018 15:36:04 +0000 (15:36 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Thu, 1 Feb 2018 15:36:04 +0000 (15:36 +0000)
/cp
2018-02-01  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/83796
* call.c (convert_like_real): If w're initializing from {} explicitly
call abstract_virtuals_error_sfinae.

/testsuite
2018-02-01  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/83796
* g++.dg/cpp0x/abstract-default1.C: New.

From-SVN: r257298

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

index 6eb7f27883fe5a7dbc715f5337fb574cde7b14e2..8fc9042ea012b2a2c9a302a75a0451eecd67d2d1 100644 (file)
@@ -1,3 +1,9 @@
+2018-02-01  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/83796
+       * call.c (convert_like_real): If w're initializing from {} explicitly
+       call abstract_virtuals_error_sfinae.
+
 2018-01-31  Jason Merrill  <jason@redhat.com>
            Jakub Jelinek  <jakub@redhat.com>
 
index 46d5ef5e7c0bfc06855a297f7bbfc660962b2594..15b723ad2b090c111f49c62a8111e704392673f8 100644 (file)
@@ -6765,6 +6765,8 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
            && TYPE_HAS_DEFAULT_CONSTRUCTOR (totype))
          {
            bool direct = CONSTRUCTOR_IS_DIRECT_INIT (expr);
+           if (abstract_virtuals_error_sfinae (NULL_TREE, totype, complain))
+             return error_mark_node;
            expr = build_value_init (totype, complain);
            expr = get_target_expr_sfinae (expr, complain);
            if (expr != error_mark_node)
index 3f2f44736115bc2e2cfc9adedc0b67331a77bae2..465ae15296a707924995c3ddc0fc8e606d4cff23 100644 (file)
@@ -1,3 +1,8 @@
+2018-02-01  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/83796
+       * g++.dg/cpp0x/abstract-default1.C: New.
+
 2018-02-01  Richard Sandiford  <richard.sandiford@linaro.org>
 
        PR tree-optimization/81635
diff --git a/gcc/testsuite/g++.dg/cpp0x/abstract-default1.C b/gcc/testsuite/g++.dg/cpp0x/abstract-default1.C
new file mode 100644 (file)
index 0000000..e98af76
--- /dev/null
@@ -0,0 +1,26 @@
+// PR c++/83796
+// { dg-do compile { target c++11 } }
+
+struct MyAbstractClass
+{
+  virtual int foo() const = 0;
+};
+
+struct TestClass
+{
+  TestClass(const MyAbstractClass& m = {})  // { dg-error "abstract type" }
+  : value_(m.foo()) {}
+
+  int value_;
+};
+
+int TestFunction(const MyAbstractClass& m = {})  // { dg-error "abstract type" }
+{
+  return m.foo();
+}
+
+int main()
+{
+  TestClass testInstance;  // { dg-error "abstract type" }
+  TestFunction();  // { dg-error "abstract type" }
+}