Here, because the class has a list constructor, we avoid the shortcut in build_special_member_call, so we need to use the new backup path for C++17 copy elision in build_over_call, which means teaching conv_binds_ref_to_prvalue about this case.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit 053b17904db3de54265a6cda7dcd90390b0753b1 Author: Jason Merrill <ja...@redhat.com> Date: Tue Apr 3 14:10:44 2018 -0400 PR c++/85092 - C++17 ICE with unused list constructor. * call.c (conv_binds_ref_to_prvalue): Also count ck_identity from a TARGET_EXPR. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 9351918b23a..901f18c43e6 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -7611,6 +7611,9 @@ conv_binds_ref_to_prvalue (conversion *c) return true; if (c->kind == ck_user && TREE_CODE (c->type) != REFERENCE_TYPE) return true; + if (c->kind == ck_identity && c->u.expr + && TREE_CODE (c->u.expr) == TARGET_EXPR) + return true; return false; } diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist99.C b/gcc/testsuite/g++.dg/cpp0x/initlist99.C new file mode 100644 index 00000000000..d96f793d398 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist99.C @@ -0,0 +1,13 @@ +// PR c++/85092 +// { dg-do compile { target c++11 } } + +#include <initializer_list> + +struct A +{ + A (std::initializer_list<char>); +}; + +A f (); + +A a { f () };