re PR c++/83918 ([c++17] ICE on constexpr eval of datatype involving function and...
authorJakub Jelinek <jakub@redhat.com>
Tue, 23 Jan 2018 07:46:05 +0000 (08:46 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 23 Jan 2018 07:46:05 +0000 (08:46 +0100)
PR c++/83918
* tree.c (maybe_wrap_with_location): Use NON_LVALUE_EXPR rather than
VIEW_CONVERT_EXPR to wrap CONST_DECLs.

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

From-SVN: r256972

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1z/pr83918.C [new file with mode: 0644]
gcc/tree.c

index 507bb52dc8258275429df7a6447f8564f1f9c5fb..a1307e34b5091ab1dde2714b832b29bf1795d2ea 100644 (file)
@@ -1,3 +1,9 @@
+2018-01-23  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/83918
+       * tree.c (maybe_wrap_with_location): Use NON_LVALUE_EXPR rather than
+       VIEW_CONVERT_EXPR to wrap CONST_DECLs.
+
 2018-01-22  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/83957
index 82497ed9641b7dadbdef3a10fc6eff757fa45606..d22af7ab9270eb3abb7db1e593be942b38a01cc2 100644 (file)
@@ -1,3 +1,8 @@
+2018-01-23  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/83918
+       * g++.dg/cpp1z/pr83918.C: New test.
+
 2018-01-22  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/83957
diff --git a/gcc/testsuite/g++.dg/cpp1z/pr83918.C b/gcc/testsuite/g++.dg/cpp1z/pr83918.C
new file mode 100644 (file)
index 0000000..d4fe826
--- /dev/null
@@ -0,0 +1,32 @@
+// PR c++/83918
+// { dg-do compile }
+// { dg-options "-std=c++17" }
+
+constexpr unsigned
+foo (unsigned x, unsigned y)
+{
+  return x > y ? x : y;
+}
+
+template <typename, typename> struct A;
+template <auto ...> struct B;
+template <auto S, auto ... T, auto U, auto ... V>
+struct A <B <S, T...>, B <U, V...>>
+{
+  enum : unsigned
+  {
+    u = foo (sizeof (S), sizeof (U)),
+    v = A <B <T...>, B <V...>>::w,
+    w = foo (u, v)
+  };
+};
+
+template <>
+struct A <B <>, B <>>
+{
+  enum : unsigned { w = 0 };
+};
+
+constexpr static const auto v { A <B <1,2,3,4,5,6,7,8,9>,
+                                  B <9,8,7,6,5,4,3,2,1>>::w };
+static_assert (v == sizeof (int));
index b3e93b87eb2dc0079b05fc20804531876bd52b90..452d3855a77fc8e4d997035dc5be8160ebc64f26 100644 (file)
@@ -14085,8 +14085,10 @@ maybe_wrap_with_location (tree expr, location_t loc)
   if (EXCEPTIONAL_CLASS_P (expr))
     return expr;
 
-  tree_code code = (CONSTANT_CLASS_P (expr) && TREE_CODE (expr) != STRING_CST
-                   ? NON_LVALUE_EXPR : VIEW_CONVERT_EXPR);
+  tree_code code
+    = (((CONSTANT_CLASS_P (expr) && TREE_CODE (expr) != STRING_CST)
+       || (TREE_CODE (expr) == CONST_DECL && !TREE_STATIC (expr)))
+       ? NON_LVALUE_EXPR : VIEW_CONVERT_EXPR);
   tree wrapper = build1_loc (loc, code, TREE_TYPE (expr), expr);
   /* Mark this node as being a wrapper.  */
   EXPR_LOCATION_WRAPPER_P (wrapper) = 1;