public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] PR c++/93299 - ICE in tsubst_copy with parenthesized expression.
@ 2020-01-17 21:18 Marek Polacek
  2020-01-24 16:07 ` Marek Polacek
  2020-01-24 17:46 ` Jason Merrill
  0 siblings, 2 replies; 3+ messages in thread
From: Marek Polacek @ 2020-01-17 21:18 UTC (permalink / raw)
  To: jason; +Cc: gcc-patches, Marek Polacek

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-01-24 17:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-17 21:18 [C++ PATCH] PR c++/93299 - ICE in tsubst_copy with parenthesized expression Marek Polacek
2020-01-24 16:07 ` Marek Polacek
2020-01-24 17:46 ` 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).