-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.c++ interopFeature: Interoperability with C++Feature: Interoperability with C++
Description
Description
If a C++ class that defines an overload for the bitwise negation operator (~) is imported by Swift, that operator will not be available from Swift.
Reproduction
//CxxLibrary.h
class Foo {
int bar;
public:
Foo(int bar) : bar(bar) { }
Foo operator ~() const {
return Foo(~bar);
}
};import CxxLibrary
let negated = ~Foo(42) //error: referencing operator function '~' on 'BinaryInteger' requires that 'Foo' conform to 'BinaryInteger'Expected behavior
The ~ operator can be used without error.
Environment
swift-driver version: 1.127.11.2 Apple Swift version 6.2 (swiftlang-6.2.0.16.14 clang-1700.3.16.4)
Target: x86_64-apple-macosx15.0
Additional information
Notably, if a C++ class defines an overload for the logical negation operator (!), it will be available.
//CxxLibrary.h
class Foo {
int bar;
public:
Foo(int bar) : bar(bar) { }
Foo operator !() const {
return Foo(!bar);
}
};import CxxLibrary
let negated = !Foo(42) //successMetadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.c++ interopFeature: Interoperability with C++Feature: Interoperability with C++