From: Marek Polacek <polacek@redhat.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>, Jason Merrill <jason@redhat.com>
Subject: C++ PATCH for c++/88857 - ICE with value-initialization of argument in template
Date: Wed, 27 Feb 2019 22:35:00 -0000 [thread overview]
Message-ID: <20190227212229.GG8512@redhat.com> (raw)
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" }
+}
next reply other threads:[~2019-02-27 21:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-27 22:35 Marek Polacek [this message]
2019-02-28 0:20 ` Jason Merrill
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190227212229.GG8512@redhat.com \
--to=polacek@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).