Fix UBSAN failure in RangeTest.cpp with libstdc++-v4.9
[folly.git] / folly / PackedSyncPtr.h
index 64337674f5f3a53b1dca735f94db26684aaecf34..a49b0270d0c25a23b699ab9b7701ee3cbfb927a7 100644 (file)
 
 #pragma once
 
+#include <type_traits>
+
+#include <glog/logging.h>
+
 #include <folly/Portability.h>
+#include <folly/SmallLocks.h>
 
-#if !FOLLY_X64 && !FOLLY_PPC64
-# error "PackedSyncPtr is x64 and ppc64 specific code."
+#if !FOLLY_X64 && !FOLLY_PPC64 && !FOLLY_AARCH64
+#error "PackedSyncPtr is x64, ppc64 or aarch64 specific code."
 #endif
 
 /*
  * @author Jordan DeLong <delong.j@fb.com>
  */
 
-#include <folly/SmallLocks.h>
-#include <type_traits>
-#include <glog/logging.h>
-
 namespace folly {
 
-template<class T>
+template <class T>
 class PackedSyncPtr {
   // This just allows using this class even with T=void.  Attempting
   // to use the operator* or operator[] on a PackedSyncPtr<void> will
   // still properly result in a compile error.
   typedef typename std::add_lvalue_reference<T>::type reference;
 
-public:
+ public:
   /*
    * If you default construct one of these, you must call this init()
    * function before using it.
@@ -73,7 +74,7 @@ public:
    * (We are avoiding a constructor to ensure gcc allows us to put
    * this class in packed structures.)
    */
-  void init(T* initialPtr = 0, uint16_t initialExtra = 0) {
+  void init(T* initialPtr = nullptr, uint16_t initialExtra = 0) {
     auto intPtr = reinterpret_cast<uintptr_t>(initialPtr);
     CHECK(!(intPtr >> 48));
     data_.init(intPtr);
@@ -149,4 +150,4 @@ std::ostream& operator<<(std::ostream& os, const PackedSyncPtr<T>& ptr) {
   os << "PackedSyncPtr(" << ptr.get() << ", " << ptr.extra() << ")";
   return os;
 }
-}
+} // namespace folly