Bug 1294537 - Don't tag |void* p| in the don't-nullcheck placement operator new overload as MOZ_NONNULL, because that makes a double-checking assertion of non-nullness into a compiler warning. r=froydnj
authorJeff Walden <jwalden@mit.edu>
Fri, 12 Aug 2016 18:02:03 -0700
changeset 350632 522135225936a32c7b084ba7eea082ee025ea7d5
parent 350631 a658af6ae5998775cef3d7cf9c1399669e105379
child 350633 6cd485867a7df91ba8e2c363b5696d70e691daf8
push id6570
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:26:13 +0000
treeherdermozilla-beta@f455459b2ae5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1294537
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1294537 - Don't tag |void* p| in the don't-nullcheck placement operator new overload as MOZ_NONNULL, because that makes a double-checking assertion of non-nullness into a compiler warning. r=froydnj
mfbt/OperatorNewExtensions.h
--- a/mfbt/OperatorNewExtensions.h
+++ b/mfbt/OperatorNewExtensions.h
@@ -5,17 +5,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* A version of |operator new| that eschews mandatory null-checks. */
 
 #ifndef mozilla_OperatorNewExtensions_h
 #define mozilla_OperatorNewExtensions_h
 
 #include "mozilla/Assertions.h"
-#include "mozilla/Attributes.h"
 
 // Credit goes to WebKit for this implementation, cf.
 // https://bugs.webkit.org/show_bug.cgi?id=74676
 namespace mozilla {
 enum NotNullTag {
   KnownNotNull,
 };
 } // namespace mozilla
@@ -34,20 +33,20 @@ enum NotNullTag {
  * just such an overload.
  *
  * You might think that MOZ_NONNULL might perform the same function, but
  * MOZ_NONNULL isn't supported on all of our compilers, and even when it is
  * supported, doesn't work on all the versions we support.  And even keeping
  * those limitations in mind, we can't put MOZ_NONNULL on the global,
  * standardized placement new function in any event.
  *
- * We do, however, add MOZ_NONNULL here for the potential benefit of static
- * analysis tools that understand such annotations.
+ * We deliberately don't add MOZ_NONNULL(3) to tag |p| as non-null, to benefit
+ * hypothetical static analyzers.  Doing so makes |MOZ_ASSERT(p)|'s internal
+ * test vacuous, and some compilers warn about such vacuous tests.
  */
-MOZ_NONNULL(3)
 inline void*
 operator new(size_t, mozilla::NotNullTag, void* p)
 {
   MOZ_ASSERT(p);
   return p;
 }
 
 #endif // mozilla_OperatorNewExtensions_h