Files
swift-mirror/test/Interop/Cxx/reference/Inputs/print-special-members.h
Gabor Horvath 00fa738209 [cxx-interop] Fix calling convention for rvalue reference params
In C++, we always expected to invoke the dtor for moved-from objects.
This is not the case for swift. Fortunately, @inCxx calling convention
is already expressing that the caller supposed to destroy the object.
This fixes the missing dtor calls when calling C++ functions taking
rvalue references. Fixes #77894.

rdar://140786022
2025-03-03 11:47:12 +00:00

22 lines
761 B
C

#pragma once
#include <cstdio>
struct MoveOnly {
int id;
MoveOnly() : id(0) { printf("MoveOnly %d created\n", id); }
MoveOnly(const MoveOnly&) = delete;
MoveOnly(MoveOnly&& other) : id(other.id + 1) { printf("MoveOnly %d move-created\n", id); }
~MoveOnly() { printf("MoveOnly %d destroyed\n", id); }
};
struct Copyable {
int id;
Copyable() : id(0) { printf("Copyable %d created\n", id); }
Copyable(const Copyable& other) : id(other.id + 1) { printf("Copyable %d copy-created\n", id); }
Copyable(Copyable&& other) : id(other.id + 1) { printf("Copyable %d move-created\n", id); }
~Copyable() { printf("Copyable %d destroyed\n", id); }
};
inline void byRValueRef(MoveOnly&& x) {}
inline void byRValueRef(Copyable&& x) {}