Bug
Bug 1355739 - Part2: Add a test case by passing a lvalue callable object.
MozReview-Commit-ID: JMltRmDnWFf
--- a/mfbt/tests/TestScopeExit.cpp
+++ b/mfbt/tests/TestScopeExit.cpp
@@ -13,38 +13,53 @@ using mozilla::MakeScopeExit;
do { \
bool cond = !!(c); \
MOZ_RELEASE_ASSERT(cond, "Failed assertion: " #c); \
if (!cond) { \
return false; \
} \
} while (false)
+class Functor
+{
+public:
+ MOZ_IMPLICIT Functor(int& aValue) : mValue(aValue) { }
+ int operator()() { return --mValue; }
+
+private:
+ int& mValue;
+};
+
static bool
Test()
{
int a = 1;
int b = 1;
-
+ int c = 1;
{
a++;
auto guardA = MakeScopeExit([&] {
a--;
});
b++;
auto guardB = MakeScopeExit([&] {
b--;
});
guardB.release();
+
+ c++;
+ Functor lValueFunctor(c);
+ auto guardC = MakeScopeExit(lValueFunctor);
}
CHECK(a == 1);
CHECK(b == 2);
+ CHECK(c == 1);
return true;
}
int
main()
{
if (!Test()) {