Skip to content

Commit 33946f5

Browse files
committed
Fixed build erros with MSVCC.
1 parent bb1a26f commit 33946f5

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

include/expectations/expectation.hpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -472,13 +472,15 @@ template <typename F>
472472
class ExpectationFunc : public Expectation<decltype(std::declval<F>()())> {
473473
static_assert(Util::is_functional<F>::value,
474474
"Error! ExpectationFunc can only contaion lambdas.");
475+
476+
typedef decltype(std::declval<F>()()) block_ret_t;
475477
F block;
476-
std::shared_ptr<decltype(std::declval<F>()())> computed = nullptr;
478+
std::shared_ptr<block_ret_t> computed = nullptr;
477479

478480
public:
479481
ExpectationFunc(ExpectationFunc<F> const &copy)
480-
: Expectation<decltype(std::declval<F>()())>(copy), block(copy.block) {}
481-
482+
: Expectation<block_ret_t>(copy), block(copy.block) {}
483+
482484
/**
483485
* @brief Create an ExpectationValue using a value.
484486
*
@@ -487,8 +489,8 @@ class ExpectationFunc : public Expectation<decltype(std::declval<F>()())> {
487489
* @return The constructed ExpectationValue.
488490
*/
489491
ExpectationFunc(ItBase &it, F block)
490-
: Expectation<decltype(block())>(it), block(block) {}
491-
492+
: Expectation<block_ret_t>(it), block(block) {}
493+
492494
/**
493495
* @brief Create an Expectation using a function.
494496
*
@@ -507,9 +509,9 @@ class ExpectationFunc : public Expectation<decltype(std::declval<F>()())> {
507509
// {}
508510

509511
/** @brief Get the target of the expectation. */
510-
decltype(block()) &get_target() & override {
511-
if (!computed) {
512-
computed = std::make_shared<decltype(block())>(block());
512+
block_ret_t &get_target() & override {
513+
if (computed == nullptr) {
514+
computed = std::make_shared<block_ret_t>(block());
513515
}
514516
return *computed;
515517
}

spec/expectations/expectation_spec.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,11 @@ describe expectation_spec("Expectation", $ {
101101
});
102102

103103
context("ExpectationFunc", _ {
104-
it("is lazy", _{
105-
auto foo = [] { return 1 + 2; };
104+
it("is lazy", _{
105+
// MSVCC optimizes this away into an int, when
106+
// we explicitly want a function. Any other time
107+
// that would be perfectly okay.
108+
std::function<int()> foo = [] { return 1 + 2; };
106109
Expectations::ExpectationFunc<decltype(foo)> expectation(self, foo);
107110
expect(expectation.get_target()).to_equal(3);
108111
});

0 commit comments

Comments
 (0)