From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id 47DB2398B85B; Thu, 20 May 2021 21:36:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 47DB2398B85B MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r10-9856] c++: constexpr and volatile member function [PR80456] X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: fe0f9ef823dda3205638a2f23d08eb7d0bc497b9 X-Git-Newrev: 75c5c4ab2662a92f0e3811cb17e27cc61814b400 Message-Id: <20210520213602.47DB2398B85B@sourceware.org> Date: Thu, 20 May 2021 21:36:02 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 May 2021 21:36:02 -0000 https://gcc.gnu.org/g:75c5c4ab2662a92f0e3811cb17e27cc61814b400 commit r10-9856-g75c5c4ab2662a92f0e3811cb17e27cc61814b400 Author: Jason Merrill Date: Thu Apr 15 15:13:18 2021 -0400 c++: constexpr and volatile member function [PR80456] When calling a static member function we still need to evaluate an explicit object argument. But we don't want to force a load of the entire object if the argument is volatile, so we take its address. If as a result it no longer has any side-effects, we don't need to evaluate it after all. gcc/cp/ChangeLog: PR c++/80456 * call.c (build_new_method_call_1): Check again for side-effects with a volatile object. gcc/testsuite/ChangeLog: PR c++/80456 * g++.dg/cpp0x/constexpr-volatile3.C: New test. Diff: --- gcc/cp/call.c | 3 ++- gcc/testsuite/g++.dg/cpp0x/constexpr-volatile3.C | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/gcc/cp/call.c b/gcc/cp/call.c index d4515f21e04..c403243be50 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -10447,7 +10447,8 @@ build_new_method_call_1 (tree instance, tree fns, vec **args, tree a = instance; if (TREE_THIS_VOLATILE (a)) a = build_this (a); - call = build2 (COMPOUND_EXPR, TREE_TYPE (call), a, call); + if (TREE_SIDE_EFFECTS (a)) + call = build2 (COMPOUND_EXPR, TREE_TYPE (call), a, call); } else if (call != error_mark_node && DECL_DESTRUCTOR_P (cand->fn) diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-volatile3.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-volatile3.C new file mode 100644 index 00000000000..5c1e865e0ac --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-volatile3.C @@ -0,0 +1,15 @@ +// PR c++/80456 +// { dg-do compile { target c++11 } } + +struct A { + static constexpr bool test() noexcept { return true; } + + void f() volatile { + constexpr bool b = test(); + } +}; + +void g() { + A a; + a.f(); +}