Skip to content

Commit e8c2241

Browse files
authored
[orc-rt] std::forward unbound arguments when using bind_front. (#155723)
The call operator for the type returned by bind_front should forward its arguments, rather than moving them. This ensures that we handle lvalue references in unbound args correctly: auto B = bind_front([](int &) {}); int N = 7; B(N); // <- no longer an error!
1 parent 9bf5bf3 commit e8c2241

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

orc-rt/include/orc-rt/bind.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ template <typename Fn, typename... BoundArgTs> class BoundFn {
2525
private:
2626
template <size_t... Is, typename... ArgTs>
2727
auto callExpandingBound(std::index_sequence<Is...>, ArgTs &&...Args) {
28-
return F(std::get<Is>(BoundArgs)..., std::move(Args)...);
28+
return F(std::get<Is>(BoundArgs)..., std::forward<ArgTs>(Args)...);
2929
}
3030

3131
public:

orc-rt/unittests/bind-test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ TEST(BindTest, MinimalCopies) {
7171
EXPECT_EQ(OpCounter::destructions(), 2U);
7272
}
7373

74+
TEST(BindTest, ForwardUnboundArgs) {
75+
auto B = bind_front([](int &) {});
76+
int N = 7;
77+
B(N);
78+
}
79+
7480
static int increment(int N) { return N + 1; }
7581

7682
TEST(BindTest, BindFunction) {

0 commit comments

Comments
 (0)