Consistency in namespace-closing comments
[folly.git] / folly / experimental / exception_tracer / ExceptionTracerLib.cpp
index d0ac4baa86509e6243ff73f5ffef8221a4cb2036..dcee56921e918d1c17bb173e6db2ab2f7d034be2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 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,6 +20,7 @@
 
 #include <vector>
 
+#include <folly/Indestructible.h>
 #include <folly/Portability.h>
 #include <folly/SharedMutex.h>
 #include <folly/Synchronized.h>
 namespace __cxxabiv1 {
 
 extern "C" {
-FOLLY_NORETURN void __cxa_throw(void* thrownException,
-                                std::type_info* type,
-                                void (*destructor)(void*));
+void __cxa_throw(
+    void* thrownException,
+    std::type_info* type,
+    void (*destructor)(void*)) __attribute__((__noreturn__));
 void* __cxa_begin_catch(void* excObj) throw();
-FOLLY_NORETURN void __cxa_rethrow(void);
-void __cxa_rethrow(void);
+void __cxa_rethrow(void) __attribute__((__noreturn__));
 void __cxa_end_catch(void);
 }
 
@@ -68,13 +69,13 @@ class CallbackHolder {
 namespace folly {
 namespace exception_tracer {
 
-#define DECLARE_CALLBACK(NAME)                         \
-  CallbackHolder<NAME##Type>& get##NAME##Callbacks() { \
-    static CallbackHolder<NAME##Type> Callbacks;       \
-    return Callbacks;                                  \
-  }                                                    \
-  void register##NAME##Callback(NAME##Type callback) { \
-    get##NAME##Callbacks().registerCallback(callback); \
+#define DECLARE_CALLBACK(NAME)                                   \
+  CallbackHolder<NAME##Type>& get##NAME##Callbacks() {           \
+    static Indestructible<CallbackHolder<NAME##Type>> Callbacks; \
+    return *Callbacks;                                           \
+  }                                                              \
+  void register##NAME##Callback(NAME##Type callback) {           \
+    get##NAME##Callbacks().registerCallback(callback);           \
   }
 
 DECLARE_CALLBACK(CxaThrow);
@@ -83,8 +84,17 @@ DECLARE_CALLBACK(CxaRethrow);
 DECLARE_CALLBACK(CxaEndCatch);
 DECLARE_CALLBACK(RethrowException);
 
-} // exception_tracer
-} // folly
+} // namespace exception_tracer
+} // namespace folly
+
+// Clang is smart enough to understand that the symbols we're loading
+// are [[noreturn]], but GCC is not. In order to be able to build with
+// -Wunreachable-code enable for Clang, these __builtin_unreachable()
+// calls need to go away. Everything else is messy though, so just
+// #define it to an empty macro under Clang and be done with it.
+#ifdef __clang__
+# define __builtin_unreachable()
+#endif
 
 namespace __cxxabiv1 {