volatile override
authorNicholas Ormrod <njormrod@fb.com>
Fri, 31 Oct 2014 18:07:44 +0000 (11:07 -0700)
committerPavlo Kushnir <pavlo@fb.com>
Sat, 8 Nov 2014 02:20:55 +0000 (18:20 -0800)
Summary:
Some uses of volatile are legit. Add a hidden override.

Test Plan: run unit tests

Run flint against folly/Malloc.cpp, see no more volatile warning.

Reviewed By: andrei.alexandrescu@fb.com

Subscribers: sdwilsh, louisk, njormrod, folly-diffs@

FB internal diff: D1644493

Tasks: 5486739

Signature: t1:1644493:1414715317:491d0f631d8152a5b7ec66237e00c404530ab590

folly/Malloc.cpp
folly/Traits.h
folly/experimental/symbolizer/test/SignalHandlerTest.h
folly/test/HasMemberFnTraitsTest.cpp

index d1a242c228dfbb0b42e9464d45f04fec9e9e3a5a..3e510d9ed367ac3c9b23b02f100384754177896e 100644 (file)
@@ -37,7 +37,7 @@ bool usingJEMallocSlow() {
 
   // "volatile" because gcc optimizes out the reads from *counter, because
   // it "knows" malloc doesn't modify global state...
-  volatile uint64_t* counter;
+  /* nolint */ volatile uint64_t* counter;
   size_t counterLen = sizeof(uint64_t*);
 
   if (mallctl("thread.allocatedp", static_cast<void*>(&counter), &counterLen,
index 2b94df1360effe21828adedb51b864e7d2282116..132e0f2b4a0b9aa73365886f1b5098591bc169f8 100644 (file)
@@ -518,7 +518,9 @@ FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1(boost::shared_ptr);
   template <typename, typename> class classname; \
   FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL(classname, func_name, ); \
   FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL(classname, func_name, const); \
-  FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL(classname, func_name, volatile); \
-  FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL(classname, func_name, volatile const)
+  FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL( \
+      classname, func_name, /* nolint */ volatile); \
+  FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL( \
+      classname, func_name, /* nolint */ volatile const)
 
 #endif //FOLLY_BASE_TRAITS_H_
index aa646627aba64571ee261e87d2e4f2b9b60ca5c3..79bf6b2f6cd7e9edc4b26dda9e83fbef466538bc 100644 (file)
@@ -20,7 +20,7 @@
 namespace folly { namespace symbolizer { namespace test {
 
 inline void failHard() {
-  *(volatile char*)42;  // SIGSEGV
+  *(/* nolint */ volatile char*)42;  // SIGSEGV
 }
 
 }}}  // namespaces
index 7944b4d473916387cfe45d12e2904ef259b5212c..2a9a308d562c0eb8c976e9a55e3d1a264d536a4b 100644 (file)
@@ -45,8 +45,8 @@ struct Bar {
 struct Gaz {
   void test();
   void test() const;
-  void test() volatile;
-  void test() const volatile;
+  void test() /* nolint */ volatile;
+  void test() const /* nolint */ volatile;
 };
 
 struct NoCV {
@@ -58,11 +58,11 @@ struct Const {
 };
 
 struct Volatile {
-  void test() volatile;
+  void test() /* nolint */ volatile;
 };
 
 struct CV {
-  void test() const volatile;
+  void test() const /* nolint */ volatile;
 };
 
 bool log_value(const char* what, bool result) {
@@ -89,33 +89,47 @@ TEST(HasMemberFnTraits, DirectMembers) {
 
   EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void()>::value)));
   EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void() const>::value)));
-  EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void() volatile>::value)));
-  EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void() const volatile>::value)));
-  EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void() volatile const>::value)));
+  EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void() /* nolint */ volatile>::value)));
+  EXPECT_TRUE(LOG_VALUE((
+          has_test<Gaz, void() const /* nolint */ volatile>::value)));
+  EXPECT_TRUE(LOG_VALUE((
+          has_test<Gaz, void() /* nolint */ volatile const>::value)));
 
   EXPECT_TRUE(LOG_VALUE((has_test<NoCV, void()>::value)));
   EXPECT_FALSE(LOG_VALUE((has_test<NoCV, void() const>::value)));
-  EXPECT_FALSE(LOG_VALUE((has_test<NoCV, void() volatile>::value)));
-  EXPECT_FALSE(LOG_VALUE((has_test<NoCV, void() const volatile>::value)));
-  EXPECT_FALSE(LOG_VALUE((has_test<NoCV, void() volatile const>::value)));
+  EXPECT_FALSE(LOG_VALUE((
+          has_test<NoCV, void() /* nolint */ volatile>::value)));
+  EXPECT_FALSE(LOG_VALUE((
+          has_test<NoCV, void() const /* nolint */ volatile>::value)));
+  EXPECT_FALSE(LOG_VALUE((
+          has_test<NoCV, void() /* nolint */ volatile const>::value)));
 
   EXPECT_FALSE(LOG_VALUE((has_test<Const, void()>::value)));
   EXPECT_TRUE(LOG_VALUE((has_test<Const, void() const>::value)));
-  EXPECT_FALSE(LOG_VALUE((has_test<Const, void() volatile>::value)));
-  EXPECT_FALSE(LOG_VALUE((has_test<Const, void() const volatile>::value)));
-  EXPECT_FALSE(LOG_VALUE((has_test<Const, void() volatile const>::value)));
+  EXPECT_FALSE(LOG_VALUE((
+          has_test<Const, void() /* nolint */ volatile>::value)));
+  EXPECT_FALSE(LOG_VALUE((
+          has_test<Const, void() const /* nolint */ volatile>::value)));
+  EXPECT_FALSE(LOG_VALUE((
+          has_test<Const, void() /* nolint */ volatile const>::value)));
 
   EXPECT_FALSE(LOG_VALUE((has_test<Volatile, void()>::value)));
   EXPECT_FALSE(LOG_VALUE((has_test<Volatile, void() const>::value)));
-  EXPECT_TRUE(LOG_VALUE((has_test<Volatile, void() volatile>::value)));
-  EXPECT_FALSE(LOG_VALUE((has_test<Volatile, void() const volatile>::value)));
-  EXPECT_FALSE(LOG_VALUE((has_test<Volatile, void() volatile const>::value)));
+  EXPECT_TRUE(LOG_VALUE((
+          has_test<Volatile, void() /* nolint */ volatile>::value)));
+  EXPECT_FALSE(LOG_VALUE((
+          has_test<Volatile, void() const /* nolint */ volatile>::value)));
+  EXPECT_FALSE(LOG_VALUE((
+          has_test<Volatile, void() /* nolint */ volatile const>::value)));
 
   EXPECT_FALSE(LOG_VALUE((has_test<CV, void()>::value)));
   EXPECT_FALSE(LOG_VALUE((has_test<CV, void() const>::value)));
-  EXPECT_FALSE(LOG_VALUE((has_test<CV, void() volatile>::value)));
-  EXPECT_TRUE(LOG_VALUE((has_test<CV, void() const volatile>::value)));
-  EXPECT_TRUE(LOG_VALUE((has_test<CV, void() volatile const>::value)));
+  EXPECT_FALSE(LOG_VALUE((
+          has_test<CV, void() /* nolint */ volatile>::value)));
+  EXPECT_TRUE(LOG_VALUE((
+          has_test<CV, void() const /* nolint */ volatile>::value)));
+  EXPECT_TRUE(LOG_VALUE((
+          has_test<CV, void() /* nolint */ volatile const>::value)));
 }
 
 int main(int argc, char *argv[]) {