From: Paolo Carlini Date: Thu, 1 Feb 2018 15:36:04 +0000 (+0000) Subject: re PR c++/83796 (Abstract classes allowed to be instantiated when initialised as... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=73b7d28f677d9bf4a4ab5ef1f69cf8282a28e377;p=gcc.git re PR c++/83796 (Abstract classes allowed to be instantiated when initialised as default parameter to function or constructor) /cp 2018-02-01 Paolo Carlini 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 PR c++/83796 * g++.dg/cpp0x/abstract-default1.C: New. From-SVN: r257298 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6eb7f27883f..8fc9042ea01 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-02-01 Paolo Carlini + + PR c++/83796 + * call.c (convert_like_real): If w're initializing from {} explicitly + call abstract_virtuals_error_sfinae. + 2018-01-31 Jason Merrill Jakub Jelinek diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 46d5ef5e7c0..15b723ad2b0 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -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) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3f2f4473611..465ae15296a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-02-01 Paolo Carlini + + PR c++/83796 + * g++.dg/cpp0x/abstract-default1.C: New. + 2018-02-01 Richard Sandiford 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 index 00000000000..e98af766170 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/abstract-default1.C @@ -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" } +}