From fe513fce568f834e1ff24a6ca70fc6dee061013c Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Tue, 19 Dec 2017 10:02:48 +0000 Subject: [PATCH] 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: r255813 --- gcc/cp/ChangeLog | 9 +++++++++ gcc/cp/constexpr.c | 2 +- gcc/testsuite/g++.dg/cpp1y/constexpr-83116.C | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/constexpr-83116.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3c9dc8f4138..d77663a88d4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2017-12-19 Marek Polacek + + Backported from mainline + 2017-12-18 Marek Polacek + + PR c++/83116 + * constexpr.c (cxx_eval_call_expression): Only look into + constexpr_call_table if ctx->strict. + 2017-12-16 Jakub Jelinek Backported from mainline diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 327c093a953..9082230b9d5 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -1558,7 +1558,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/g++.dg/cpp1y/constexpr-83116.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-83116.C new file mode 100644 index 00000000000..18d79e2e1cc --- /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 (); +}