We miscompile the below testcase because keep_unused_object_arg thinks
the object argument of an xobj member function is unused, and so it ends
up duplicating the argument's side effects.
PR c++/113640
gcc/cp/ChangeLog:
* call.cc (keep_unused_object_arg): Punt for an xobj member
function.
gcc/testsuite/ChangeLog:
* g++.dg/cpp23/explicit-obj-lambda14.C: New test.
Reviewed-by: Jason Merrill <jason@redhat.com>
{
if (result == NULL_TREE
|| result == error_mark_node
- || TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE
+ || DECL_OBJECT_MEMBER_FUNCTION_P (fn)
|| !TREE_SIDE_EFFECTS (obj))
return result;
--- /dev/null
+// PR c++/113640
+// { dg-do run { target c++23 } }
+
+static int total;
+
+struct A {
+ A f(this auto self, int n) {
+ total += n;
+ return self;
+ }
+};
+
+int main() {
+ A a;
+ a.f(1).f(42).f(100);
+ if (total != 143)
+ __builtin_abort();
+
+ auto l = [](this auto self, int n) {
+ total += n;
+ return self;
+ };
+ total = 0;
+ l(1)(42)(100);
+ if (total != 143)
+ __builtin_abort();
+}