public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Marek Polacek <polacek@redhat.com>
To: jason@redhat.com
Cc: gcc-patches@gcc.gnu.org,	Marek Polacek <polacek@redhat.com>
Subject: [C++ PATCH] PR c++/93299 - ICE in tsubst_copy with parenthesized expression.
Date: Fri, 17 Jan 2020 21:18:00 -0000	[thread overview]
Message-ID: <20200117210309.808128-1-polacek@redhat.com> (raw)

Since e4511ca2e9ecdb51d41b64452398f8e2df575668 force_paren_expr can create
a VIEW_CONVERT_EXPR so that we have something to set REF_PARENTHESIZED_P
on, while not making the expression dependent.  But tsubst_copy can't cope
with such a VIEW_CONVERT_EXPR, because it's not location_wrapper_p, or
a TEMPLATE_PARM_INDEX wrapped in a VIEW_CONVERT_EXPR.

I think we need to teach tsubst_copy how to handle it.  Setting
EXPR_LOCATION_WRAPPER_P in force_paren_expr would make the ICE go away
too, but tsubst_copy would lose the REF_PARENTHESIZED_P flag.

Bootstrapped/regtested on x86_64-linux, ok for trunk and 9?

	* pt.c (tsubst_copy): Handle a REF_PARENTHESIZED_P VIEW_CONVERT_EXPR.

	* g++.dg/cpp1y/paren5.C: New test.
---
 gcc/cp/pt.c                         |  8 ++++++++
 gcc/testsuite/g++.dg/cpp1y/paren5.C | 12 ++++++++++++
 2 files changed, 20 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp1y/paren5.C

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 1b3d07b1a52..5d3d127e528 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -16423,6 +16423,14 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
 		  return op;
 		}
 	    }
+	  /* force_paren_expr can also create a VIEW_CONVERT_EXPR.  */
+	  else if (code == VIEW_CONVERT_EXPR && REF_PARENTHESIZED_P (t))
+	    {
+	      op = tsubst_copy (op, args, complain, in_decl);
+	      op = build1 (code, TREE_TYPE (op), op);
+	      REF_PARENTHESIZED_P (op) = true;
+	      return op;
+	    }
 	  /* We shouldn't see any other uses of these in templates.  */
 	  gcc_unreachable ();
 	}
diff --git a/gcc/testsuite/g++.dg/cpp1y/paren5.C b/gcc/testsuite/g++.dg/cpp1y/paren5.C
new file mode 100644
index 00000000000..86a51356465
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/paren5.C
@@ -0,0 +1,12 @@
+// PR c++/93299 - ICE in tsubst_copy with parenthesized expression.
+// { dg-do compile { target c++14 } }
+
+template <typename> struct A {
+  enum { b = 8 };
+};
+
+template <int> struct __attribute__((aligned((A<int>::b)))) D { };
+struct S : D<0> { };
+
+template <int N> struct __attribute__((aligned((A<int>::b) + N))) D2 { };
+struct S2 : D2<0> { };

base-commit: 6687d13a87c42dddc7d1c7adade38d31ba0d1401
-- 
2.24.1

             reply	other threads:[~2020-01-17 21:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-17 21:18 Marek Polacek [this message]
2020-01-24 16:07 ` Marek Polacek
2020-01-24 17:46 ` 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=20200117210309.808128-1-polacek@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).