clang:dev rejects vector<atomic<T>> in EventBaseTest.cpp.
authorYedidya Feldblum <yfeldblum@fb.com>
Fri, 13 Feb 2015 22:35:04 +0000 (14:35 -0800)
committerAlecs King <int@fb.com>
Tue, 3 Mar 2015 03:20:17 +0000 (19:20 -0800)
Summary: [Folly] clang:dev rejects vector<atomic<T>> in EventBaseTest.cpp.

Test Plan: Build and run `folly/io/async/test/EventBaseTest.cpp` using the current `clang`; try building with `clang:dev` and verifying that at least the related failures are gone.

Reviewed By: meyering@fb.com

Subscribers: mathieubaudet, folly-diffs@, yfeldblum, dougw, brettp

FB internal diff: D1848749

Tasks: 6244720

Signature: t1:1848749:1423866420:7b7354d4568b6a6d6a824236ae8d271f6855d90b

folly/io/async/test/EventBaseTest.cpp

index 255054998223b82dfac0b7d5bf309a54bf72ec18..f94ebfc4d584736a663e51bdd8cbc770100a116e 100644 (file)
@@ -16,6 +16,8 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+#include <folly/Memory.h>
+
 #include <folly/io/async/AsyncTimeout.h>
 #include <folly/io/async/EventBase.h>
 #include <folly/io/async/EventHandler.h>
@@ -32,6 +34,7 @@ using std::atomic;
 using std::deque;
 using std::pair;
 using std::vector;
+using std::unique_ptr;
 using std::thread;
 using std::make_pair;
 using std::cerr;
@@ -1179,14 +1182,14 @@ TEST(EventBaseTest, RunInThread) {
 //  whether any of the race conditions happened.
 TEST(EventBaseTest, RunInEventLoopThreadAndWait) {
   const size_t c = 256;
-  vector<atomic<size_t>> atoms(c);
+  vector<unique_ptr<atomic<size_t>>> atoms(c);
   for (size_t i = 0; i < c; ++i) {
     auto& atom = atoms.at(i);
-    atom = 0;
+    atom = make_unique<atomic<size_t>>(0);
   }
   vector<thread> threads(c);
   for (size_t i = 0; i < c; ++i) {
-    auto& atom = atoms.at(i);
+    auto& atom = *atoms.at(i);
     auto& th = threads.at(i);
     th = thread([&atom] {
         EventBase eb;
@@ -1209,7 +1212,7 @@ TEST(EventBaseTest, RunInEventLoopThreadAndWait) {
     th.join();
   }
   size_t sum = 0;
-  for (auto& atom : atoms) sum += atom;
+  for (auto& atom : atoms) sum += *atom;
   EXPECT_EQ(c, sum);
 }