Initialize variable before using in own initialization
authorMichael Connor <mconnor@fb.com>
Wed, 27 Mar 2013 17:16:59 +0000 (10:16 -0700)
committerJordan DeLong <jdelong@fb.com>
Sun, 21 Apr 2013 20:21:06 +0000 (13:21 -0700)
Summary:
Clang throws error because the callback refers to itself inside its lambda
function definition.  I prevent this by declaring the variable first then the
compiler does not complain when it is used within its lambda definition.

folly/test/TimeoutQueueTest.cpp:99:37: error: variable 'cb' is uninitialized
when used within its own initialization [-Werror,-Wuninitialized]

Test Plan:
fbconfig --clang --platform=gcc-4.7.1-glibc-2.14.1 --with-project-version
boost:1.51.0 folly/test/
fbmake opt
fbmake runtests_opt

Reviewed By: ldbrandy@fb.com

FB internal diff: D753061

folly/test/TimeoutQueueTest.cpp

index a384c44b47516590eeb0b2157e3717e125206dae..1ddff6a9383ba3cd93d041247726e9f2f3af48a3 100644 (file)
@@ -93,8 +93,8 @@ TEST(TimeoutQueue, RunOnceRepeating) {
 TEST(TimeoutQueue, RunOnceReschedule) {
   int count = 0;
   TimeoutQueue q;
-  TimeoutQueue::Callback cb =
-    [&count, &q, &cb](TimeoutQueue::Id id, int64_t now) {
+  TimeoutQueue::Callback cb;
+  cb = [&count, &q, &cb](TimeoutQueue::Id id, int64_t now) {
       if (++count < 100) {
         EXPECT_LT(id, q.add(now, 0, cb));
       }