Skip to content

Commit 4d6c8da

Browse files
committed
Swift: no perfect forwarding for label fetchers
While we need universal references to catch different value categories, we don't need perfect forwarding as `fetchLabel` does not behave differently on lvalue and rvalues.
1 parent 6e44a12 commit 4d6c8da

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

swift/extractor/SwiftDispatcher.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,21 +126,24 @@ class SwiftDispatcher {
126126
}
127127

128128
// return `std::optional(fetchLabel(arg))` if arg converts to true, otherwise std::nullopt
129+
// universal reference `Arg&&` is used to catch both temporary and non-const references, not
130+
// for perfect forwarding
129131
template <typename Arg>
130-
auto fetchOptionalLabel(Arg&& arg)
131-
-> std::optional<decltype(fetchLabel(std::forward<Arg>(arg)))> {
132+
auto fetchOptionalLabel(Arg&& arg) -> std::optional<decltype(fetchLabel(arg))> {
132133
if (arg) {
133-
return fetchLabel(std::forward<Arg>(arg));
134+
return fetchLabel(arg);
134135
}
135136
return std::nullopt;
136137
}
137138

138139
// map `fetchLabel` on the iterable `arg`, returning a vector of all labels
140+
// universal reference `Arg&&` is used to catch both temporary and non-const references, not
141+
// for perfect forwarding
139142
template <typename Iterable>
140143
auto fetchRepeatedLabels(Iterable&& arg) {
141144
std::vector<decltype(fetchLabel(*arg.begin()))> ret;
142145
ret.reserve(arg.size());
143-
for (const auto& e : std::forward<Iterable>(arg)) {
146+
for (auto&& e : arg) {
144147
ret.push_back(fetchLabel(e));
145148
}
146149
return ret;

0 commit comments

Comments
 (0)