Update documentation for Synchronized
[folly.git] / folly / CppAttributes.h
index 4a001946a3cc27220880654a6940abc98bff253a..6bd6cfe33817b040c9dff8645c5f42f79bf75fc5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2015 Facebook, Inc.
+ * Copyright 2016 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,8 +20,7 @@
  * @author Dominik Gabi
  */
 
-#ifndef FOLLY_BASE_ATTRIBUTES_H_
-#define FOLLY_BASE_ATTRIBUTES_H_
+#pragma once
 
 #ifndef __has_cpp_attribute
 #define FOLLY_HAS_CPP_ATTRIBUTE(x) 0
 #define FOLLY_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
 #endif
 
+#ifndef __has_extension
+#define FOLLY_HAS_EXTENSION(x) 0
+#else
+#define FOLLY_HAS_EXTENSION(x) __has_extension(x)
+#endif
+
 /**
  * Fallthrough to indicate that `break` was left out on purpose in a switch
  * statement, e.g.
 #define FOLLY_FALLTHROUGH
 #endif
 
-#endif /* FOLLY_BASE_ATTRIBUTES_H_ */
+/**
+ * Nullable indicates that a return value or a parameter may be a `nullptr`,
+ * e.g.
+ *
+ * int* FOLLY_NULLABLE foo(int* a, int* FOLLY_NULLABLE b) {
+ *   if (*a > 0) {  // safe dereference
+ *     return nullptr;
+ *   }
+ *   if (*b < 0) {  // unsafe dereference
+ *     return *a;
+ *   }
+ *   if (b != nullptr && *b == 1) {  // safe checked dereference
+ *     return new int(1);
+ *   }
+ *   return nullptr;
+ * }
+ */
+#if FOLLY_HAS_EXTENSION(nullability)
+#define FOLLY_NULLABLE _Nullable
+#else
+#define FOLLY_NULLABLE
+#endif