aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/call.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2021-04-15 15:13:18 -0400
committerJason Merrill <jason@redhat.com>2021-04-15 16:32:00 -0400
commit3682052e4ccf0a29d1f61df1c8e31f8190eafafe (patch)
treec1e7ea4ee939342e91e67c24b355a168a8dc2d4e /gcc/cp/call.c
parent2dbbbe893f75f587c48111ab4c97cf5e74fb91bb (diff)
downloadgcc-3682052e4ccf0a29d1f61df1c8e31f8190eafafe.zip
gcc-3682052e4ccf0a29d1f61df1c8e31f8190eafafe.tar.gz
gcc-3682052e4ccf0a29d1f61df1c8e31f8190eafafe.tar.bz2
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.
Diffstat (limited to 'gcc/cp/call.c')
-rw-r--r--gcc/cp/call.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index c9a8c0d..678e120a 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -10793,7 +10793,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)