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 400354 522135225936a32c7b084ba7eea082ee025ea7d5
parent 400353 a658af6ae5998775cef3d7cf9c1399669e105379
child 400355 6cd485867a7df91ba8e2c363b5696d70e691daf8
push id26137
push userbmo:jbeich@FreeBSD.org
push dateSat, 13 Aug 2016 02:43:24 +0000
reviewersfroydnj
bugs1294537
milestone51.0a1
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