Commit | Line | Data |
---|---|---|
7077c39b VM |
1 | From d0f929a5db87cb34d03afb0d8e8bfc95b8f786e3 Mon Sep 17 00:00:00 2001 |
2 | From: Victor Costan <costan@gmail.com> | |
3 | Date: Mon, 11 Sep 2017 13:18:27 -0700 | |
4 | Subject: [PATCH] More conservative check for <string_view> availability. (#4) | |
5 | ||
6 | has_include(<string_view>) does not imply that the header can be | |
7 | included and will work. The assumption fails on MSVC and libc++ [1, 2]. | |
8 | Conversely, checking that __cplusplus > 201402L is not sufficient on its | |
9 | own either, as the toolchain on Mac OS 10.12 passes that check but does | |
10 | not contain a <string_view> header. | |
11 | ||
12 | [1] https://crbug.com/759349 | |
13 | [2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79433 | |
14 | --- | |
15 | include/crc32c/crc32c.h | 10 +++------- | |
16 | src/crc32c_unittest.cc | 6 ++---- | |
17 | 2 files changed, 5 insertions(+), 11 deletions(-) | |
18 | ||
19 | diff --git a/include/crc32c/crc32c.h b/include/crc32c/crc32c.h | |
20 | index 9f1973a..8ecab0d 100644 | |
21 | --- a/include/crc32c/crc32c.h | |
22 | +++ b/include/crc32c/crc32c.h | |
23 | @@ -33,22 +33,18 @@ inline uint32_t Crc32c(const std::string& string) { | |
24 | string.size()); | |
25 | } | |
26 | ||
27 | -#if defined(__has_include) | |
28 | +#if __cplusplus > 201402L | |
29 | #if __has_include(<string_view>) | |
30 | -// Visual Studio provides a <string_view> header even in C++11 mode. When | |
31 | -// included, the header issues an #error. (C1189) | |
32 | -#if !defined(_MSC_VER) || __cplusplus >= 201703L | |
33 | #include <string_view> | |
34 | ||
35 | -// Comptues the CRC32C of the bytes in the string_view. | |
36 | +// Computes the CRC32C of the bytes in the string_view. | |
37 | inline uint32_t Crc32c(const std::string_view& string_view) { | |
38 | return Crc32c(reinterpret_cast<const uint8_t*>(string_view.data()), | |
39 | string_view.size()); | |
40 | } | |
41 | ||
42 | -#endif // !defined(_MSC_VER) || __cplusplus >= 201703L | |
43 | #endif // __has_include(<string_view>) | |
44 | -#endif // defined(__has_include) | |
45 | +#endif // __cplusplus > 201402L | |
46 | ||
47 | } // namespace crc32c | |
48 | ||
49 | diff --git a/src/crc32c_unittest.cc b/src/crc32c_unittest.cc | |
50 | index 7a9c765..69babb3 100644 | |
51 | --- a/src/crc32c_unittest.cc | |
52 | +++ b/src/crc32c_unittest.cc | |
53 | @@ -95,9 +95,8 @@ TEST(CRC32CTest, Crc32cStdString) { | |
54 | EXPECT_EQ(static_cast<uint32_t>(0x113fdb5c), crc32c::Crc32c(buf)); | |
55 | } | |
56 | ||
57 | -#if defined(__has_include) | |
58 | +#if __cplusplus > 201402L | |
59 | #if __has_include(<string_view>) | |
60 | -#if !defined(_MSC_VER) || __cplusplus >= 201703L | |
61 | ||
62 | TEST(CRC32CTest, Crc32cStdStringView) { | |
63 | uint8_t buf[32]; | |
64 | @@ -118,9 +117,8 @@ TEST(CRC32CTest, Crc32cStdStringView) { | |
65 | EXPECT_EQ(static_cast<uint32_t>(0x113fdb5c), crc32c::Crc32c(view)); | |
66 | } | |
67 | ||
68 | -#endif // !defined(_MSC_VER) || __cplusplus >= 201703L | |
69 | #endif // __has_include(<string_view>) | |
70 | -#endif // defined(__has_include) | |
71 | +#endif // __cplusplus > 201402L | |
72 | ||
73 | #define TESTED_EXTEND Extend | |
74 | #include "./crc32c_extend_unittests.h" |