Bug 1291423: Explicitly qualify the destructor call that we invoke in Maybe::reset. r=Waldo draft
authorDaniel Holbert <dholbert@cs.stanford.edu>
Tue, 02 Aug 2016 14:59:24 -0700
changeset 395793 0ec5ba62c348238ffe12e556511dd801df490977
parent 395790 9cc951558a1754b1eac8e3840576526e61e2d286
child 527062 9e59f5340c03f9c18d5d418c78c3cf59628995d8
push id24847
push userdholbert@mozilla.com
push dateTue, 02 Aug 2016 22:00:17 +0000
reviewersWaldo
bugs1291423
milestone51.0a1
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
mfbt/Maybe.h
mfbt/tests/TestMaybe.cpp
--- 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;
 }