C++ PATCH to fix ICE with constexpr operator"" (PR c++/84325)

Message ID 20180226174238.GK2995@redhat.com
State New
Headers show
Series
  • C++ PATCH to fix ICE with constexpr operator"" (PR c++/84325)
Related show

Commit Message

Marek Polacek Feb. 26, 2018, 5:42 p.m.
The original testcase was invalid but I added seconds's constructor and made
time_to_wait inline and now the testcase is accepted by clang++.

But we ICE in replace_placeholders_r because we were checking TREE_CONSTANT
on a type.  With this patch we accept the code without crashing.  (We require
time_to_wait to be inline but clang++ does not.)

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

2018-02-26  Marek Polacek  <polacek@redhat.com>

	PR c++/84325
	* tree.c (replace_placeholders_r): Only check TREE_CONSTANT on
	non-types.

	* g++.dg/cpp1z/pr84325.C: New test.


	Marek

Comments

Jason Merrill Feb. 26, 2018, 5:50 p.m. | #1
On Mon, Feb 26, 2018 at 12:42 PM, Marek Polacek <polacek@redhat.com> wrote:
> The original testcase was invalid but I added seconds's constructor and made

> time_to_wait inline and now the testcase is accepted by clang++.

>

> But we ICE in replace_placeholders_r because we were checking TREE_CONSTANT

> on a type.  With this patch we accept the code without crashing.  (We require

> time_to_wait to be inline but clang++ does not.)

>

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

>

> 2018-02-26  Marek Polacek  <polacek@redhat.com>

>

>         PR c++/84325

>         * tree.c (replace_placeholders_r): Only check TREE_CONSTANT on

>         non-types.

>

>         * g++.dg/cpp1z/pr84325.C: New test.

>

> diff --git gcc/cp/tree.c gcc/cp/tree.c

> index 39c1ef28b2d..298517ff83a 100644

> --- gcc/cp/tree.c

> +++ gcc/cp/tree.c

> @@ -3091,7 +3091,7 @@ replace_placeholders_r (tree* t, int* walk_subtrees, void* data_)

>    replace_placeholders_t *d = static_cast<replace_placeholders_t*>(data_);

>    tree obj = d->obj;

>

> -  if (TREE_CONSTANT (*t))

> +  if (!TYPE_P (*t) && TREE_CONSTANT (*t))


I'd make this

if (TYPE_P (*t) || TREE_CONSTANT (*t))

so we don't keep walking into types.  OK with that change.

Jason

Patch

diff --git gcc/cp/tree.c gcc/cp/tree.c
index 39c1ef28b2d..298517ff83a 100644
--- gcc/cp/tree.c
+++ gcc/cp/tree.c
@@ -3091,7 +3091,7 @@  replace_placeholders_r (tree* t, int* walk_subtrees, void* data_)
   replace_placeholders_t *d = static_cast<replace_placeholders_t*>(data_);
   tree obj = d->obj;
 
-  if (TREE_CONSTANT (*t))
+  if (!TYPE_P (*t) && TREE_CONSTANT (*t))
     {
       *walk_subtrees = false;
       return NULL_TREE;
diff --git gcc/testsuite/g++.dg/cpp1z/pr84325.C gcc/testsuite/g++.dg/cpp1z/pr84325.C
index e69de29bb2d..dddadc32692 100644
--- gcc/testsuite/g++.dg/cpp1z/pr84325.C
+++ gcc/testsuite/g++.dg/cpp1z/pr84325.C
@@ -0,0 +1,17 @@ 
+// PR c++/84325
+// { dg-do compile }
+// { dg-options "-std=c++17" }
+
+struct seconds { int i_{0}; constexpr seconds (int) {} };
+template <char... _Digits> constexpr seconds operator""_s() {
+  return seconds(0);
+}
+constexpr seconds operator""_s(long double i) {
+  return seconds(0);
+}
+template<class TYPE>
+struct Param {
+  constexpr static inline seconds time_to_wait{10_s};
+};
+struct Empty {};
+Param<Empty> p;