Bug 1291423: Explicitly qualify the destructor call that we invoke in Maybe::reset. r=Waldo
MozReview-Commit-ID: 6vQouBSxnsZ
* * *
[mq]: 1291423-test.patch
MozReview-Commit-ID: AfByE1odDx5
--- a/mfbt/Maybe.h
+++ b/mfbt/Maybe.h
@@ -369,17 +369,17 @@ public:
}
return Maybe<ReturnType>();
}
/* If |isSome()|, empties this Maybe and destroys its contents. */
void reset()
{
if (isSome()) {
- ref().~T();
+ ref().T::~T();
mIsSome = false;
}
}
/*
* Constructs a T value in-place in this empty Maybe<T>'s storage. The
* arguments to |emplace()| are the parameters to T's constructor.
*/
--- a/mfbt/tests/TestMaybe.cpp
+++ b/mfbt/tests/TestMaybe.cpp
@@ -731,21 +731,47 @@ TestComparisonOperators()
MOZ_RELEASE_ASSERT(nothingValue >= anotherNothingValue);
MOZ_RELEASE_ASSERT(oneValue >= nothingValue);
MOZ_RELEASE_ASSERT(oneValue >= oneValue);
MOZ_RELEASE_ASSERT(twoValue >= oneValue);
return true;
}
+// Check that Maybe<> can wrap a superclass that happens to also be a concrete
+// class (i.e. that the compiler doesn't warn when we invoke the superclass's
+// destructor explicitly in |reset()|.
+class MySuperClass {
+ virtual void VirtualMethod() { /* do nothing */ }
+};
+
+class MyDerivedClass : public MySuperClass {
+ void VirtualMethod() override { /* do nothing */ }
+};
+
+static bool
+TestVirtualFunction() {
+ Maybe<MySuperClass> super;
+ super.emplace();
+ super.reset();
+
+ Maybe<MySuperClass> derived;
+ derived.emplace();
+ derived.reset();
+
+ // If this compiles successfully, we've passed.
+ return true;
+}
+
int
main()
{
RUN_TEST(TestBasicFeatures);
RUN_TEST(TestCopyAndMove);
RUN_TEST(TestFunctionalAccessors);
RUN_TEST(TestApply);
RUN_TEST(TestMap);
RUN_TEST(TestToMaybe);
RUN_TEST(TestComparisonOperators);
+ RUN_TEST(TestVirtualFunction);
return 0;
}