public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r9-9547] c++: constexpr and volatile member function [PR80456] Date: Fri, 21 May 2021 14:50:48 +0000 (GMT) [thread overview] Message-ID: <20210521145048.C47A4384A00F@sourceware.org> (raw) https://gcc.gnu.org/g:0c6b4e661d875410535e17a9d82e6a0d09f28c65 commit r9-9547-g0c6b4e661d875410535e17a9d82e6a0d09f28c65 Author: Jason Merrill <jason@redhat.com> 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 82303e093ef..7f76bd905ca 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -9944,7 +9944,8 @@ build_new_method_call_1 (tree instance, tree fns, vec<tree, va_gc> **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(); +}
reply other threads:[~2021-05-21 14:50 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210521145048.C47A4384A00F@sourceware.org \ --to=jason@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).