From: Christopher Dykes Date: Thu, 14 Sep 2017 01:59:20 +0000 (-0700) Subject: Workaround a bug in template instation in MSVC 2017.3 with /permissive- X-Git-Tag: v2017.09.18.00~6 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=0caa2c14220d6b681663670470f7e6a0997d6c11;p=folly.git Workaround a bug in template instation in MSVC 2017.3 with /permissive- 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 --- diff --git a/folly/stats/Histogram.cpp b/folly/stats/Histogram.cpp index c138005e..bbf5c36b 100644 --- a/folly/stats/Histogram.cpp +++ b/folly/stats/Histogram.cpp @@ -24,6 +24,7 @@ #include #include +#if !FOLLY_MSVC_USE_WORKAROUND_FOR_C5037 namespace folly { template class Histogram; @@ -53,3 +54,4 @@ detail::HistogramBuckets::Bucket>:: Histogram::CountFromBucket countFromBucket) const; } // namespace folly +#endif diff --git a/folly/stats/Histogram.h b/folly/stats/Histogram.h index 0be9e160..06db3d04 100644 --- a/folly/stats/Histogram.h +++ b/folly/stats/Histogram.h @@ -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 +#endif