Commit 4464999f authored by Adam Simpkins's avatar Adam Simpkins Committed by Facebook Github Bot

minor tweaks to constexpr_strlen() definition

Summary:
- Use `FOLLLY_HAS_FEATURE(cxx_constexpr_string_builtins)` to check for the
  availability of `__builtin_strlen()` on clang, as recommended by the clang
  documentation (https://clang.llvm.org/docs/LanguageExtensions.html)
- Only use `std::strlen()` on gcc, rather than having checks to exclude all
  other compilers.  `strlen()` happens to be constexpr on gcc, but this is not
  required by the standard and cannot be assumed to be true in general.

Reviewed By: yfeldblum

Differential Revision: D6881815

fbshipit-source-id: 88c614419ae390464893087513dc764b0bfddfb8
parent 30ad7fa1
......@@ -16,6 +16,8 @@
#pragma once
#include <folly/CPortability.h>
#include <cstdint>
#include <cstring>
#include <type_traits>
......@@ -40,12 +42,14 @@ constexpr size_t constexpr_strlen(const Char* s) {
template <>
constexpr size_t constexpr_strlen(const char* s) {
#if defined(__clang__)
#if FOLLY_HAS_FEATURE(cxx_constexpr_string_builtins)
// clang provides a constexpr builtin
return __builtin_strlen(s);
#elif defined(_MSC_VER) || defined(__CUDACC__)
return detail::constexpr_strlen_internal(s, 0);
#else
#elif defined(__GNUC__) && !defined(__clang__)
// strlen() happens to already be constexpr under gcc
return std::strlen(s);
#else
return detail::constexpr_strlen_internal(s, 0);
#endif
}
} // namespace folly
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