Workaround a bug in template instation in MSVC 2017.3 with /permissive-
authorChristopher Dykes <cdykes@fb.com>
Thu, 14 Sep 2017 01:59:20 +0000 (18:59 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 14 Sep 2017 02:05:22 +0000 (19:05 -0700)
Summary:
As described in the comment in `folly/stats/Histogram.h`, MSVC 2017.3 has issues with `/permissive-`.
The bug has been fixed upstream, it's just waiting for release.

These explicit template instantiations are never forward-declared anywhere, so, as long as `Histogram-defs.h` has been included, it's perfectly safe to just not do them.

https://developercommunity.visualstudio.com/content/problem/81223/incorrect-error-c5037-with-permissive.html

Reviewed By: yfeldblum

Differential Revision: D5828891

fbshipit-source-id: 4db8407c9d35aa5bb3f7b81aa24f611b5787fb6e

folly/stats/Histogram.cpp
folly/stats/Histogram.h

index c138005e24f6d8ab51bc28feeaf539035808489d..bbf5c36ba00586111ba364a5d038c2520a967eae 100644 (file)
@@ -24,6 +24,7 @@
 #include <folly/stats/Histogram.h>
 #include <folly/stats/Histogram-defs.h>
 
+#if !FOLLY_MSVC_USE_WORKAROUND_FOR_C5037
 namespace folly {
 
 template class Histogram<int64_t>;
@@ -53,3 +54,4 @@ detail::HistogramBuckets<int64_t, Histogram<int64_t>::Bucket>::
         Histogram<int64_t>::CountFromBucket countFromBucket) const;
 
 } // namespace folly
+#endif
index 0be9e160aaec3f83fc153d7b9c88301d207a1dfe..06db3d049d92a7af17c80a8985a80ab9ddfec46d 100644 (file)
@@ -479,3 +479,18 @@ class Histogram {
 };
 
 } // namespace folly
+
+// MSVC 2017 Update 3 has an issue with explicitly instantiating templated
+// functions with default arguments inside templated classes when compiled
+// with /permissive- (the default for the CMake build), so we directly include
+// the -defs as if it were -inl, and don't provide the explicit instantiations.
+// https://developercommunity.visualstudio.com/content/problem/81223/incorrect-error-c5037-with-permissive.html
+#if defined(_MSC_VER) && _MSC_FULL_VER >= 191125506 && _MSC_FULL_VER < 191125542
+#define FOLLY_MSVC_USE_WORKAROUND_FOR_C5037 1
+#else
+#define FOLLY_MSVC_USE_WORKAROUND_FOR_C5037 0
+#endif
+
+#if FOLLY_MSVC_USE_WORKAROUND_FOR_C5037
+#include <folly/stats/Histogram-defs.h>
+#endif