Summary:
- Only declare the Range constructor as a constexpr if strlen() is also
a constexpr. Otherwise, we'll get compilation errors.
Test Plan:
- fbconfig -r folly && fbmake runtests
- ./configure && make check on Ubuntu/FC/Mac
Reviewed By: soren@fb.com
FB internal diff:
D1003124
Range(Iter start, size_t size)
: b_(start), e_(start + size) { }
+#if FOLLY_HAVE_CONSTEXPR_STRLEN
// Works only for Range<const char*>
/* implicit */ constexpr Range(Iter str)
: b_(str), e_(str + strlen(str)) {}
+#else
+ // Works only for Range<const char*>
+ /* implicit */ Range(Iter str)
+ : b_(str), e_(str + strlen(str)) {}
+#endif
// Works only for Range<const char*>
/* implicit */ Range(const std::string& str)
: b_(str.data()), e_(b_ + str.size()) {}
[AC_DEFINE([HAVE_STD__THIS_THREAD__SLEEP_FOR], [1],
[Define to 1 if std::this_thread::sleep_for() is defined.])])
+AC_COMPILE_IFELSE(
+ [AC_LANG_SOURCE[
+ #include <cstring>
+ static constexpr int val = strlen("foo");]],
+ [AC_DEFINE([HAVE_CONSTEXPR_STRLEN], [1],
+ [Define to 1 if strlen(3) is constexpr.])])
+
AC_COMPILE_IFELSE(
[AC_LANG_SOURCE[
#include <type_traits>
EXPECT_THROW(a.subpiece(6), std::out_of_range);
}
+#if FOLLY_HAVE_CONSTEXPR_STRLEN
constexpr char helloArray[] = "hello";
TEST(StringPiece, Constexpr) {
constexpr StringPiece hello2(helloArray);
EXPECT_EQ("hello", hello2);
}
+#endif
TEST(qfind, UInt32_Ranges) {
vector<uint32_t> a({1, 2, 3, 260, 5});