Use decltype to get the type of a non-static local
authorChristopher Dykes <cdykes@fb.com>
Fri, 22 Jul 2016 17:13:42 +0000 (10:13 -0700)
committerFacebook Github Bot 1 <facebook-github-bot-1-bot@fb.com>
Fri, 22 Jul 2016 17:23:50 +0000 (10:23 -0700)
Summary: As the `sizeof()` is being evaluated in a static context, MSVC doesn't let you reference non-static locals. Solve the issue by getting the type of the local via `decltype` instead.

Reviewed By: yfeldblum

Differential Revision: D3600845

fbshipit-source-id: 825d93ced8f09d9f4bf0dcf02142f47a0ec32605

folly/io/async/test/AsyncSSLSocketTest.h

index 42bb03ac135a7f7dfe71fda0be60a7884e02f6c0..384198d1a48cbae5ea050d768eb8cbd6b72c9206 100644 (file)
@@ -1085,8 +1085,9 @@ class SSLClient : public AsyncSocket::ConnectCallback,
   // socket, even if the maxReadsPerEvent_ is hit during
   // a event loop iteration.
   static constexpr size_t kMaxReadsPerEvent = 2;
+  // 2 event loop iterations
   static constexpr size_t kMaxReadBufferSz =
-    sizeof(readbuf_) / kMaxReadsPerEvent / 2;  // 2 event loop iterations
+    sizeof(decltype(readbuf_)) / kMaxReadsPerEvent / 2;
 
  public:
   SSLClient(EventBase *eventBase,