PR c++/87372 - __func__ constexpr evaluation.
authorMarek Polacek <polacek@redhat.com>
Fri, 21 Sep 2018 18:45:59 +0000 (18:45 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 21 Sep 2018 18:45:59 +0000 (18:45 +0000)
* constexpr.c (maybe_constant_init_1): Pass false for strict down to
cxx_eval_outermost_constant_expr.

* g++.dg/cpp1y/func_constexpr2.C: New test.

From-SVN: r264489

gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1y/func_constexpr2.C [new file with mode: 0644]

index b75d0c70589c31c1732042ded4937182b0643cf5..079d1cb8574609021b1348353f5c06f7b07084d0 100644 (file)
@@ -1,3 +1,9 @@
+2018-09-21  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/87372 - __func__ constexpr evaluation.
+       * constexpr.c (maybe_constant_init_1): Pass false for strict down to
+       cxx_eval_outermost_constant_expr.
+
 2018-09-20  Marek Polacek  <polacek@redhat.com>
 
        PR c++/87109 - wrong ctor with maybe-rvalue semantics.
index b4814743784a3f1c37808e15ef468559e0b0233a..08d00e859d8773d33830ae722d2f88167e80f792 100644 (file)
@@ -5364,7 +5364,7 @@ maybe_constant_init_1 (tree t, tree decl, bool allow_non_constant,
     /* No evaluation needed.  */;
   else
     t = cxx_eval_outermost_constant_expr (t, allow_non_constant,
-                                         !allow_non_constant,
+                                         /*strict*/false,
                                          pretend_const_required, decl);
   if (TREE_CODE (t) == TARGET_EXPR)
     {
index ea6cefb5f35cb2185cc6a4571db104aa38a19cd5..c6ea7f17b1caf475281fd8ae7b35578763c46d38 100644 (file)
@@ -1,3 +1,8 @@
+2018-09-21  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/87372 - __func__ constexpr evaluation.
+       * g++.dg/cpp1y/func_constexpr2.C: New test.
+
 2018-09-21  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/77325
diff --git a/gcc/testsuite/g++.dg/cpp1y/func_constexpr2.C b/gcc/testsuite/g++.dg/cpp1y/func_constexpr2.C
new file mode 100644 (file)
index 0000000..b1576e6
--- /dev/null
@@ -0,0 +1,21 @@
+// PR c++/87372
+// { dg-do compile { target c++14 } }
+
+constexpr int
+foo (char const *s)
+{
+  int i = 0;
+  while (s[i])
+    ++i;
+  return i;
+}
+
+constexpr int
+bar ()
+{
+  constexpr int l = foo (__PRETTY_FUNCTION__);
+  constexpr int l2 = foo (__FUNCTION__);
+  constexpr int l3 = foo (__func__);
+  return l + l2 + l3;
+}
+static_assert (bar () == 25, "");