Files
Gabor Horvath e79e04c0a6 [cxx-interop] Mark C++ reference parameters @addressable
C++ code can return values that depend on the storage that backs the
references that were passed in as argument. Thus, swift should not
introdue temporary copies of that storage before invoking those
functions as they could result in lifetime issues.
2025-02-11 11:10:51 +00:00

51 lines
1.9 KiB
C

#ifndef TEST_INTEROP_CXX_CLASS_METHOD_METHODS_H
#define TEST_INTEROP_CXX_CLASS_METHOD_METHODS_H
struct __attribute__((swift_attr("import_unsafe"))) NonTrivialInWrapper {
int value;
NonTrivialInWrapper(int value) : value(value) {}
// explicit copy constructor is needed, as on Windows a destructor
// still makes this a type that's passed in registers.
NonTrivialInWrapper(const NonTrivialInWrapper &other) : value(other.value) {}
~NonTrivialInWrapper() { }
};
struct HasMethods {
void nonConstMethod() { }
void nonConstMethod(int) { }
static void nonConstMethod(float) { } // checking name colisions: rdar://120858502
void constMethod() const { }
static void constMethod(float) { } // checking name colisions: rdar://120858502
int nonConstPassThrough(int a) { return a; }
int constPassThrough(int a) const { return a; }
int nonConstSum(int a, int b) { return a + b; }
int constSum(int a, int b) const { return a + b; }
int nonConstSum(NonTrivialInWrapper a, NonTrivialInWrapper b) { return a.value + b.value; }
int constSum(NonTrivialInWrapper a, NonTrivialInWrapper b) const { return a.value + b.value; }
NonTrivialInWrapper nonConstSumAsWrapper(NonTrivialInWrapper a, NonTrivialInWrapper b) { return {a.value + b.value}; }
NonTrivialInWrapper constSumAsWrapper(NonTrivialInWrapper a, NonTrivialInWrapper b) const { return {a.value + b.value}; }
NonTrivialInWrapper nonConstPassThroughAsWrapper(int a) { return {a}; }
NonTrivialInWrapper constPassThroughAsWrapper(int a) const { return {a}; }
void nonTrivialTakesConstRef(const NonTrivialInWrapper& w) const {}
void nonTrivialTakesRef(NonTrivialInWrapper& w) const {}
};
struct ReferenceParams {
int a;
int b;
ReferenceParams(const int &a, const int &b) : a(a), b(b) { }
static void staticMethod(const int &a, const int &b) {
ReferenceParams t{a, b};
}
};
#endif // TEST_INTEROP_CXX_CLASS_METHOD_METHODS_H