From: Paolo Carlini Date: Wed, 14 Mar 2018 01:03:13 +0000 (+0000) Subject: PR c++/82336 - link error with list-init default argument. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=024a6f45a72d4686aa535a37abe7b34d678e459d;p=gcc.git PR c++/82336 - link error with list-init default argument. * decl.c (check_default_argument): Unshare an initializer list. Co-Authored-By: Jason Merrill From-SVN: r258512 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 09dc2b1ac12..71fba751807 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-03-13 Paolo Carlini + Jason Merrill + + PR c++/82336 - link error with list-init default argument. + * decl.c (check_default_argument): Unshare an initializer list. + 2018-03-13 Jakub Jelinek PR c++/84843 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index ff6dd66e769..45daccda916 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -12668,7 +12668,9 @@ check_default_argument (tree decl, tree arg, tsubst_flags_t complain) A default argument expression is implicitly converted to the parameter type. */ ++cp_unevaluated_operand; - perform_implicit_conversion_flags (decl_type, arg, complain, + /* Avoid digest_init clobbering the initializer. */ + tree carg = BRACE_ENCLOSED_INITIALIZER_P (arg) ? unshare_expr (arg): arg; + perform_implicit_conversion_flags (decl_type, carg, complain, LOOKUP_IMPLICIT); --cp_unevaluated_operand; diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-defarg2.C b/gcc/testsuite/g++.dg/cpp0x/initlist-defarg2.C new file mode 100644 index 00000000000..65240355fc3 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist-defarg2.C @@ -0,0 +1,8 @@ +// PR c++/82336 +// { dg-do link { target c++11 } } + +struct foo { int x = 5; }; +struct bar : foo { bar() = default; }; +struct baz { bar x; }; +void qux(baz = {}){} +int main() { qux(); }