From: Marek Polacek <polacek@redhat.com>
To: Jason Merrill <jason@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: C++ PATCH for c++/88216, ICE with class type in non-type template parameter
Date: Tue, 11 Dec 2018 21:05:00 -0000 [thread overview]
Message-ID: <20181211210506.GX21364@redhat.com> (raw)
In-Reply-To: <7b54d664-f7cb-3a45-bc40-6d62f29ceb5a@redhat.com>
On Tue, Dec 11, 2018 at 10:48:17AM -0500, Jason Merrill wrote:
> On 12/10/18 2:52 PM, Marek Polacek wrote:
> > + if (processing_template_decl && value_dependent_expression_p (expr))
>
> You don't need to check processing_template_decl before
> value_dependent_expression_p.
Ok.
> I would lean toward checking for value-dependence in
> convert_nontype_argument, which already does that a lot. Enough, actually,
> that perhaps we should remember the result in a local variable.
I've moved the call, but I didn't add a local variable for the result,
because I was afraid that, since EXPR is being modified on some of the
codepaths, its value-dependent-ness (is that a term?) may change.
Thanks,
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2018-12-11 Marek Polacek <polacek@redhat.com>
PR c++/88216 - ICE with class type in non-type template parameter.
* mangle.c (write_expression): Handle TARGET_EXPR and
VIEW_CONVERT_EXPR.
* pt.c (convert_nontype_argument): Don't call
get_template_parm_object for value-dependent expressions.
* g++.dg/cpp2a/nontype-class9.C: New test.
diff --git gcc/cp/mangle.c gcc/cp/mangle.c
index 64415894bc5..56247883010 100644
--- gcc/cp/mangle.c
+++ gcc/cp/mangle.c
@@ -2836,13 +2836,21 @@ write_expression (tree expr)
{
enum tree_code code = TREE_CODE (expr);
+ if (TREE_CODE (expr) == TARGET_EXPR)
+ {
+ expr = TARGET_EXPR_INITIAL (expr);
+ code = TREE_CODE (expr);
+ }
+
/* Skip NOP_EXPR and CONVERT_EXPR. They can occur when (say) a pointer
argument is converted (via qualification conversions) to another type. */
while (CONVERT_EXPR_CODE_P (code)
|| location_wrapper_p (expr)
/* Parentheses aren't mangled. */
|| code == PAREN_EXPR
- || code == NON_LVALUE_EXPR)
+ || code == NON_LVALUE_EXPR
+ || (code == VIEW_CONVERT_EXPR
+ && TREE_CODE (TREE_OPERAND (expr, 0)) == TEMPLATE_PARM_INDEX))
{
expr = TREE_OPERAND (expr, 0);
code = TREE_CODE (expr);
diff --git gcc/cp/pt.c gcc/cp/pt.c
index 8560e588593..3b378ee9ff4 100644
--- gcc/cp/pt.c
+++ gcc/cp/pt.c
@@ -7123,7 +7123,8 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain)
{
/* Replace the argument with a reference to the corresponding template
parameter object. */
- expr = get_template_parm_object (expr, complain);
+ if (!value_dependent_expression_p (expr))
+ expr = get_template_parm_object (expr, complain);
if (expr == error_mark_node)
return NULL_TREE;
}
diff --git gcc/testsuite/g++.dg/cpp2a/nontype-class9.C gcc/testsuite/g++.dg/cpp2a/nontype-class9.C
new file mode 100644
index 00000000000..737f712be47
--- /dev/null
+++ gcc/testsuite/g++.dg/cpp2a/nontype-class9.C
@@ -0,0 +1,29 @@
+// PR c++/88216
+// { dg-do compile { target c++2a } }
+
+template <class T, class U> struct same;
+template <class T> struct same<T,T> {};
+
+struct T { };
+
+template <T t>
+struct U { };
+
+template <T t>
+void f (U<t>)
+{
+ same<T,decltype(t)> s;
+ same<const T&,decltype((t))> s2;
+}
+
+template<T t>
+U<t> u;
+
+T t;
+U<t> u2;
+
+void
+g ()
+{
+ f<t>(u2);
+}
next prev parent reply other threads:[~2018-12-11 21:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-10 19:52 Marek Polacek
2018-12-11 15:48 ` Jason Merrill
2018-12-11 21:05 ` Marek Polacek [this message]
2018-12-13 20:39 ` 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=20181211210506.GX21364@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).