Changes imported from Abseil "staging" branch:

- 06abebb2bdb201c572da209fc7f781d6bd774d6b Documentation fixes for `absl::optional`. by Abseil Team <absl-team@google.com>
  - 42adc4c4daade2e070dc337e94d8851a1fd4bead  Rolling back the previous change because `__has_warning`... by Xiaoyi Zhang <zhangxy@google.com>
  - 02a42cbaa97d82ee7942bc498538359185d75087 Remove literal UTF8 strings in abseil code to avoid file ... by Jon Cohen <cohenjon@google.com>

GitOrigin-RevId: 06abebb2bdb201c572da209fc7f781d6bd774d6b
Change-Id: I4f4659c2e7ca6fc585b6c089bcf20ca61aced75d
This commit is contained in:
Abseil Team 2018-01-31 20:34:59 -08:00 committed by jueminyang
parent 8a401394b8
commit 0ec11bad6f
7 changed files with 27 additions and 39 deletions

View file

@ -18,5 +18,5 @@ possible in this section.]
[Please clearly describe the API change(s) being proposed. If multiple changes, [Please clearly describe the API change(s) being proposed. If multiple changes,
please keep them clearly distinguished. When possible, **use example code please keep them clearly distinguished. When possible, **use example code
snippets to illustrate beforeafter API usages**. List pros-n-cons. Highlight snippets to illustrate before-after API usages**. List pros-n-cons. Highlight
the main questions that you want to be answered. Given the Abseil project compatibility requirements, describe why the API change is safe.] the main questions that you want to be answered. Given the Abseil project compatibility requirements, describe why the API change is safe.]

View file

@ -53,24 +53,7 @@
// it will likely be a reference type). // it will likely be a reference type).
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// ABSL_INTERNAL_HAS_WARNING() #ifdef __cpp_inline_variables
//
// If the compiler supports the `__has_warning` extension for detecting
// warnings, then this macro is defined to be `__has_warning`.
//
// If the compiler does not support `__has_warning`, invocations expand to 0.
//
// For clang's documentation of `__has_warning`, see
// https://clang.llvm.org/docs/LanguageExtensions.html#has-warning
#if defined(__has_warning)
#define ABSL_INTERNAL_HAS_WARNING __has_warning
#else // Otherwise, be optimistic and assume the warning is not enabled.
#define ABSL_INTERNAL_HAS_WARNING(warning) 0
#endif // defined(__has_warning)
// If the compiler supports inline variables and does not warn when used...
#if defined(__cpp_inline_variables) && \
!ABSL_INTERNAL_HAS_WARNING("-Wc++98-c++11-c++14-compat")
// Clang's -Wmissing-variable-declarations option erroneously warned that // Clang's -Wmissing-variable-declarations option erroneously warned that
// inline constexpr objects need to be pre-declared. This has now been fixed, // inline constexpr objects need to be pre-declared. This has now been fixed,
@ -83,21 +66,19 @@
// identity_t is used here so that the const and name are in the // identity_t is used here so that the const and name are in the
// appropriate place for pointer types, reference types, function pointer // appropriate place for pointer types, reference types, function pointer
// types, etc.. // types, etc..
#if defined(__clang__) && \ #if defined(__clang__)
ABSL_INTERNAL_HAS_WARNING("-Wmissing-variable-declarations")
#define ABSL_INTERNAL_EXTERN_DECL(type, name) \ #define ABSL_INTERNAL_EXTERN_DECL(type, name) \
extern const ::absl::internal::identity_t<type> name; extern const ::absl::internal::identity_t<type> name;
#else // Otherwise, just define the macro to do nothing. #else // Otherwise, just define the macro to do nothing.
#define ABSL_INTERNAL_EXTERN_DECL(type, name) #define ABSL_INTERNAL_EXTERN_DECL(type, name)
#endif // defined(__clang__) && #endif // defined(__clang__)
// ABSL_INTERNAL_HAS_WARNING("-Wmissing-variable-declarations")
// See above comment at top of file for details. // See above comment at top of file for details.
#define ABSL_INTERNAL_INLINE_CONSTEXPR(type, name, init) \ #define ABSL_INTERNAL_INLINE_CONSTEXPR(type, name, init) \
ABSL_INTERNAL_EXTERN_DECL(type, name) \ ABSL_INTERNAL_EXTERN_DECL(type, name) \
inline constexpr ::absl::internal::identity_t<type> name = init inline constexpr ::absl::internal::identity_t<type> name = init
#else // Otherwise, we need to emulate inline variables... #else
// See above comment at top of file for details. // See above comment at top of file for details.
// //
@ -121,7 +102,6 @@
static_assert(sizeof(void (*)(decltype(name))) != 0, \ static_assert(sizeof(void (*)(decltype(name))) != 0, \
"Silence unused variable warnings.") "Silence unused variable warnings.")
#endif // defined(__cpp_inline_variables) && #endif // __cpp_inline_variables
// !ABSL_INTERNAL_HAS_WARNING("-Wc++98-c++11-c++14-compat")
#endif // ABSL_BASE_INTERNAL_INLINE_VARIABLE_EMULATION_H_ #endif // ABSL_BASE_INTERNAL_INLINE_VARIABLE_EMULATION_H_

View file

