mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
If a templated C++ class declares an operator as a member function, and is instantiated using a typedef or a using-decl on the C++ side, it previously could not be conformed to a Swift protocol that requires the operator function despite matching signatures. This was due to a Swift name lookup issue: operators, unlike regular member functions, are found by doing an unqualified lookup. Since C++ class template specializations and their members are not added to `SwiftLookupTable`, when doing qualified lookup members are searched by looking at all of the members of the specialization and choosing the ones with matching names. With unqualified lookup, we cannot rely on knowing the right specialization and need to search for all the operators in a given module. This change adds synthesized operator thunks to `SwiftLookupTable` to make them discoverable by unqualified lookup.
70 lines
1.4 KiB
C++
70 lines
1.4 KiB
C++
#ifndef TEST_INTEROP_CXX_CLASS_INPUTS_PROTOCOL_CONFORMANCE_H
|
|
#define TEST_INTEROP_CXX_CLASS_INPUTS_PROTOCOL_CONFORMANCE_H
|
|
|
|
struct ConformsToProtocol {
|
|
int return42() { return 42; }
|
|
};
|
|
|
|
struct DoesNotConformToProtocol {
|
|
int returnFortyTwo() { return 42; }
|
|
};
|
|
|
|
struct DummyStruct {};
|
|
|
|
struct __attribute__((swift_attr("import_unsafe"))) NonTrivial {
|
|
~NonTrivial() {}
|
|
NonTrivial(DummyStruct) {}
|
|
NonTrivial() {}
|
|
void test1() {}
|
|
void test2(int) {}
|
|
char test3(int, unsigned) { return 42; }
|
|
};
|
|
|
|
struct Trivial {
|
|
Trivial(DummyStruct) {}
|
|
Trivial() {}
|
|
void test1() {}
|
|
void test2(int) {}
|
|
char test3(int, unsigned) { return 42; }
|
|
};
|
|
|
|
struct ReturnsNullableValue {
|
|
const int *returnPointer() __attribute__((swift_attr("import_unsafe"))) {
|
|
return nullptr;
|
|
}
|
|
};
|
|
|
|
struct ReturnsNonNullValue {
|
|
const int *returnPointer() __attribute__((returns_nonnull))
|
|
__attribute__((swift_attr("import_unsafe"))) {
|
|
return (int *)this;
|
|
}
|
|
};
|
|
|
|
struct HasOperatorExclaim {
|
|
int value;
|
|
|
|
HasOperatorExclaim operator!() const { return {-value}; }
|
|
};
|
|
|
|
struct HasOperatorEqualEqual {
|
|
int value;
|
|
|
|
bool operator==(const HasOperatorEqualEqual &other) const {
|
|
return value == other.value;
|
|
}
|
|
};
|
|
|
|
template <typename T>
|
|
struct HasOperatorPlusEqual {
|
|
T value;
|
|
|
|
HasOperatorPlusEqual &operator+=(int x) {
|
|
value += x;
|
|
return *this;
|
|
}
|
|
};
|
|
|
|
using HasOperatorPlusEqualInt = HasOperatorPlusEqual<int>;
|
|
|
|
#endif // TEST_INTEROP_CXX_CLASS_INPUTS_PROTOCOL_CONFORMANCE_H
|