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.
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)
--- /dev/null
+// 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();
+}