Skip to content

Add support for importing operator function templates from C++ #83153

@maddyadams

Description

@maddyadams

Description

No response

Reproduction

#include <vector>

template <typename T>
struct MyVec {
    MyVec() = default;
    MyVec(std::vector<T> impl) : impl(impl) {}
    
    std::vector<T> impl;
};

template <typename T>
T operator+(T lhs, T rhs) {
    std::vector<T> lhsImpl;
    std::vector<T> rhsImpl;
    for (int i = 0; i < std::min(lhsImpl.size(), rhsImpl.size()); i++) {
        lhsImpl[i] += rhsImpl[i];
    }
    return T(lhsImpl);
}

using MyIntVec = MyVec<int>;
let a = MyIntVec([1, 2, 3])
let b = MyIntVec([4, 5, 6])
let c = a + b // Binary operator '+' cannot be applied to two 'MyIntVec' (aka 'MyVec<CInt>') operands

Expected behavior

I expected the code would compile

Environment

swift-driver version: 1.120.5 Apple Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3)
Target: arm64-apple-macosx15.0

Additional information

rdar://151168686

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions