Skip to content

Commit 493d5cb

Browse files
davidbenBoringssl LUCI CQ
authored and
Boringssl LUCI CQ
committed
Try to require C++14.
Now that we've dropped MSVC 2015, I believe we can rely on C++14 (which is now seven years old). This switches the build to require C++14. I've gone ahead and switched code in both public headers and within the library, but if the public headers are a problem, we can revert those separately. C++14 doesn't get us quite as much as C++17, but see if we can get to C++14 first. Still, std::enable_if_t and the less restricted constexpr are nice wins. Update-Note: C++14 is now required to build BoringSSL. If the build breaks, make sure your compiler is C++14-capable and is not passing -std=c++11. If this is causing problems for your project, let us know. Change-Id: If03a88e3f8a11980180781f95b806e7f3c3cb6c3 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/52246 Reviewed-by: Adam Langley <[email protected]> Commit-Queue: David Benjamin <[email protected]>
1 parent edbdc24 commit 493d5cb

File tree

9 files changed

+45
-52
lines changed

9 files changed

+45
-52
lines changed

BUILDING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ most recent stable version of each tool.
3030
by CMake, it may be configured explicitly by setting
3131
`CMAKE_ASM_NASM_COMPILER`.
3232

33-
* C and C++ compilers with C++11 support are required. On Windows, MSVC from
33+
* C and C++ compilers with C++14 support are required. On Windows, MSVC from
3434
Visual Studio 2017 or later with Platform SDK 8.1 or later are supported,
3535
but newer versions are recommended. Recent versions of GCC (6.1+) and Clang
3636
should work on non-Windows platforms, and maybe on Windows too.

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CLANG)
163163
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${C_CXX_FLAGS} -Wmissing-declarations")
164164

165165
if(NOT MSVC)
166-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
166+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
167167
if(APPLE)
168168
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
169169
endif()

crypto/test/abi_test.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,9 @@ inline crypto_word_t CheckImpl(Result *out, bool unwind, R (*func)(Args...),
380380
// CheckImpl implementation. It must be specialized for void returns because we
381381
// call |func| directly.
382382
template <typename R, typename... Args>
383-
inline typename std::enable_if<!std::is_void<R>::value, crypto_word_t>::type
384-
CheckImpl(Result *out, bool /* unwind */, R (*func)(Args...),
385-
typename DeductionGuard<Args>::Type... args) {
383+
inline std::enable_if_t<!std::is_void<R>::value, crypto_word_t> CheckImpl(
384+
Result *out, bool /* unwind */, R (*func)(Args...),
385+
typename DeductionGuard<Args>::Type... args) {
386386
*out = Result();
387387
return func(args...);
388388
}

include/openssl/span.h

+7-10
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,11 @@ class Span : private internal::SpanBase<const T> {
9999
// Heuristically test whether C is a container type that can be converted into
100100
// a Span by checking for data() and size() member functions.
101101
//
102-
// TODO(davidben): Require C++14 support and switch to std::enable_if_t.
103-
// Perhaps even C++17 now?
102+
// TODO(davidben): Require C++17 support for std::is_convertible_v, etc.
104103
template <typename C>
105-
using EnableIfContainer = typename std::enable_if<
104+
using EnableIfContainer = std::enable_if_t<
106105
std::is_convertible<decltype(std::declval<C>().data()), T *>::value &&
107-
std::is_integral<decltype(std::declval<C>().size())>::value>::type;
106+
std::is_integral<decltype(std::declval<C>().size())>::value>;
108107

109108
public:
110109
constexpr Span() : Span(nullptr, 0) {}
@@ -113,14 +112,12 @@ class Span : private internal::SpanBase<const T> {
113112
template <size_t N>
114113
constexpr Span(T (&array)[N]) : Span(array, N) {}
115114

116-
template <
117-
typename C, typename = EnableIfContainer<C>,
118-
typename = typename std::enable_if<std::is_const<T>::value, C>::type>
115+
template <typename C, typename = EnableIfContainer<C>,
116+
typename = std::enable_if_t<std::is_const<T>::value, C>>
119117
Span(const C &container) : data_(container.data()), size_(container.size()) {}
120118

121-
template <
122-
typename C, typename = EnableIfContainer<C>,
123-
typename = typename std::enable_if<!std::is_const<T>::value, C>::type>
119+
template <typename C, typename = EnableIfContainer<C>,
120+
typename = std::enable_if_t<!std::is_const<T>::value, C>>
124121
explicit Span(C &container)
125122
: data_(container.data()), size_(container.size()) {}
126123

include/openssl/stack.h

+7-10
Original file line numberDiff line numberDiff line change
@@ -443,16 +443,14 @@ namespace internal {
443443

444444
// Stacks defined with |DEFINE_CONST_STACK_OF| are freed with |sk_free|.
445445
template <typename Stack>
446-
struct DeleterImpl<
447-
Stack, typename std::enable_if<StackTraits<Stack>::kIsConst>::type> {
446+
struct DeleterImpl<Stack, std::enable_if_t<StackTraits<Stack>::kIsConst>> {
448447
static void Free(Stack *sk) { sk_free(reinterpret_cast<_STACK *>(sk)); }
449448
};
450449

451450
// Stacks defined with |DEFINE_STACK_OF| are freed with |sk_pop_free| and the
452451
// corresponding type's deleter.
453452
template <typename Stack>
454-
struct DeleterImpl<
455-
Stack, typename std::enable_if<!StackTraits<Stack>::kIsConst>::type> {
453+
struct DeleterImpl<Stack, std::enable_if_t<!StackTraits<Stack>::kIsConst>> {
456454
static void Free(Stack *sk) {
457455
// sk_FOO_pop_free is defined by macros and bound by name, so we cannot
458456
// access it from C++ here.
@@ -502,18 +500,17 @@ class StackIteratorImpl {
502500
};
503501

504502
template <typename Stack>
505-
using StackIterator = typename std::enable_if<StackTraits<Stack>::kIsStack,
506-
StackIteratorImpl<Stack>>::type;
503+
using StackIterator =
504+
std::enable_if_t<StackTraits<Stack>::kIsStack, StackIteratorImpl<Stack>>;
507505

508506
} // namespace internal
509507

510508
// PushToStack pushes |elem| to |sk|. It returns true on success and false on
511509
// allocation failure.
512510
template <typename Stack>
513-
inline
514-
typename std::enable_if<!internal::StackTraits<Stack>::kIsConst, bool>::type
515-
PushToStack(Stack *sk,
516-
UniquePtr<typename internal::StackTraits<Stack>::Type> elem) {
511+
inline std::enable_if_t<!internal::StackTraits<Stack>::kIsConst, bool>
512+
PushToStack(Stack *sk,
513+
UniquePtr<typename internal::StackTraits<Stack>::Type> elem) {
517514
if (!sk_push(reinterpret_cast<_STACK *>(sk), elem.get())) {
518515
return false;
519516
}

ssl/internal.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ void Delete(T *t) {
216216
// may be C structs which require a |BORINGSSL_MAKE_DELETER| registration.
217217
namespace internal {
218218
template <typename T>
219-
struct DeleterImpl<T, typename std::enable_if<T::kAllowUniquePtr>::type> {
219+
struct DeleterImpl<T, std::enable_if_t<T::kAllowUniquePtr>> {
220220
static void Free(T *t) { Delete(t); }
221221
};
222222
} // namespace internal

ssl/ssl_cipher.cc

+22-23
Original file line numberDiff line numberDiff line change
@@ -1327,34 +1327,33 @@ BSSL_NAMESPACE_END
13271327

13281328
using namespace bssl;
13291329

1330-
static constexpr int ssl_cipher_id_cmp_inner(const SSL_CIPHER *a,
1331-
const SSL_CIPHER *b) {
1332-
// C++11's constexpr functions must have a body consisting of just a
1333-
// return-statement.
1334-
return (a->id > b->id) ? 1 : ((a->id < b->id) ? -1 : 0);
1335-
}
1336-
1337-
static int ssl_cipher_id_cmp(const void *in_a, const void *in_b) {
1338-
return ssl_cipher_id_cmp_inner(reinterpret_cast<const SSL_CIPHER *>(in_a),
1339-
reinterpret_cast<const SSL_CIPHER *>(in_b));
1330+
static constexpr int ssl_cipher_id_cmp(const SSL_CIPHER *a,
1331+
const SSL_CIPHER *b) {
1332+
if (a->id > b->id) {
1333+
return 1;
1334+
}
1335+
if (a->id < b->id) {
1336+
return -1;
1337+
}
1338+
return 0;
13401339
}
13411340

1342-
template <typename T, size_t N>
1343-
static constexpr size_t countof(T const (&)[N]) {
1344-
return N;
1341+
static int ssl_cipher_id_cmp_void(const void *in_a, const void *in_b) {
1342+
return ssl_cipher_id_cmp(reinterpret_cast<const SSL_CIPHER *>(in_a),
1343+
reinterpret_cast<const SSL_CIPHER *>(in_b));
13451344
}
13461345

1347-
template <typename T, size_t I>
1348-
static constexpr int check_order(const T (&arr)[I], size_t N) {
1349-
// C++11's constexpr functions must have a body consisting of just a
1350-
// return-statement.
1351-
return N > 1 ? ((ssl_cipher_id_cmp_inner(&arr[N - 2], &arr[N - 1]) < 0)
1352-
? check_order(arr, N - 1)
1353-
: 0)
1354-
: 1;
1346+
template <size_t N>
1347+
static constexpr bool ssl_ciphers_sorted(const SSL_CIPHER (&ciphers)[N]) {
1348+
for (size_t i = 1; i < N; i++) {
1349+
if (ssl_cipher_id_cmp(&ciphers[i - 1], &ciphers[i]) >= 0) {
1350+
return false;
1351+
}
1352+
}
1353+
return true;
13551354
}
13561355

1357-
static_assert(check_order(kCiphers, countof(kCiphers)) == 1,
1356+
static_assert(ssl_ciphers_sorted(kCiphers),
13581357
"Ciphers are not sorted, bsearch won't work");
13591358

13601359
const SSL_CIPHER *SSL_get_cipher_by_value(uint16_t value) {
@@ -1363,7 +1362,7 @@ const SSL_CIPHER *SSL_get_cipher_by_value(uint16_t value) {
13631362
c.id = 0x03000000L | value;
13641363
return reinterpret_cast<const SSL_CIPHER *>(bsearch(
13651364
&c, kCiphers, OPENSSL_ARRAY_SIZE(kCiphers), sizeof(SSL_CIPHER),
1366-
ssl_cipher_id_cmp));
1365+
ssl_cipher_id_cmp_void));
13671366
}
13681367

13691368
uint32_t SSL_CIPHER_get_id(const SSL_CIPHER *cipher) { return cipher->id; }

util/BUILD.toplevel

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ boringssl_copts_c11 = boringssl_copts + select({
137137
"//conditions:default": [],
138138
})
139139

140-
# For C++ targets only (not C), compile with C++11 support.
140+
# For C++ targets only (not C), compile with C++14 support.
141141
posix_copts_cxx = [
142-
"-std=c++11",
142+
"-std=c++14",
143143
"-Wmissing-declarations",
144144
]
145145

util/generate_build_files.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ def __init__(self):
437437
endif()
438438
439439
if(CMAKE_COMPILER_IS_GNUCXX OR CLANG)
440-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fvisibility=hidden -fno-common -fno-exceptions -fno-rtti")
440+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -fvisibility=hidden -fno-common -fno-exceptions -fno-rtti")
441441
if(APPLE)
442442
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
443443
endif()

0 commit comments

Comments
 (0)