Commit 63fcb6c7 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Hack around MSVC not supporting constexpr storage

Summary:
[Folly] Hack around MSVC not supporting `constexpr` storage.

GCC and Clang do, but MSVC does not, support:

```lang=c++
extern int const num;
constexpr int const num = 3;
```

Work around it.

Reviewed By: elsteveogrande

Differential Revision: D6903413

fbshipit-source-id: 3a0957816d8d82718fb6187dc1803df1605f80aa
parent 36f840db
......@@ -75,17 +75,17 @@ struct format_table_sign_make_item {
};
// the tables
constexpr auto formatAlignTable =
FOLLY_STORAGE_CONSTEXPR auto formatAlignTable =
make_array_with<256>(format_table_align_make_item{});
constexpr auto formatSignTable =
FOLLY_STORAGE_CONSTEXPR auto formatSignTable =
make_array_with<256>(format_table_sign_make_item{});
constexpr decltype(formatHexLower) formatHexLower =
FOLLY_STORAGE_CONSTEXPR decltype(formatHexLower) formatHexLower =
make_array_with<256>(format_table_conv_make_item<16, 2, false>{});
constexpr decltype(formatHexUpper) formatHexUpper =
FOLLY_STORAGE_CONSTEXPR decltype(formatHexUpper) formatHexUpper =
make_array_with<256>(format_table_conv_make_item<16, 2, true>{});
constexpr decltype(formatOctal) formatOctal =
FOLLY_STORAGE_CONSTEXPR decltype(formatOctal) formatOctal =
make_array_with<512>(format_table_conv_make_item<8, 3>{});
constexpr decltype(formatBinary) formatBinary =
FOLLY_STORAGE_CONSTEXPR decltype(formatBinary) formatBinary =
make_array_with<256>(format_table_conv_make_item<2, 8>{});
} // namespace detail
......
......@@ -131,11 +131,12 @@ struct group_varint_table_sse_mask_make_item
};
#if FOLLY_SSE >= 3
alignas(16) constexpr decltype(groupVarintSSEMasks) groupVarintSSEMasks =
make_array_with<256>(group_varint_table_sse_mask_make_item{});
alignas(16) FOLLY_STORAGE_CONSTEXPR
decltype(groupVarintSSEMasks) groupVarintSSEMasks =
make_array_with<256>(group_varint_table_sse_mask_make_item{});
#endif
constexpr decltype(groupVarintLengths) groupVarintLengths =
FOLLY_STORAGE_CONSTEXPR decltype(groupVarintLengths) groupVarintLengths =
make_array_with<256>(group_varint_table_length_make_item{});
} // namespace detail
......
......@@ -366,6 +366,29 @@ constexpr auto kMscVer = 0;
#define FOLLY_CPP14_CONSTEXPR inline
#endif
// MSVC does not permit:
//
// extern int const num;
// constexpr int const num = 3;
//
// Instead:
//
// extern int const num;
// FOLLY_STORAGE_CONSTEXPR int const num = 3;
//
// True for MSVC 2015 and MSVC 2017.
#if _MSC_VER
#define FOLLY_STORAGE_CONSTEXPR
#define FOLLY_STORAGE_CPP14_CONSTEXPR
#else
#define FOLLY_STORAGE_CONSTEXPR constexpr
#if FOLLY_USE_CPP14_CONSTEXPR
#define FOLLY_STORAGE_CPP14_CONSTEXPR constexpr
#else
#define FOLLY_STORAGE_CPP14_CONSTEXPR
#endif
#endif
#if __cpp_coroutines >= 201703L && FOLLY_HAS_INCLUDE(<experimental/coroutine>)
#define FOLLY_HAS_COROUTINES 1
#elif _MSC_VER && _RESUMABLE_FUNCTIONS_SUPPORTED
......
......@@ -25,6 +25,7 @@
#include <glog/logging.h>
#include <folly/Portability.h>
#include <folly/ScopeGuard.h>
#include <folly/container/Array.h>
......@@ -111,13 +112,13 @@ struct string_table_uri_escape_make_item {
}
};
constexpr decltype(cEscapeTable) cEscapeTable =
FOLLY_STORAGE_CONSTEXPR decltype(cEscapeTable) cEscapeTable =
make_array_with<256>(string_table_c_escape_make_item{});
constexpr decltype(cUnescapeTable) cUnescapeTable =
FOLLY_STORAGE_CONSTEXPR decltype(cUnescapeTable) cUnescapeTable =
make_array_with<256>(string_table_c_unescape_make_item{});
constexpr decltype(hexTable) hexTable =
FOLLY_STORAGE_CONSTEXPR decltype(hexTable) hexTable =
make_array_with<256>(string_table_hex_make_item{});
constexpr decltype(uriEscapeTable) uriEscapeTable =
FOLLY_STORAGE_CONSTEXPR decltype(uriEscapeTable) uriEscapeTable =
make_array_with<256>(string_table_uri_escape_make_item{});
} // namespace detail
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment