From: Anton Likhtarov Date: Tue, 3 Nov 2015 18:45:21 +0000 (-0800) Subject: Disallow nullptr literal in StringPiece constructor X-Git-Tag: deprecate-dynamic-initializer~282 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=82ba5835fb134d84cf15f23d2a1eb3ba93858385;p=folly.git Disallow nullptr literal in StringPiece constructor Summary: This disallows implicitly constructing a StringPiece from a literal nullptr at compile time (without this change, nullptr would cause a segfault in strlen()). Reviewed By: meyering, andriigrynenko Differential Revision: D2603597 fb-gh-sync-id: cafbc45945bacc72a7c89310b99aa62d19a3ff9f --- diff --git a/folly/Conv.h b/folly/Conv.h index 4acb9c1e..f50bde71 100644 --- a/folly/Conv.h +++ b/folly/Conv.h @@ -388,6 +388,11 @@ estimateSpaceNeeded(Src value) { return folly::StringPiece(value).size(); } +template<> +inline size_t estimateSpaceNeeded(std::nullptr_t value) { + return 0; +} + template typename std::enable_if< std::is_pointer::value && diff --git a/folly/Range.h b/folly/Range.h index 8e517607..c72288e2 100644 --- a/folly/Range.h +++ b/folly/Range.h @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -200,6 +201,12 @@ public: constexpr Range(Iter start, size_t size) : b_(start), e_(start + size) { } +# if !defined(__clang__) || __clang_major__ > 3 || \ + (__clang_major__ == 3 && __clang_minor__ > 6) + // Clang 3.6 crashes on this line + /* implicit */ Range(std::nullptr_t) = delete; +# endif + template ::type = 0> constexpr /* implicit */ Range(Iter str) : b_(str), e_(str + constexpr_strlen(str)) {}