summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--absl/base/config.h2
-rw-r--r--absl/container/BUILD.bazel3
-rw-r--r--absl/container/CMakeLists.txt3
-rw-r--r--absl/container/internal/raw_hash_set_test.cc27
-rw-r--r--absl/log/internal/log_sink_set.cc1
-rw-r--r--absl/log/log_entry.h6
-rw-r--r--absl/strings/BUILD.bazel3
-rw-r--r--absl/strings/CMakeLists.txt1
-rw-r--r--absl/strings/charconv.cc11
-rw-r--r--absl/strings/str_cat.h5
-rw-r--r--absl/strings/str_cat_test.cc18
-rw-r--r--absl/strings/str_format.h5
-rw-r--r--absl/strings/str_format_test.cc17
13 files changed, 87 insertions, 15 deletions
diff --git a/absl/base/config.h b/absl/base/config.h
index 35911698..1058ce74 100644
--- a/absl/base/config.h
+++ b/absl/base/config.h
@@ -243,7 +243,7 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
#ifdef ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE
#error ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE cannot be directly set
#elif defined(_LIBCPP_VERSION) || defined(_MSC_VER) || \
- (defined(__clang__) && __clang_major__ >= 15) || \
+ (defined(__clang__) && __clang_major__ >= 15) || \
(!defined(__clang__) && defined(__GLIBCXX__) && \
ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(4, 8))
#define ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE 1
diff --git a/absl/container/BUILD.bazel b/absl/container/BUILD.bazel
index 71afe9d2..15162f28 100644
--- a/absl/container/BUILD.bazel
+++ b/absl/container/BUILD.bazel
@@ -637,6 +637,8 @@ cc_test(
],
deps = [
":container_memory",
+ ":flat_hash_map",
+ ":flat_hash_set",
":hash_function_defaults",
":hash_policy_testing",
":hashtable_debug",
@@ -646,6 +648,7 @@ cc_test(
"//absl/base:core_headers",
"//absl/base:prefetch",
"//absl/base:raw_logging_internal",
+ "//absl/log",
"//absl/strings",
"@com_google_googletest//:gtest_main",
],
diff --git a/absl/container/CMakeLists.txt b/absl/container/CMakeLists.txt
index a3fdb969..6c2931b6 100644
--- a/absl/container/CMakeLists.txt
+++ b/absl/container/CMakeLists.txt
@@ -722,12 +722,15 @@ absl_cc_test(
${ABSL_TEST_COPTS}
DEPS
absl::container_memory
+ absl::flat_hash_map
+ absl::flat_hash_set
absl::hash_function_defaults
absl::hash_policy_testing
absl::hashtable_debug
absl::raw_hash_set
absl::base
absl::config
+ absl::log
absl::core_headers
absl::prefetch
absl::raw_logging_internal
diff --git a/absl/container/internal/raw_hash_set_test.cc b/absl/container/internal/raw_hash_set_test.cc
index f77ffbc1..eec9da43 100644
--- a/absl/container/internal/raw_hash_set_test.cc
+++ b/absl/container/internal/raw_hash_set_test.cc
@@ -14,17 +14,25 @@
#include "absl/container/internal/raw_hash_set.h"
+#include <algorithm>
#include <atomic>
#include <cmath>
#include <cstdint>
#include <deque>
#include <functional>
+#include <iterator>
+#include <list>
+#include <map>
#include <memory>
#include <numeric>
+#include <ostream>
#include <random>
#include <string>
+#include <type_traits>
#include <unordered_map>
#include <unordered_set>
+#include <utility>
+#include <vector>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
@@ -33,10 +41,13 @@
#include "absl/base/internal/cycleclock.h"
#include "absl/base/internal/prefetch.h"
#include "absl/base/internal/raw_logging.h"
+#include "absl/container/flat_hash_map.h"
+#include "absl/container/flat_hash_set.h"
#include "absl/container/internal/container_memory.h"
#include "absl/container/internal/hash_function_defaults.h"
#include "absl/container/internal/hash_policy_testing.h"
#include "absl/container/internal/hashtable_debug.h"
+#include "absl/log/log.h"
#include "absl/strings/string_view.h"
namespace absl {
@@ -339,7 +350,7 @@ class StringPolicy {
struct ctor {};
template <class... Ts>
- slot_type(ctor, Ts&&... ts) : pair(std::forward<Ts>(ts)...) {}
+ explicit slot_type(ctor, Ts&&... ts) : pair(std::forward<Ts>(ts)...) {}
std::pair<std::string, std::string> pair;
};
@@ -411,7 +422,7 @@ struct CustomAlloc : std::allocator<T> {
CustomAlloc() {}
template <typename U>
- CustomAlloc(const CustomAlloc<U>& other) {}
+ explicit CustomAlloc(const CustomAlloc<U>& /*other*/) {}
template<class U> struct rebind {
using other = CustomAlloc<U>;
@@ -1275,6 +1286,7 @@ TEST(Table, DISABLED_EnsureNonQuadraticTopNXorSeedByProbeSeqLength) {
for (size_t size : sizes) {
auto& stat = stats[size];
VerifyStats(size, expected, stat);
+ LOG(INFO) << size << " " << stat;
}
}
@@ -1370,6 +1382,7 @@ TEST(Table, DISABLED_EnsureNonQuadraticTopNLinearTransformByProbeSeqLength) {
for (size_t size : sizes) {
auto& stat = stats[size];
VerifyStats(size, expected, stat);
+ LOG(INFO) << size << " " << stat;
}
}
@@ -1504,7 +1517,7 @@ TEST(Table, RehashZeroForcesRehash) {
TEST(Table, ConstructFromInitList) {
using P = std::pair<std::string, std::string>;
struct Q {
- operator P() const { return {}; }
+ operator P() const { return {}; } // NOLINT
};
StringTable t = {P(), Q(), {}, {{}, {}}};
}
@@ -2027,7 +2040,7 @@ TEST(Table, UnstablePointers) {
TEST(TableDeathTest, EraseOfEndAsserts) {
// Use an assert with side-effects to figure out if they are actually enabled.
bool assert_enabled = false;
- assert([&]() {
+ assert([&]() { // NOLINT
assert_enabled = true;
return true;
}());
@@ -2047,7 +2060,7 @@ TEST(RawHashSamplerTest, Sample) {
auto& sampler = GlobalHashtablezSampler();
size_t start_size = 0;
- std::unordered_set<const HashtablezInfo*> preexisting_info;
+ absl::flat_hash_set<const HashtablezInfo*> preexisting_info;
start_size += sampler.Iterate([&](const HashtablezInfo& info) {
preexisting_info.insert(&info);
++start_size;
@@ -2074,8 +2087,8 @@ TEST(RawHashSamplerTest, Sample) {
}
}
size_t end_size = 0;
- std::unordered_map<size_t, int> observed_checksums;
- std::unordered_map<ssize_t, int> reservations;
+ absl::flat_hash_map<size_t, int> observed_checksums;
+ absl::flat_hash_map<ssize_t, int> reservations;
end_size += sampler.Iterate([&](const HashtablezInfo& info) {
if (preexisting_info.count(&info) == 0) {
observed_checksums[info.hashes_bitwise_xor.load(
diff --git a/absl/log/internal/log_sink_set.cc b/absl/log/internal/log_sink_set.cc
index 4fe301c6..f9d030aa 100644
--- a/absl/log/internal/log_sink_set.cc
+++ b/absl/log/internal/log_sink_set.cc
@@ -69,6 +69,7 @@ bool& ThreadIsLoggingStatus() {
}
return true;
}();
+ (void)unused; // Fixes -wunused-variable warning
bool* thread_is_logging_ptr =
reinterpret_cast<bool*>(pthread_getspecific(thread_is_logging_key));
diff --git a/absl/log/log_entry.h b/absl/log/log_entry.h
index d90961fe..30114c33 100644
--- a/absl/log/log_entry.h
+++ b/absl/log/log_entry.h
@@ -58,8 +58,10 @@ class LogEntry final {
static constexpr int kNoVerbosityLevel = -1;
static constexpr int kNoVerboseLevel = -1; // TO BE removed
- LogEntry(const LogEntry&) = default;
- LogEntry& operator=(const LogEntry&) = default;
+ // Pass `LogEntry` by reference, and do not store it as its state does not
+ // outlive the call to `LogSink::Send()`.
+ LogEntry(const LogEntry&) = delete;
+ LogEntry& operator=(const LogEntry&) = delete;
// Source file and line where the log message occurred. Taken from `__FILE__`
// and `__LINE__` unless overridden by `LOG(...).AtLocation(...)`.
diff --git a/absl/strings/BUILD.bazel b/absl/strings/BUILD.bazel
index 5a40887e..5b12c010 100644
--- a/absl/strings/BUILD.bazel
+++ b/absl/strings/BUILD.bazel
@@ -963,8 +963,8 @@ cc_test(
copts = ABSL_TEST_COPTS,
visibility = ["//visibility:private"],
deps = [
+ ":str_format",
":strings",
- "//absl/base:core_headers",
"@com_google_googletest//:gtest_main",
],
)
@@ -1164,7 +1164,6 @@ cc_test(
":cord",
":str_format",
":strings",
- "//absl/base:core_headers",
"@com_google_googletest//:gtest_main",
],
)
diff --git a/absl/strings/CMakeLists.txt b/absl/strings/CMakeLists.txt
index e1c2093a..01f86184 100644
--- a/absl/strings/CMakeLists.txt
+++ b/absl/strings/CMakeLists.txt
@@ -281,6 +281,7 @@ absl_cc_test(
${ABSL_TEST_COPTS}
DEPS
absl::strings
+ absl::str_format
absl::core_headers
GTest::gmock_main
)
diff --git a/absl/strings/charconv.cc b/absl/strings/charconv.cc
index 9b4bc5ea..c08623c4 100644
--- a/absl/strings/charconv.cc
+++ b/absl/strings/charconv.cc
@@ -339,14 +339,19 @@ template <typename FloatType>
bool HandleEdgeCase(const strings_internal::ParsedFloat& input, bool negative,
FloatType* value) {
if (input.type == strings_internal::FloatType::kNan) {
- // A bug in both clang and gcc would cause the compiler to optimize away the
- // buffer we are building below. Declaring the buffer volatile avoids the
- // issue, and has no measurable performance impact in microbenchmarks.
+ // A bug in both clang < 7 and gcc would cause the compiler to optimize
+ // away the buffer we are building below. Declaring the buffer volatile
+ // avoids the issue, and has no measurable performance impact in
+ // microbenchmarks.
//
// https://bugs.llvm.org/show_bug.cgi?id=37778
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86113
constexpr ptrdiff_t kNanBufferSize = 128;
+#if defined(__GNUC__) || (defined(__clang__) && __clang_major__ < 7)
volatile char n_char_sequence[kNanBufferSize];
+#else
+ char n_char_sequence[kNanBufferSize];
+#endif
if (input.subrange_begin == nullptr) {
n_char_sequence[0] = '\0';
} else {
diff --git a/absl/strings/str_cat.h b/absl/strings/str_cat.h
index 05728ab5..6ee88f14 100644
--- a/absl/strings/str_cat.h
+++ b/absl/strings/str_cat.h
@@ -85,6 +85,11 @@ class StringifySink {
bool PutPaddedString(string_view v, int width, int precision, bool left);
+ // Support `absl::Format(&sink, format, args...)`.
+ friend void AbslFormatFlush(StringifySink* sink, absl::string_view v) {
+ sink->Append(v);
+ }
+
template <typename T>
friend string_view ExtractStringification(StringifySink& sink, const T& v);
diff --git a/absl/strings/str_cat_test.cc b/absl/strings/str_cat_test.cc
index 868b9bce..1b3b7ece 100644
--- a/absl/strings/str_cat_test.cc
+++ b/absl/strings/str_cat_test.cc
@@ -21,6 +21,7 @@
#include <vector>
#include "gtest/gtest.h"
+#include "absl/strings/str_format.h"
#include "absl/strings/substitute.h"
#ifdef __ANDROID__
@@ -632,4 +633,21 @@ TEST(StrCat, AbslStringifyExample) {
EXPECT_EQ(absl::StrCat("a ", p, " z"), "a (10, 20) z");
}
+struct PointStringifyUsingFormat {
+ template <typename FormatSink>
+ friend void AbslStringify(FormatSink& sink,
+ const PointStringifyUsingFormat& p) {
+ absl::Format(&sink, "(%g, %g)", p.x, p.y);
+ }
+
+ double x = 10.0;
+ double y = 20.0;
+};
+
+TEST(StrCat, AbslStringifyExampleUsingFormat) {
+ PointStringifyUsingFormat p;
+ EXPECT_EQ(absl::StrCat(p), "(10, 20)");
+ EXPECT_EQ(absl::StrCat("a ", p, " z"), "a (10, 20) z");
+}
+
} // namespace
diff --git a/absl/strings/str_format.h b/absl/strings/str_format.h
index e6537ea0..ffbcb9af 100644
--- a/absl/strings/str_format.h
+++ b/absl/strings/str_format.h
@@ -789,6 +789,11 @@ class FormatSink {
return sink_->PutPaddedString(v, width, precision, left);
}
+ // Support `absl::Format(&sink, format, args...)`.
+ friend void AbslFormatFlush(FormatSink* sink, absl::string_view v) {
+ sink->Append(v);
+ }
+
private:
friend str_format_internal::FormatSinkImpl;
explicit FormatSink(str_format_internal::FormatSinkImpl* s) : sink_(s) {}
diff --git a/absl/strings/str_format_test.cc b/absl/strings/str_format_test.cc
index 0c4f10c8..62ed262d 100644
--- a/absl/strings/str_format_test.cc
+++ b/absl/strings/str_format_test.cc
@@ -1118,6 +1118,23 @@ TEST_F(FormatExtensionTest, AbslStringifyExample) {
PointStringify p;
EXPECT_EQ(absl::StrFormat("a %v z", p), "a (10, 20) z");
}
+
+struct PointStringifyUsingFormat {
+ template <typename FormatSink>
+ friend void AbslStringify(FormatSink& sink,
+ const PointStringifyUsingFormat& p) {
+ absl::Format(&sink, "(%g, %g)", p.x, p.y);
+ }
+
+ double x = 10.0;
+ double y = 20.0;
+};
+
+TEST_F(FormatExtensionTest, AbslStringifyExampleUsingFormat) {
+ PointStringifyUsingFormat p;
+ EXPECT_EQ(absl::StrFormat("a %v z", p), "a (10, 20) z");
+}
+
} // namespace
// Some codegen thunks that we can use to easily dump the generated assembly for