Skip to content

Commit 3a0746b

Browse files
committed
Fix reference types in the return type
* Closes #35
1 parent e44d97f commit 3a0746b

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

include/function2/function2.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -990,13 +990,13 @@ class vtable<property<IsThrowing, HasStrongExceptGuarantee, FormalArgs...>> {
990990

991991
/// Invoke the function at the given index
992992
template <std::size_t Index, typename... Args>
993-
constexpr auto invoke(Args&&... args) const {
993+
constexpr decltype(auto) invoke(Args&&... args) const {
994994
auto thunk = invoke_table_t::template fetch<Index>(vtable_);
995995
return thunk(std::forward<Args>(args)...);
996996
}
997997
/// Invoke the function at the given index
998998
template <std::size_t Index, typename... Args>
999-
constexpr auto invoke(Args&&... args) const volatile {
999+
constexpr decltype(auto) invoke(Args&&... args) const volatile {
10001000
auto thunk = invoke_table_t::template fetch<Index>(vtable_);
10011001
return thunk(std::forward<Args>(args)...);
10021002
}
@@ -1208,7 +1208,7 @@ class erasure : internal_capacity_holder<typename Config::capacity> {
12081208
/// We define this out of class to be able to forward the qualified
12091209
/// erasure correctly.
12101210
template <std::size_t Index, typename Erasure, typename... Args>
1211-
static constexpr auto invoke(Erasure&& erasure, Args&&... args) {
1211+
static constexpr decltype(auto) invoke(Erasure&& erasure, Args&&... args) {
12121212
auto const capacity = erasure.capacity();
12131213
return erasure.vtable_.template invoke<Index>(
12141214
std::forward<Erasure>(erasure).opaque_ptr(), capacity,
@@ -1324,7 +1324,7 @@ class erasure<false, Config,
13241324
}
13251325

13261326
template <std::size_t Index, typename Erasure, typename... T>
1327-
static constexpr auto invoke(Erasure&& erasure, T&&... args) {
1327+
static constexpr decltype(auto) invoke(Erasure&& erasure, T&&... args) {
13281328
auto thunk = invoke_table_t::template fetch<Index>(erasure.invoke_table_);
13291329
return thunk(&(erasure.view_), 0UL, std::forward<T>(args)...);
13301330
}

test/regressions.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,37 @@ TEST(regression_tests, unique_non_copyable) {
198198
199199
ASSERT_EQ(view(), 5);
200200
}*/
201+
202+
namespace issue_35 {
203+
class ref_obj {
204+
public:
205+
ref_obj() = default;
206+
ref_obj(ref_obj const&) = delete;
207+
ref_obj(ref_obj&&) = default;
208+
ref_obj& operator=(ref_obj&&) = default;
209+
ref_obj& operator=(ref_obj const&) = delete;
210+
211+
int data() const {
212+
return data_;
213+
}
214+
215+
private:
216+
int data_{8373827};
217+
};
218+
219+
ref_obj& ref_obj_getter() {
220+
static ref_obj some;
221+
return some;
222+
}
223+
} // namespace issue_35
224+
225+
ALL_LEFT_TYPED_TEST_CASE(AllReferenceRetConstructTests)
226+
227+
// https://github.com/Naios/function2/issues/35
228+
TYPED_TEST(AllReferenceRetConstructTests, reference_returns_not_buildable) {
229+
using namespace issue_35;
230+
231+
typename TestFixture::template left_t<ref_obj&()> left(&ref_obj_getter);
232+
ref_obj& ref = left();
233+
ASSERT_EQ(ref.data(), 8373827);
234+
}

0 commit comments

Comments
 (0)