From 96e8ac5bc5d633325e85cbc1d87136ba1ce68120 Mon Sep 17 00:00:00 2001 From: Christopher Dykes Date: Thu, 18 Aug 2016 12:50:37 -0700 Subject: [PATCH] Fix folly::Expected under MSVC Summary: There are 3 separate issues that this addresses to get Expected working correctly under MSVC. The first is simply that it doesn't like `StrictConjunction`. Switching that to `std::conjunction`, which is part of C++17 and already implemented in MSVC, solves that issue. The second is that MSVC was complaining that all members must be initialized in a `constexpr` constructor, but only one of the base classes of `ExpectedStorage` was being initialized, and, as there were no default `constexpr` constructors for the other bases, they couldn't be initialized. This was solved by making the base class's default constructors `constexpr`. The last was the most fun, as the simple solutions all resulted in internal compiler errors. MSVC doesn't like SFINAE evaluation in the context of a template type parameter on a static operator defined inline in the class via `friend`. The solution is to simply move the definitions after the class and only include the declarations to be able to mark them as `friend`. Reviewed By: ericniebler Differential Revision: D3731833 fbshipit-source-id: ea9244b247b69046866f27cee9fdbd1b2405cafb --- folly/Expected.h | 195 +++++++++++++++++++++++++++++------------------ 1 file changed, 119 insertions(+), 76 deletions(-) diff --git a/folly/Expected.h b/folly/Expected.h index cde4a04b..0bf217c7 100644 --- a/folly/Expected.h +++ b/folly/Expected.h @@ -92,8 +92,15 @@ using ExpectedErrorType = // Details... namespace expected_detail { +#ifdef _MSC_VER +// MSVC 2015 can't handle the StrictConjunction, so we have +// to use std::conjunction instead. +template