@ -142,7 +142,7 @@ inline void UnalignedStore64(void *p, uint64_t v) {
// and 32-bit values (not 64-bit); older versions either raise a fatal signal, // and 32-bit values (not 64-bit); older versions either raise a fatal signal,
// do an unaligned read and rotate the words around a bit, or do the reads very // do an unaligned read and rotate the words around a bit, or do the reads very
// slowly (trip through kernel mode). There's no simple #define that says just // slowly (trip through kernel mode). There's no simple #define that says just
// “ARMv7 or higher”, so we have to filter away all ARMv5 and ARMv6 // "ARMv7 or higher", so we have to filter away all ARMv5 and ARMv6
// sub-architectures. Newer gcc (>= 4.6) set an __ARM_FEATURE_ALIGNED #define, // sub-architectures. Newer gcc (>= 4.6) set an __ARM_FEATURE_ALIGNED #define,
// so in time, maybe we can move on to that. // so in time, maybe we can move on to that.
// //

View file

@ -621,23 +621,28 @@ TEST(Split, StringDelimiter) {
TEST(Split, UTF8) { TEST(Split, UTF8) {
// Tests splitting utf8 strings and utf8 delimiters. // Tests splitting utf8 strings and utf8 delimiters.
std::string utf8_string = "\u03BA\u1F79\u03C3\u03BC\u03B5";
{ {
// A utf8 input std::string with an ascii delimiter. // A utf8 input std::string with an ascii delimiter.
std::vector<absl::string_view> v = absl::StrSplit("a,κόσμε", ','); std::string to_split = "a," + utf8_string;
EXPECT_THAT(v, ElementsAre("a", "κόσμε")); std::vector<absl::string_view> v = absl::StrSplit(to_split, ',');
EXPECT_THAT(v, ElementsAre("a", utf8_string));
} }
{ {
// A utf8 input std::string and a utf8 delimiter. // A utf8 input std::string and a utf8 delimiter.
std::vector<absl::string_view> v = absl::StrSplit("a,κόσμε,b", ",κόσμε,"); std::string to_split = "a," + utf8_string + ",b";
std::string unicode_delimiter = "," + utf8_string + ",";
std::vector<absl::string_view> v =
absl::StrSplit(to_split, unicode_delimiter);
EXPECT_THAT(v, ElementsAre("a", "b")); EXPECT_THAT(v, ElementsAre("a", "b"));
} }
{ {
// A utf8 input std::string and ByAnyChar with ascii chars. // A utf8 input std::string and ByAnyChar with ascii chars.
std::vector<absl::string_view> v = std::vector<absl::string_view> v =
absl::StrSplit("Foo hällo th丞re", absl::ByAnyChar(" \t")); absl::StrSplit("Foo h\u00E4llo th\u4E1Ere", absl::ByAnyChar(" \t"));
EXPECT_THAT(v, ElementsAre("Foo", "hällo", "th丞re")); EXPECT_THAT(v, ElementsAre("Foo", "h\u00E4llo", "th\u4E1Ere"));
} }
} }

View file

@ -684,8 +684,11 @@ TEST(StringViewTest, TruncSubstr) {
} }
TEST(StringViewTest, UTF8) { TEST(StringViewTest, UTF8) {
EXPECT_EQ(strlen("á"), absl::string_view("á á").find_first_of(" ")); std::string utf8 = "\u00E1";
EXPECT_EQ(strlen("á"), absl::string_view("á á").find_first_of(" \t")); std::string utf8_twice = utf8 + " " + utf8;
int utf8_len = strlen(utf8.data());
EXPECT_EQ(utf8_len, absl::string_view(utf8_twice).find_first_of(" "));
EXPECT_EQ(utf8_len, absl::string_view(utf8_twice).find_first_of(" \t"));
} }
TEST(StringViewTest, FindConformance) { TEST(StringViewTest, FindConformance) {

View file

@ -304,7 +304,7 @@ class any {
// object of type `VT` with the arguments `std::forward<Args>(args)...`, and // object of type `VT` with the arguments `std::forward<Args>(args)...`, and
// returning a reference to the new contained value. // returning a reference to the new contained value.
// //
// Note: If an exception is thrown during the call to `VT`s constructor, // Note: If an exception is thrown during the call to `VT`'s constructor,
// `*this` does not contain a value, and any previously contained value has // `*this` does not contain a value, and any previously contained value has
// been destroyed. // been destroyed.
template < template <
@ -325,7 +325,7 @@ class any {
// `initilizer_list, std::forward<Args>(args)...`, and returning a reference // `initilizer_list, std::forward<Args>(args)...`, and returning a reference
// to the new contained value. // to the new contained value.
// //
// Note: If an exception is thrown during the call to `VT`s constructor, // Note: If an exception is thrown during the call to `VT`'s constructor,
// `*this` does not contain a value, and any previously contained value has // `*this` does not contain a value, and any previously contained value has
// been destroyed. The function shall not participate in overload resolution // been destroyed. The function shall not participate in overload resolution
// unless `is_copy_constructible_v<VT>` is `true` and // unless `is_copy_constructible_v<VT>` is `true` and

View file

@ -492,11 +492,11 @@ class optional : private optional_internal::optional_data<T>,
// Constructors // Constructors
// Constructs a default-constructed `optional` holding the empty value, NOT a // Constructs an `optional` holding an empty value, NOT a default constructed
// default constructed `T`. // `T`.
constexpr optional() noexcept {} constexpr optional() noexcept {}
// Construct an `optional` initialized with `nullopt` to hold an empty value. // Constructs an `optional` initialized with `nullopt` to hold an empty value.
constexpr optional(nullopt_t) noexcept {} // NOLINT(runtime/explicit) constexpr optional(nullopt_t) noexcept {} // NOLINT(runtime/explicit)
// Copy constructor, standard semantics // Copy constructor, standard semantics