C++ PATCH for c++/88857 - ICE with value-initialization of argument in template
Marek Polacek
polacek@redhat.com
Wed Feb 27 22:35:00 GMT 2019
build_value_init doesn't work in templates (for non-scalar/array types,
anyway), so avoid this situation, much like in build_new_method_call_1.
We're calling convert_like_real because when there's only one non-viable
candidate function, build_new_function_call calls cp_build_function_call_vec
to give errors and that calls convert_arguments. If there's a viable
candidate, build_new_function_call calls build_over_call instead, and that,
when in a template, doesn't process the arguments.
I ran the testsuite to see if we ever call build_value_init in a template
in convert_like_real and nothing turned up.
Bootstrapped/regtested on x86_64-linux, ok for trunk/8?
2019-02-27 Marek Polacek <polacek@redhat.com>
PR c++/88857 - ICE with value-initialization of argument in template.
* call.c (convert_like_real): Don't call build_value_init in template.
* g++.dg/cpp0x/initlist-value4.C: New test.
diff --git gcc/cp/call.c gcc/cp/call.c
index c53eb582aac..fb67d905acd 100644
--- gcc/cp/call.c
+++ gcc/cp/call.c
@@ -7005,7 +7005,8 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
/* If we're initializing from {}, it's value-initialization. */
if (BRACE_ENCLOSED_INITIALIZER_P (expr)
&& CONSTRUCTOR_NELTS (expr) == 0
- && TYPE_HAS_DEFAULT_CONSTRUCTOR (totype))
+ && TYPE_HAS_DEFAULT_CONSTRUCTOR (totype)
+ && !processing_template_decl)
{
bool direct = CONSTRUCTOR_IS_DIRECT_INIT (expr);
if (abstract_virtuals_error_sfinae (NULL_TREE, totype, complain))
diff --git gcc/testsuite/g++.dg/cpp0x/initlist-value4.C gcc/testsuite/g++.dg/cpp0x/initlist-value4.C
new file mode 100644
index 00000000000..427147ff7f2
--- /dev/null
+++ gcc/testsuite/g++.dg/cpp0x/initlist-value4.C
@@ -0,0 +1,12 @@
+// PR c++/88857
+// { dg-do compile { target c++11 } }
+
+class S { int a; };
+void foo (const S &, int);
+
+template <int N>
+void
+bar ()
+{
+ foo ({}); // { dg-error "too few arguments to function" }
+}
More information about the Gcc-patches
mailing list