aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2017-12-18 21:25:16 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2017-12-18 21:25:16 +0000
commit4a58d2fe83ca6325f6ba4384eb9be6008ad65f3b (patch)
treeb2bee25f88cb8e33d0cfc96ef0db01f83694700f
parentaa8ec7fb260489a0af7578c727c4b41ebc1ae593 (diff)
downloadgcc-4a58d2fe83ca6325f6ba4384eb9be6008ad65f3b.zip
gcc-4a58d2fe83ca6325f6ba4384eb9be6008ad65f3b.tar.gz
gcc-4a58d2fe83ca6325f6ba4384eb9be6008ad65f3b.tar.bz2
re PR c++/83116 (Statement with no effect causes wrong code of static object constexpr method)
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
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/constexpr.c2
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/constexpr-83116.C18
4 files changed, 30 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index b6e782a..6ac963a 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 0455be1..518798e 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -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));
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index da078f1..129d142 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..18d79e2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-83116.C
@@ -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 ();
+}