* C++ PATCH for c++/88857 - ICE with value-initialization of argument in template
@ 2019-02-27 22:35 Marek Polacek
2019-02-28 0:20 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2019-02-27 22:35 UTC (permalink / raw)
To: GCC Patches, Jason Merrill
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" }
+}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: C++ PATCH for c++/88857 - ICE with value-initialization of argument in template
2019-02-27 22:35 C++ PATCH for c++/88857 - ICE with value-initialization of argument in template Marek Polacek
@ 2019-02-28 0:20 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2019-02-28 0:20 UTC (permalink / raw)
To: Marek Polacek, GCC Patches
On 2/27/19 4:22 PM, Marek Polacek wrote:
> 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.
OK.
Jason
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-02-27 23:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-27 22:35 C++ PATCH for c++/88857 - ICE with value-initialization of argument in template Marek Polacek
2019-02-28 0:20 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).