Explicit vtordisp for MSVC
authorOrvid King <blah38621@gmail.com>
Thu, 25 Feb 2016 00:28:14 +0000 (16:28 -0800)
committerfacebook-github-bot-4 <folly-bot@fb.com>
Thu, 25 Feb 2016 01:20:25 +0000 (17:20 -0800)
Summary:Because sometimes things are just different.

MSVC warns about the `dynamic_cast` done against this class because the class's declaration doesn't show that it would need a vtordisp. While I don't believe the `dynamic_cast` in question is actually called in either the constructor or destructor paths for the class, better to be safe and force the disp to be created.

Reviewed By: yfeldblum

Differential Revision: D2887490

Pulled By: Orvid

fb-gh-sync-id: 821a6fc820087ac7120fffd9f8b95a26c2b4e71b
shipit-source-id: 821a6fc820087ac7120fffd9f8b95a26c2b4e71b

folly/io/async/AsyncSocket.h

index de1ca7893ce9389294b9fcb6d9bfe5942b9af3f6..28c553a5f82683a39476e15a2833fb173dc02321 100644 (file)
@@ -61,6 +61,13 @@ namespace folly {
  * responding and no further progress can be made sending the data.
  */
 
+#ifdef _MSC_VER
+// We do a dynamic_cast on this, in
+// AsyncTransportWrapper::getUnderlyingTransport so be safe and
+// force displacements for it. See:
+// https://msdn.microsoft.com/en-us/library/7sf3txa8.aspx
+#pragma vtordisp(push, 2)
+#endif
 class AsyncSocket : virtual public AsyncTransportWrapper {
  public:
   typedef std::unique_ptr<AsyncSocket, Destructor> UniquePtr;
@@ -818,6 +825,8 @@ class AsyncSocket : virtual public AsyncTransportWrapper {
 
   BufferCallback* bufferCallback_{nullptr};
 };
-
+#ifdef _MSC_VER
+#pragma vtordisp(pop)
+#endif
 
 } // folly