At least with a recent GCC trunk build: > $ g++ --version > g++ (GCC) 7.0.1 20170214 (experimental) > Copyright (C) 2017 Free Software Foundation, Inc. > This is free software; see the source for copying conditions. There is NO > warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. > > $ cat test.cc > struct S {}; > S f(); > S s(static_cast<S const &>(f())); > > $ g++ -std=c++17 -fsyntax-only test.cc > test.cc:3:32: internal compiler error: in build_over_call, at cp/call.c:7978 > S s(static_cast<S const &>(f())); > ^ > 0x5c34ec build_over_call > ../../src/gcc/cp/call.c:7975 > 0x5c443e build_new_method_call_1 > ../../src/gcc/cp/call.c:8801 > 0x5c443e build_new_method_call(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>**, tree_node*, int, tree_node**, int) > ../../src/gcc/cp/call.c:8870 > 0x5c58c9 build_special_member_call(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>**, tree_node*, int, int) > ../../src/gcc/cp/call.c:8399 > 0x74dfe4 expand_default_init > ../../src/gcc/cp/init.c:1790 > 0x74dfe4 expand_aggr_init_1 > ../../src/gcc/cp/init.c:1905 > 0x74ebeb build_aggr_init(tree_node*, tree_node*, int, int) > ../../src/gcc/cp/init.c:1643 > 0x5e05df build_aggr_init_full_exprs > ../../src/gcc/cp/decl.c:6164 > 0x5e05df check_initializer > ../../src/gcc/cp/decl.c:6312 > 0x60aabc cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int) > ../../src/gcc/cp/decl.c:7025 > 0x7090a3 cp_parser_init_declarator > ../../src/gcc/cp/parser.c:19389 > 0x709a6c cp_parser_simple_declaration > ../../src/gcc/cp/parser.c:12792 > 0x70a825 cp_parser_block_declaration > ../../src/gcc/cp/parser.c:12617 > 0x6e33d4 cp_parser_declaration > ../../src/gcc/cp/parser.c:12515 > 0x713e6b cp_parser_declaration_seq_opt > ../../src/gcc/cp/parser.c:12391 > 0x71414a cp_parser_translation_unit > ../../src/gcc/cp/parser.c:4366 > 0x71414a c_parse_file() > ../../src/gcc/cp/parser.c:38425 > 0x873ac3 c_common_parse_file() > ../../src/gcc/c-family/c-opts.c:1107 > Please submit a full bug report, > with preprocessed source if appropriate. > Please include the complete backtrace with any bug report. > See <https://gcc.gnu.org/bugs/> for instructions. The ICE happens with -std=c++17/-std=gnu++17, doesn't happen with -std=c++14 etc. I cannot reproduce it with g++ from gcc-c++-6.3.1-1.fc25.x86_64, but maybe that one's built without assertions.
Confirmed with -std=c++17/-std=gnu++17.
commit c821ae1a57320c4b1ba47afef6136b534f830351 Author: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Sat Oct 8 16:23:26 2016 +0000 Further P0135 refinement. * call.c (build_user_type_conversion_1): Consider conversions from a single element in an initializer-list. (build_temp): Undo early_elide_copy change. (build_over_call): Check that we don't try to copy a TARGET_EXPR in C++17 mode. Set user_conv_p here. (convert_like_real): Not here. (check_self_delegation): Split out from... (build_special_member_call): ...here. Handle C++17 copy elision. * cvt.c (early_elide_copy): Remove. (ocp_convert): Undo early_elide_copy change. * except.c (build_throw): Likewise. * init.c (expand_default_init): Likewise. * typeck.c (cp_build_modify_expr): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@240889 138bc75d-0d04-0410-961f-82ee72b054a4
Author: jason Date: Fri Feb 17 16:50:16 2017 New Revision: 245538 URL: https://gcc.gnu.org/viewcvs?rev=245538&root=gcc&view=rev Log: PR c++/79533 - C++17 ICE with temporary cast to reference * call.c (build_over_call): Conversion to a reference prevents copy elision. Added: trunk/gcc/testsuite/g++.dg/init/elide6.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/call.c
Fixed.