re PR c++/83116 (Statement with no effect causes wrong code of static object constexp...
authorMarek Polacek <polacek@redhat.com>
Mon, 18 Dec 2017 21:25:16 +0000 (21:25 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Mon, 18 Dec 2017 21:25:16 +0000 (21:25 +0000)
PR c++/83116
* constexpr.c (cxx_eval_call_expression): Only look into
constexpr_call_table if ctx->strict.

* g++.dg/cpp1y/constexpr-83116.C: New test.

From-SVN: r255788

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

index b6e782a389c573f35b90959e613e83b6a1746278..6ac963ae99a5d55754b129ec21b89e8e8e8c907f 100644 (file)
@@ -1,3 +1,9 @@
+2017-12-18  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/83116
+       * constexpr.c (cxx_eval_call_expression): Only look into
+       constexpr_call_table if ctx->strict.
+
 2017-12-18  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/83300
index 0455be1d6dae2742691da4948ad462fc8eccd79a..518798e0c431819a9b8aef60035e37a5c5144643 100644 (file)
@@ -1588,7 +1588,7 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t,
   tree result = NULL_TREE;
 
   constexpr_call *entry = NULL;
-  if (depth_ok && !non_constant_args)
+  if (depth_ok && !non_constant_args && ctx->strict)
     {
       new_call.hash = iterative_hash_template_arg
        (new_call.bindings, constexpr_fundef_hasher::hash (new_call.fundef));
index da078f123304d99ff8f2395e6d0fce0bad73ece6..129d142a83cb1d2f8a7ccbba40162d765064d6c7 100644 (file)
@@ -1,3 +1,8 @@
+2017-12-18  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/83116
+       * g++.dg/cpp1y/constexpr-83116.C: New test.
+
 2017-12-18  Segher Boessenkool  <segher@kernel.crashing.org>
 
        PR rtl-optimization/83424
diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-83116.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-83116.C
new file mode 100644 (file)
index 0000000..18d79e2
--- /dev/null
@@ -0,0 +1,18 @@
+// PR c++/83116
+// { dg-do run { target c++14 } }
+// { dg-options "-O2" }
+
+struct S {
+  constexpr S () : s(0) { foo (); }
+  constexpr int foo () { return s; }
+  int s;
+};
+
+int
+main ()
+{
+  static S var;
+  var.s = 5;
+  if (var.s != 5 || var.foo () != 5)
+    __builtin_abort ();
+}