From f45f47606083b408b7d08c68b1167e8ffcd38e76 Mon Sep 17 00:00:00 2001 From: Daniel Cheng Date: Mon, 28 Feb 2022 22:38:32 +0000 Subject: [PATCH] Migrate base::{size,empty,data} to STL equivalents in //base. This is not a complete migration; this only migrates fully-qualified references to these functions, with the minimal set of build fixes needed to make things compile. Bug: 1299695 Change-Id: Ib7359b018dae054adcc87e435aee0f186c74fd50 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3492822 Reviewed-by: Lei Zhang Commit-Queue: Lei Zhang Owners-Override: Lei Zhang Cr-Commit-Position: refs/heads/main@{#975977} --- .../address_pool_manager.cc | 5 +- .../partition_alloc_unittest.cc | 7 +- .../jank_metric_uma_recorder_unittest.cc | 6 +- base/android/jni_array_unittest.cc | 29 +++-- base/command_line.cc | 4 +- base/command_line_unittest.cc | 8 +- base/containers/checked_range.h | 11 +- base/containers/checked_range_unittest.cc | 12 +-- base/containers/flat_tree.h | 7 +- base/containers/intrusive_heap_unittest.cc | 3 +- base/containers/linked_list_unittest.cc | 30 +++--- base/containers/span.h | 27 +++-- base/containers/span_unittest.cc | 18 ++-- base/cpu.cc | 5 +- base/cxx17_backports_unittest.cc | 100 +++++++++--------- base/debug/crash_logging.h | 3 +- base/debug/debugger_posix.cc | 5 +- base/debug/proc_maps_linux_unittest.cc | 10 +- base/debug/stack_trace.cc | 7 +- base/debug/stack_trace_fuchsia.cc | 3 +- base/debug/stack_trace_posix.cc | 2 +- base/feature_list_unittest.cc | 9 +- base/files/file_path.h | 2 +- base/files/file_path_constants.cc | 3 +- base/files/file_path_unittest.cc | 56 +++++----- base/files/file_path_watcher_fsevents.cc | 3 +- base/files/file_proxy_unittest.cc | 5 +- base/files/file_util_posix.cc | 6 +- base/files/file_util_unittest.cc | 11 +- base/files/file_util_win.cc | 8 +- base/files/important_file_writer.cc | 5 +- base/hash/md5_constexpr_unittest.cc | 9 +- base/i18n/break_iterator_unittest.cc | 4 +- base/i18n/build_utf8_validator_tables.cc | 13 ++- base/i18n/file_util_icu_unittest.cc | 2 +- base/i18n/icu_string_conversions_unittest.cc | 8 +- base/i18n/rtl.cc | 3 +- .../i18n/streaming_utf8_validator_unittest.cc | 11 +- base/i18n/string_search_unittest.cc | 8 +- base/i18n/utf8_validator_tables.cc | 5 +- base/ios/ios_util.mm | 4 +- base/json/json_reader_unittest.cc | 11 +- base/json/string_escape_unittest.cc | 3 +- base/logging.cc | 12 +-- base/mac/authorization_util.mm | 5 +- base/mac/backup_util_unittest.mm | 12 +-- base/mac/foundation_util.mm | 3 +- base/mac/foundation_util_unittest.mm | 9 +- base/mac/mac_util_unittest.mm | 5 +- base/mac/mach_port_rendezvous_unittest.cc | 3 +- base/mac/os_crash_dumps.cc | 3 +- base/memory/ref_counted_memory_unittest.cc | 2 +- base/message_loop/message_pump_mac.mm | 3 +- base/metrics/metrics_hashes_unittest.cc | 5 +- base/metrics/sparse_histogram_unittest.cc | 3 +- base/pickle_unittest.cc | 4 +- base/process/memory.cc | 2 +- base/process/process_handle_freebsd.cc | 6 +- base/process/process_handle_openbsd.cc | 10 +- base/process/process_iterator_freebsd.cc | 9 +- base/process/process_iterator_mac.cc | 9 +- base/process/process_iterator_openbsd.cc | 9 +- base/process/process_metrics_freebsd.cc | 5 +- base/process/process_metrics_openbsd.cc | 7 +- base/process/process_win.cc | 2 +- .../chrome_unwind_info_android_unittest.cc | 22 ++-- .../chrome_unwinder_android_v2_unittest.cc | 10 +- .../stack_sampling_profiler_unittest.cc | 2 +- ...seil_string_number_conversions_unittest.cc | 3 +- base/strings/escape.cc | 4 +- .../string_number_conversions_unittest.cc | 29 +++-- base/strings/string_util.cc | 7 +- base/strings/string_util_internal.h | 2 +- base/strings/string_util_unittest.cc | 35 +++--- base/strings/stringprintf.cc | 7 +- .../utf_offset_string_conversions_unittest.cc | 30 +++--- .../utf_string_conversions_unittest.cc | 14 +-- base/sync_socket_win.cc | 5 +- base/system/sys_info_chromeos.cc | 5 +- base/system/sys_info_ios.mm | 3 +- base/system/sys_info_mac.mm | 3 +- base/system/sys_info_openbsd.cc | 9 +- ...troller_with_message_pump_impl_unittest.cc | 4 +- ...ooled_single_thread_task_runner_manager.cc | 9 +- base/task/thread_pool/task_tracker.cc | 2 +- base/threading/hang_watcher.cc | 2 +- base/threading/platform_thread_unittest.cc | 18 ++-- .../sequence_local_storage_slot_unittest.cc | 5 +- base/time/pr_time_unittest.cc | 3 +- base/time/time_mac.mm | 3 +- base/time/time_unittest.cc | 3 +- base/trace_event/builtin_categories.h | 12 +-- ...eap_profiler_allocation_context_tracker.cc | 9 +- base/trace_event/memory_dump_manager.cc | 2 +- base/values.cc | 6 +- base/vlog.cc | 3 +- base/win/access_token.cc | 3 +- base/win/i18n.cc | 2 +- .../scoped_process_information_unittest.cc | 2 +- base/win/shortcut_unittest.cc | 17 ++- base/win/win_util_unittest.cc | 3 +- .../gaussian_trainer.cc | 1 + .../video/chromeos/camera_app_device_impl.cc | 1 + media/gpu/vaapi/test/vp8_decoder.cc | 1 + 104 files changed, 426 insertions(+), 494 deletions(-) diff --git a/base/allocator/partition_allocator/address_pool_manager.cc b/base/allocator/partition_allocator/address_pool_manager.cc index c1bcd730d853a7..ef289974ced080 100644 --- a/base/allocator/partition_allocator/address_pool_manager.cc +++ b/base/allocator/partition_allocator/address_pool_manager.cc @@ -17,7 +17,6 @@ #include "base/allocator/partition_allocator/partition_alloc_constants.h" #include "base/allocator/partition_allocator/partition_alloc_notreached.h" #include "base/allocator/partition_allocator/reservation_offset_table.h" -#include "base/cxx17_backports.h" #include "base/lazy_instance.h" #include "build/build_config.h" @@ -57,7 +56,7 @@ pool_handle AddressPoolManager::Add(uintptr_t ptr, size_t length) { PA_DCHECK(!(ptr & kSuperPageOffsetMask)); PA_DCHECK(!((ptr + length) & kSuperPageOffsetMask)); - for (pool_handle i = 0; i < base::size(pools_); ++i) { + for (pool_handle i = 0; i < std::size(pools_); ++i) { if (!pools_[i].IsInitialized()) { pools_[i].Initialize(ptr, length); return i + 1; @@ -86,7 +85,7 @@ uintptr_t AddressPoolManager::GetPoolBaseAddress(pool_handle handle) { } void AddressPoolManager::ResetForTesting() { - for (pool_handle i = 0; i < base::size(pools_); ++i) + for (pool_handle i = 0; i < std::size(pools_); ++i) pools_[i].Reset(); } diff --git a/base/allocator/partition_allocator/partition_alloc_unittest.cc b/base/allocator/partition_allocator/partition_alloc_unittest.cc index f02c4b825d95be..9d20204373e3e8 100644 --- a/base/allocator/partition_allocator/partition_alloc_unittest.cc +++ b/base/allocator/partition_allocator/partition_alloc_unittest.cc @@ -32,7 +32,6 @@ #include "base/allocator/partition_allocator/tagging.h" #include "base/bits.h" #include "base/cpu.h" -#include "base/cxx17_backports.h" #include "base/logging.h" #include "base/rand_util.h" #include "base/system/sys_info.h" @@ -147,7 +146,7 @@ const size_t kTestSizes[] = { 1 << 20, 1 << 21, }; -constexpr size_t kTestSizesCount = base::size(kTestSizes); +constexpr size_t kTestSizesCount = std::size(kTestSizes); void AllocateRandomly(base::PartitionRoot* root, size_t count, @@ -4382,10 +4381,10 @@ class ScopedOpenCLNoOpKernel { const size_t source_lengths[] = { strlen(sources[0]), }; - static_assert(base::size(sources) == base::size(source_lengths), + static_assert(std::size(sources) == std::size(source_lengths), "arrays must be parallel"); - program_ = clCreateProgramWithSource(context_, base::size(sources), sources, + program_ = clCreateProgramWithSource(context_, std::size(sources), sources, source_lengths, &rv); ASSERT_EQ(rv, CL_SUCCESS) << "clCreateProgramWithSource"; diff --git a/base/android/jank_metric_uma_recorder_unittest.cc b/base/android/jank_metric_uma_recorder_unittest.cc index 23d9bd5ad1f2e2..e72f43478022c3 100644 --- a/base/android/jank_metric_uma_recorder_unittest.cc +++ b/base/android/jank_metric_uma_recorder_unittest.cc @@ -49,9 +49,9 @@ const int64_t kDurations[] = { 1'000'000, // 1ms 20'000'000, // 20ms }; -const size_t kDurationsLen = base::size(kDurations); +const size_t kDurationsLen = std::size(kDurations); -static_assert(base::size(kDurations) == base::size(kTimestampsNs), +static_assert(std::size(kDurations) == std::size(kTimestampsNs), "Length of timestamps and durations should be equal."); // Jank bursts are calculated based on durations. @@ -59,7 +59,7 @@ const int64_t kJankBursts[] = { 100'000'000, // 100ms 20'000'000, // 20ms }; -const size_t kJankBurstsLen = base::size(kJankBursts); +const size_t kJankBurstsLen = std::size(kJankBursts); } // namespace diff --git a/base/android/jni_array_unittest.cc b/base/android/jni_array_unittest.cc index f862a2d95fb01f..89293aa15deb93 100644 --- a/base/android/jni_array_unittest.cc +++ b/base/android/jni_array_unittest.cc @@ -6,14 +6,13 @@ #include #include -#include +#include #include #include "base/android/jni_android.h" #include "base/android/jni_string.h" #include "base/android/scoped_java_ref.h" -#include "base/cxx17_backports.h" #include "base/strings/utf_string_conversions.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -23,7 +22,7 @@ namespace android { TEST(JniArray, BasicConversions) { const uint8_t kBytes[] = {0, 1, 2, 3}; - const size_t kLen = base::size(kBytes); + const size_t kLen = std::size(kBytes); JNIEnv* env = AttachCurrentThread(); ScopedJavaLocalRef bytes = ToJavaByteArray(env, kBytes, kLen); ASSERT_TRUE(bytes); @@ -79,7 +78,7 @@ void CheckBoolConversion(JNIEnv* env, TEST(JniArray, BoolConversions) { const bool kBools[] = {false, true, false}; - const size_t kLen = base::size(kBools); + const size_t kLen = std::size(kBools); JNIEnv* env = AttachCurrentThread(); CheckBoolConversion(env, kBools, kLen, ToJavaBooleanArray(env, kBools, kLen)); @@ -105,7 +104,7 @@ void CheckIntConversion( TEST(JniArray, IntConversions) { const int kInts[] = {0, 1, -1, std::numeric_limits::min(), std::numeric_limits::max()}; - const size_t kLen = base::size(kInts); + const size_t kLen = std::size(kInts); JNIEnv* env = AttachCurrentThread(); CheckIntConversion(env, kInts, kLen, ToJavaIntArray(env, kInts, kLen)); @@ -133,7 +132,7 @@ void CheckLongConversion(JNIEnv* env, TEST(JniArray, LongConversions) { const int64_t kLongs[] = {0, 1, -1, std::numeric_limits::min(), std::numeric_limits::max()}; - const size_t kLen = base::size(kLongs); + const size_t kLen = std::size(kLongs); JNIEnv* env = AttachCurrentThread(); CheckLongConversion(env, kLongs, kLen, ToJavaLongArray(env, kLongs, kLen)); @@ -207,7 +206,7 @@ TEST(JniArray, ArrayOfStringArrayConversionUTF16) { TEST(JniArray, FloatConversions) { const float kFloats[] = { 0.0f, 1.0f, -10.0f}; - const size_t kLen = base::size(kFloats); + const size_t kLen = std::size(kFloats); JNIEnv* env = AttachCurrentThread(); CheckFloatConversion(env, kFloats, kLen, @@ -219,7 +218,7 @@ TEST(JniArray, FloatConversions) { TEST(JniArray, JavaBooleanArrayToBoolVector) { const bool kBools[] = {false, true, false}; - const size_t kLen = base::size(kBools); + const size_t kLen = std::size(kBools); JNIEnv* env = AttachCurrentThread(); ScopedJavaLocalRef jbooleans(env, env->NewBooleanArray(kLen)); @@ -242,7 +241,7 @@ TEST(JniArray, JavaBooleanArrayToBoolVector) { TEST(JniArray, JavaIntArrayToIntVector) { const int kInts[] = {0, 1, -1}; - const size_t kLen = base::size(kInts); + const size_t kLen = std::size(kInts); JNIEnv* env = AttachCurrentThread(); ScopedJavaLocalRef jints(env, env->NewIntArray(kLen)); @@ -264,7 +263,7 @@ TEST(JniArray, JavaIntArrayToIntVector) { TEST(JniArray, JavaLongArrayToInt64Vector) { const int64_t kInt64s[] = {0LL, 1LL, -1LL}; - const size_t kLen = base::size(kInt64s); + const size_t kLen = std::size(kInt64s); JNIEnv* env = AttachCurrentThread(); ScopedJavaLocalRef jlongs(env, env->NewLongArray(kLen)); @@ -292,7 +291,7 @@ TEST(JniArray, JavaLongArrayToInt64Vector) { TEST(JniArray, JavaLongArrayToLongVector) { const int64_t kInt64s[] = {0LL, 1LL, -1LL}; - const size_t kLen = base::size(kInt64s); + const size_t kLen = std::size(kInt64s); JNIEnv* env = AttachCurrentThread(); ScopedJavaLocalRef jlongs(env, env->NewLongArray(kLen)); @@ -319,7 +318,7 @@ TEST(JniArray, JavaLongArrayToLongVector) { TEST(JniArray, JavaFloatArrayToFloatVector) { const float kFloats[] = {0.0, 0.5, -0.5}; - const size_t kLen = base::size(kFloats); + const size_t kLen = std::size(kFloats); JNIEnv* env = AttachCurrentThread(); ScopedJavaLocalRef jfloats(env, env->NewFloatArray(kLen)); @@ -489,12 +488,12 @@ TEST(JniArray, JavaArrayOfIntArrayToIntVector) { // Populate int[][] object. const int kInts0[] = {0, 1, -1, std::numeric_limits::min(), std::numeric_limits::max()}; - const size_t kLen0 = base::size(kInts0); + const size_t kLen0 = std::size(kInts0); ScopedJavaLocalRef int_array0 = ToJavaIntArray(env, kInts0, kLen0); env->SetObjectArrayElement(array.obj(), 0, int_array0.obj()); const int kInts1[] = {3, 4, 5}; - const size_t kLen1 = base::size(kInts1); + const size_t kLen1 = std::size(kInts1); ScopedJavaLocalRef int_array1 = ToJavaIntArray(env, kInts1, kLen1); env->SetObjectArrayElement(array.obj(), 1, int_array1.obj()); @@ -504,7 +503,7 @@ TEST(JniArray, JavaArrayOfIntArrayToIntVector) { env->SetObjectArrayElement(array.obj(), 2, int_array2.obj()); const int kInts3[] = {16}; - const size_t kLen3 = base::size(kInts3); + const size_t kLen3 = std::size(kInts3); ScopedJavaLocalRef int_array3 = ToJavaIntArray(env, kInts3, kLen3); env->SetObjectArrayElement(array.obj(), 3, int_array3.obj()); diff --git a/base/command_line.cc b/base/command_line.cc index 8f26e95cc6c578..b59bc4b1b6041c 100644 --- a/base/command_line.cc +++ b/base/command_line.cc @@ -50,7 +50,7 @@ constexpr CommandLine::StringPieceType kSwitchPrefixes[] = {L"--", L"-", L"/"}; // Unixes don't use slash as a switch. constexpr CommandLine::StringPieceType kSwitchPrefixes[] = {"--", "-"}; #endif -size_t switch_prefix_count = base::size(kSwitchPrefixes); +size_t switch_prefix_count = std::size(kSwitchPrefixes); #if BUILDFLAG(IS_WIN) // Switch string that specifies the single argument to the command line. @@ -196,7 +196,7 @@ void CommandLine::set_slash_is_not_a_switch() { // The last switch prefix should be slash, so adjust the size to skip it. static_assert(base::make_span(kSwitchPrefixes).back() == L"/", "Error: Last switch prefix is not a slash."); - switch_prefix_count = base::size(kSwitchPrefixes) - 1; + switch_prefix_count = std::size(kSwitchPrefixes) - 1; } // static diff --git a/base/command_line_unittest.cc b/base/command_line_unittest.cc index ec3d1bd5e08006..20226a0c10b158 100644 --- a/base/command_line_unittest.cc +++ b/base/command_line_unittest.cc @@ -48,7 +48,7 @@ TEST(CommandLineTest, CommandLineConstructor) { FILE_PATH_LITERAL("--not-a-switch"), FILE_PATH_LITERAL("\"in the time of submarines...\""), FILE_PATH_LITERAL("unquoted arg-with-space")}; - CommandLine cl(size(argv), argv); + CommandLine cl(std::size(argv), argv); EXPECT_FALSE(cl.GetCommandLineString().empty()); EXPECT_FALSE(cl.HasSwitch("cruller")); @@ -293,7 +293,7 @@ TEST(CommandLineTest, AppendSwitchesDashDash) { const CommandLine::CharType* raw_argv[] = { FILE_PATH_LITERAL("prog"), FILE_PATH_LITERAL("--"), FILE_PATH_LITERAL("--arg1") }; - CommandLine cl(size(raw_argv), raw_argv); + CommandLine cl(std::size(raw_argv), raw_argv); cl.AppendSwitch("switch1"); cl.AppendSwitchASCII("switch2", "foo"); @@ -564,7 +564,7 @@ TEST(CommandLineTest, MultipleSameSwitch) { FILE_PATH_LITERAL("-baz"), FILE_PATH_LITERAL("--foo=two") // --foo second time }; - CommandLine cl(size(argv), argv); + CommandLine cl(std::size(argv), argv); EXPECT_TRUE(cl.HasSwitch("foo")); EXPECT_TRUE(cl.HasSwitch("baz")); @@ -614,7 +614,7 @@ TEST(CommandLineTest, MultipleFilterFileSwitch) { CommandLine::SetDuplicateSwitchHandler( std::make_unique()); - CommandLine cl(size(argv), argv); + CommandLine cl(std::size(argv), argv); EXPECT_TRUE(cl.HasSwitch("mergeable-foo")); EXPECT_TRUE(cl.HasSwitch("baz")); diff --git a/base/containers/checked_range.h b/base/containers/checked_range.h index e3e799f3dc3157..1dae9075cb0af8 100644 --- a/base/containers/checked_range.h +++ b/base/containers/checked_range.h @@ -12,7 +12,6 @@ #include #include "base/containers/checked_iterators.h" -#include "base/cxx17_backports.h" #include "base/template_util.h" namespace base { @@ -20,7 +19,7 @@ namespace base { // CheckedContiguousRange is a light-weight wrapper around a container modeling // the ContiguousContainer requirement [1, 2]. Effectively this means that the // container stores its elements contiguous in memory. Furthermore, it is -// expected that base::data(container) and base::size(container) are valid +// expected that std::data(container) and std::size(container) are valid // expressions, and that data() + idx is dereferenceable for all idx in the // range [0, size()). In the standard library this includes the containers // std::string, std::vector and std::array, but other containers like @@ -51,7 +50,7 @@ template class CheckedContiguousRange { public: using element_type = std::remove_pointer_t()))>; + std::data(std::declval()))>; using value_type = std::remove_cv_t; using reference = element_type&; using const_reference = const element_type&; @@ -132,17 +131,17 @@ class CheckedContiguousRange { } constexpr pointer data() const noexcept { - return container_ ? base::data(*container_) : nullptr; + return container_ ? std::data(*container_) : nullptr; } constexpr const_pointer cdata() const noexcept { return data(); } constexpr size_type size() const noexcept { - return container_ ? base::size(*container_) : 0; + return container_ ? std::size(*container_) : 0; } constexpr bool empty() const noexcept { - return container_ ? base::empty(*container_) : true; + return container_ ? std::empty(*container_) : true; } private: diff --git a/base/containers/checked_range_unittest.cc b/base/containers/checked_range_unittest.cc index a84496dc8f1b01..4880059df12457 100644 --- a/base/containers/checked_range_unittest.cc +++ b/base/containers/checked_range_unittest.cc @@ -39,15 +39,15 @@ TEST(CheckedContiguousRange, Constructor_String) { TEST(CheckedContiguousRange, Constructor_Array) { static constexpr int array[] = {1, 2, 3, 4, 5}; constexpr CheckedContiguousRange range(array); - static_assert(data(array) == range.data(), ""); - static_assert(size(array) == range.size(), ""); + static_assert(std::data(array) == range.data(), ""); + static_assert(std::size(array) == range.size(), ""); } TEST(CheckedContiguousRange, Constructor_StdArray) { static constexpr std::array array = {1, 2, 3, 4, 5}; constexpr CheckedContiguousRange> range(array); static_assert(data(array) == range.data(), ""); - static_assert(base::size(array) == range.size(), ""); + static_assert(std::size(array) == range.size(), ""); } TEST(CheckedContiguousRange, Constructor_StringPiece) { @@ -60,8 +60,8 @@ TEST(CheckedContiguousRange, Constructor_StringPiece) { TEST(CheckedContiguousRange, Constructor_InitializerList) { static constexpr std::initializer_list il = {1, 2, 3, 4, 5}; constexpr CheckedContiguousRange> range(il); - static_assert(base::data(il) == range.data(), ""); - static_assert(base::size(il) == range.size(), ""); + static_assert(std::data(il) == range.data(), ""); + static_assert(std::size(il) == range.size(), ""); } TEST(CheckedContiguousRange, Constructor_Copy) { @@ -162,7 +162,7 @@ TEST(CheckedContiguousRange, DataSizeEmpty_Constexpr) { constexpr CheckedContiguousRange> range(array); static_assert(data(array) == range.data(), ""); static_assert(data(array) == range.cdata(), ""); - static_assert(base::size(array) == range.size(), ""); + static_assert(std::size(array) == range.size(), ""); static_assert(range.empty(), ""); } diff --git a/base/containers/flat_tree.h b/base/containers/flat_tree.h index 0e6616f71c191d..c1b44327987dc0 100644 --- a/base/containers/flat_tree.h +++ b/base/containers/flat_tree.h @@ -15,7 +15,6 @@ #include "base/as_const.h" #include "base/check.h" #include "base/compiler_specific.h" -#include "base/cxx17_backports.h" #include "base/functional/not_fn.h" #include "base/ranges/algorithm.h" #include "base/template_util.h" @@ -75,14 +74,14 @@ constexpr std::array ToArray(const T (&data)[N]) { return ToArrayImpl(data, std::make_index_sequence()); } -// Helper that calls `container.reserve(base::size(source))`. +// Helper that calls `container.reserve(std::size(source))`. template constexpr void ReserveIfSupported(const T&, const U&) {} template auto ReserveIfSupported(T& container, const U& source) - -> decltype(container.reserve(base::size(source)), void()) { - container.reserve(base::size(source)); + -> decltype(container.reserve(std::size(source)), void()) { + container.reserve(std::size(source)); } // std::pair's operator= is not constexpr prior to C++20. Thus we need this diff --git a/base/containers/intrusive_heap_unittest.cc b/base/containers/intrusive_heap_unittest.cc index cda59df785c786..38f103b53e5e8a 100644 --- a/base/containers/intrusive_heap_unittest.cc +++ b/base/containers/intrusive_heap_unittest.cc @@ -6,7 +6,6 @@ #include "base/callback_helpers.h" #include "base/check_op.h" -#include "base/cxx17_backports.h" #include "base/memory/ptr_util.h" #include "base/notreached.h" #include "base/rand_util.h" @@ -69,7 +68,7 @@ void ExpectCanonical(const IntrusiveHeapInt& heap) { void MakeCanonical(IntrusiveHeapInt* heap) { static constexpr int kInts[] = {CANONICAL_ELEMENTS}; heap->clear(); - heap->insert(kInts, kInts + base::size(kInts)); + heap->insert(kInts, kInts + std::size(kInts)); ExpectCanonical(*heap); } diff --git a/base/containers/linked_list_unittest.cc b/base/containers/linked_list_unittest.cc index bacbca501d83c0..83f5111ab68d32 100644 --- a/base/containers/linked_list_unittest.cc +++ b/base/containers/linked_list_unittest.cc @@ -3,7 +3,7 @@ // found in the LICENSE file. #include "base/containers/linked_list.h" -#include "base/cxx17_backports.h" + #include "base/test/gtest_util.h" #include "testing/gtest/include/gtest/gtest.h" @@ -92,7 +92,7 @@ TEST(LinkedList, Append) { EXPECT_EQ(&n1, list.tail()); { const int expected[] = {1}; - ExpectListContents(list, base::size(expected), expected); + ExpectListContents(list, std::size(expected), expected); } Node n2(2); @@ -102,7 +102,7 @@ TEST(LinkedList, Append) { EXPECT_EQ(&n2, list.tail()); { const int expected[] = {1, 2}; - ExpectListContents(list, base::size(expected), expected); + ExpectListContents(list, std::size(expected), expected); } Node n3(3); @@ -112,7 +112,7 @@ TEST(LinkedList, Append) { EXPECT_EQ(&n3, list.tail()); { const int expected[] = {1, 2, 3}; - ExpectListContents(list, base::size(expected), expected); + ExpectListContents(list, std::size(expected), expected); } } @@ -135,7 +135,7 @@ TEST(LinkedList, RemoveFromList) { EXPECT_EQ(&n5, list.tail()); { const int expected[] = {1, 2, 3, 4, 5}; - ExpectListContents(list, base::size(expected), expected); + ExpectListContents(list, std::size(expected), expected); } // Remove from the middle. @@ -145,7 +145,7 @@ TEST(LinkedList, RemoveFromList) { EXPECT_EQ(&n5, list.tail()); { const int expected[] = {1, 2, 4, 5}; - ExpectListContents(list, base::size(expected), expected); + ExpectListContents(list, std::size(expected), expected); } // Remove from the tail. @@ -155,7 +155,7 @@ TEST(LinkedList, RemoveFromList) { EXPECT_EQ(&n4, list.tail()); { const int expected[] = {1, 2, 4}; - ExpectListContents(list, base::size(expected), expected); + ExpectListContents(list, std::size(expected), expected); } // Remove from the head. @@ -165,7 +165,7 @@ TEST(LinkedList, RemoveFromList) { EXPECT_EQ(&n4, list.tail()); { const int expected[] = {2, 4}; - ExpectListContents(list, base::size(expected), expected); + ExpectListContents(list, std::size(expected), expected); } // Empty the list. @@ -187,7 +187,7 @@ TEST(LinkedList, RemoveFromList) { EXPECT_EQ(&n5, list.tail()); { const int expected[] = {1, 2, 3, 4, 5}; - ExpectListContents(list, base::size(expected), expected); + ExpectListContents(list, std::size(expected), expected); } } @@ -206,7 +206,7 @@ TEST(LinkedList, InsertBefore) { EXPECT_EQ(&n2, list.tail()); { const int expected[] = {1, 2}; - ExpectListContents(list, base::size(expected), expected); + ExpectListContents(list, std::size(expected), expected); } n3.InsertBefore(&n2); @@ -215,7 +215,7 @@ TEST(LinkedList, InsertBefore) { EXPECT_EQ(&n2, list.tail()); { const int expected[] = {1, 3, 2}; - ExpectListContents(list, base::size(expected), expected); + ExpectListContents(list, std::size(expected), expected); } n4.InsertBefore(&n1); @@ -224,7 +224,7 @@ TEST(LinkedList, InsertBefore) { EXPECT_EQ(&n2, list.tail()); { const int expected[] = {4, 1, 3, 2}; - ExpectListContents(list, base::size(expected), expected); + ExpectListContents(list, std::size(expected), expected); } } @@ -243,7 +243,7 @@ TEST(LinkedList, InsertAfter) { EXPECT_EQ(&n2, list.tail()); { const int expected[] = {1, 2}; - ExpectListContents(list, base::size(expected), expected); + ExpectListContents(list, std::size(expected), expected); } n3.InsertAfter(&n2); @@ -252,7 +252,7 @@ TEST(LinkedList, InsertAfter) { EXPECT_EQ(&n3, list.tail()); { const int expected[] = {1, 2, 3}; - ExpectListContents(list, base::size(expected), expected); + ExpectListContents(list, std::size(expected), expected); } n4.InsertAfter(&n1); @@ -261,7 +261,7 @@ TEST(LinkedList, InsertAfter) { EXPECT_EQ(&n3, list.tail()); { const int expected[] = {1, 4, 2, 3}; - ExpectListContents(list, base::size(expected), expected); + ExpectListContents(list, std::size(expected), expected); } } diff --git a/base/containers/span.h b/base/containers/span.h index 3694913a8a9b03..3906e0d678b04e 100644 --- a/base/containers/span.h +++ b/base/containers/span.h @@ -18,7 +18,6 @@ #include "base/compiler_specific.h" #include "base/containers/checked_iterators.h" #include "base/containers/contiguous_iterator.h" -#include "base/cxx17_backports.h" #include "base/cxx20_to_address.h" #include "base/template_util.h" @@ -85,12 +84,12 @@ using EnableIfCompatibleContiguousIterator = std::enable_if_t< template using ContainerHasConvertibleData = IsLegalDataConversion< - std::remove_pointer_t()))>, + std::remove_pointer_t()))>, T>; template using ContainerHasIntegralSize = - std::is_integral()))>; + std::is_integral()))>; template using EnableIfLegalSpanConversion = @@ -297,7 +296,7 @@ class GSL_POINTER span : public internal::ExtentStorage { template < size_t N, typename = internal::EnableIfSpanCompatibleArray> - constexpr span(T (&array)[N]) noexcept : span(base::data(array), N) {} + constexpr span(T (&array)[N]) noexcept : span(std::data(array), N) {} template < typename U, @@ -305,17 +304,17 @@ class GSL_POINTER span : public internal::ExtentStorage { typename = internal::EnableIfSpanCompatibleArray&, T, Extent>> constexpr span(std::array& array) noexcept - : span(base::data(array), N) {} + : span(std::data(array), N) {} template &, T, Extent>> constexpr span(const std::array& array) noexcept - : span(base::data(array), N) {} + : span(std::data(array), N) {} - // Conversion from a container that has compatible base::data() and integral - // base::size(). + // Conversion from a container that has compatible std::data() and integral + // std::size(). template < typename Container, typename = @@ -323,7 +322,7 @@ class GSL_POINTER span : public internal::ExtentStorage { T, Extent>> constexpr span(Container& container) noexcept - : span(base::data(container), base::size(container)) {} + : span(std::data(container), std::size(container)) {} template < typename Container, @@ -332,7 +331,7 @@ class GSL_POINTER span : public internal::ExtentStorage { T, Extent>> constexpr span(const Container& container) noexcept - : span(base::data(container), base::size(container)) {} + : span(std::data(container), std::size(container)) {} constexpr span(const span& other) noexcept = default; @@ -485,7 +484,7 @@ constexpr auto make_span(It it, EndOrSize end_or_size) noexcept { template constexpr auto make_span(Container&& container) noexcept { using T = - std::remove_pointer_t()))>; + std::remove_pointer_t()))>; using Extent = internal::Extent; return span(std::forward(container)); } @@ -510,8 +509,8 @@ constexpr auto make_span(It it, EndOrSize end_or_size) noexcept { template constexpr auto make_span(Container&& container) noexcept { using T = - std::remove_pointer_t()))>; - return span(base::data(container), base::size(container)); + std::remove_pointer_t()))>; + return span(std::data(container), std::size(container)); } } // namespace base @@ -520,7 +519,7 @@ constexpr auto make_span(Container&& container) noexcept { // with definite extent, i.e. everything that is a contiguous storage of some // sort with static size. Specifically, this works for std::array in a constexpr // context. Note: -// * |base::size| should be preferred for plain arrays. +// * |std::size| should be preferred for plain arrays. // * In run-time contexts, functions such as |std::array::size| should be // preferred. #define EXTENT(x) \ diff --git a/base/containers/span_unittest.cc b/base/containers/span_unittest.cc index 28306e04eef4fd..6dfb4f9eac2fea 100644 --- a/base/containers/span_unittest.cc +++ b/base/containers/span_unittest.cc @@ -230,7 +230,7 @@ TEST(SpanTest, ConstructFromConstexprArray) { constexpr span dynamic_span(kArray); static_assert(kArray == dynamic_span.data(), ""); - static_assert(base::size(kArray) == dynamic_span.size(), ""); + static_assert(std::size(kArray) == dynamic_span.size(), ""); static_assert(kArray[0] == dynamic_span[0], ""); static_assert(kArray[1] == dynamic_span[1], ""); @@ -238,9 +238,9 @@ TEST(SpanTest, ConstructFromConstexprArray) { static_assert(kArray[3] == dynamic_span[3], ""); static_assert(kArray[4] == dynamic_span[4], ""); - constexpr span static_span(kArray); + constexpr span static_span(kArray); static_assert(kArray == static_span.data(), ""); - static_assert(base::size(kArray) == static_span.size(), ""); + static_assert(std::size(kArray) == static_span.size(), ""); static_assert(kArray[0] == static_span[0], ""); static_assert(kArray[1] == static_span[1], ""); @@ -254,19 +254,19 @@ TEST(SpanTest, ConstructFromArray) { span const_span(array); EXPECT_EQ(array, const_span.data()); - EXPECT_EQ(base::size(array), const_span.size()); + EXPECT_EQ(std::size(array), const_span.size()); for (size_t i = 0; i < const_span.size(); ++i) EXPECT_EQ(array[i], const_span[i]); span dynamic_span(array); EXPECT_EQ(array, dynamic_span.data()); - EXPECT_EQ(base::size(array), dynamic_span.size()); + EXPECT_EQ(std::size(array), dynamic_span.size()); for (size_t i = 0; i < dynamic_span.size(); ++i) EXPECT_EQ(array[i], dynamic_span[i]); - span static_span(array); + span static_span(array); EXPECT_EQ(array, static_span.data()); - EXPECT_EQ(base::size(array), static_span.size()); + EXPECT_EQ(std::size(array), static_span.size()); for (size_t i = 0; i < static_span.size(); ++i) EXPECT_EQ(array[i], static_span[i]); } @@ -288,7 +288,7 @@ TEST(SpanTest, ConstructFromStdArray) { for (size_t i = 0; i < dynamic_span.size(); ++i) EXPECT_EQ(array[i], dynamic_span[i]); - span static_span(array); + span static_span(array); EXPECT_EQ(array.data(), static_span.data()); EXPECT_EQ(array.size(), static_span.size()); for (size_t i = 0; i < static_span.size(); ++i) @@ -1342,7 +1342,7 @@ TEST(SpanTest, EnsureConstexprGoodness) { constexpr span lasts = constexpr_span.last(size); for (size_t i = 0; i < lasts.size(); ++i) { - const size_t j = (base::size(kArray) - size) + i; + const size_t j = (std::size(kArray) - size) + i; EXPECT_EQ(kArray[j], lasts[i]); } diff --git a/base/cpu.cc b/base/cpu.cc index 54ce0bf70c7457..17c201bc50eb29 100644 --- a/base/cpu.cc +++ b/base/cpu.cc @@ -14,7 +14,6 @@ #include #include -#include "base/cxx17_backports.h" #include "base/no_destructor.h" #include "build/build_config.h" @@ -244,7 +243,7 @@ void CPU::Initialize(bool require_branding) { int num_ids = cpu_info[0]; std::swap(cpu_info[2], cpu_info[3]); static constexpr size_t kVendorNameSize = 3 * sizeof(cpu_info[1]); - static_assert(kVendorNameSize < base::size(cpu_string), + static_assert(kVendorNameSize < std::size(cpu_string), "cpu_string too small"); memcpy(cpu_string, &cpu_info[1], kVendorNameSize); cpu_string[kVendorNameSize] = '\0'; @@ -309,7 +308,7 @@ void CPU::Initialize(bool require_branding) { static constexpr int kParameterStart = 0x80000002; static constexpr int kParameterEnd = 0x80000004; static constexpr int kParameterSize = kParameterEnd - kParameterStart + 1; - static_assert(kParameterSize * sizeof(cpu_info) + 1 == base::size(cpu_string), + static_assert(kParameterSize * sizeof(cpu_info) + 1 == std::size(cpu_string), "cpu_string has wrong size"); if (max_parameter >= kParameterEnd) { diff --git a/base/cxx17_backports_unittest.cc b/base/cxx17_backports_unittest.cc index 1080aaea77bff7..5a788bb347830b 100644 --- a/base/cxx17_backports_unittest.cc +++ b/base/cxx17_backports_unittest.cc @@ -22,36 +22,35 @@ TEST(Cxx17BackportTest, Size) { { std::vector vector = {1, 2, 3, 4, 5}; static_assert( - std::is_same::value, - "base::size(vector) should have the same type as vector.size()"); - EXPECT_EQ(vector.size(), base::size(vector)); + "std::size(vector) should have the same type as vector.size()"); + EXPECT_EQ(vector.size(), std::size(vector)); } { std::string empty_str; static_assert( - std::is_same::value, - "base::size(empty_str) should have the same type as empty_str.size()"); - EXPECT_EQ(0u, base::size(empty_str)); + "std::size(empty_str) should have the same type as empty_str.size()"); + EXPECT_EQ(0u, std::size(empty_str)); } { std::array array = {{1, 2, 3, 4}}; static_assert( - std::is_same::value, - "base::size(array) should have the same type as array.size()"); - static_assert(base::size(array) == array.size(), - "base::size(array) should be equal to array.size()"); + std::is_same::value, + "std::size(array) should have the same type as array.size()"); + static_assert(std::size(array) == array.size(), + "std::size(array) should be equal to array.size()"); } { int array[] = {1, 2, 3}; - static_assert(std::is_same::value, - "base::size(array) should be of type size_t"); - static_assert(3u == base::size(array), "base::size(array) should be 3"); + static_assert(std::is_same::value, + "std::size(array) should be of type size_t"); + static_assert(3u == std::size(array), "std::size(array) should be 3"); } } @@ -59,34 +58,34 @@ TEST(Cxx17BackportTest, Empty) { { std::vector vector; static_assert( - std::is_same::value, - "base::empty(vector) should have the same type as vector.empty()"); - EXPECT_EQ(vector.empty(), base::empty(vector)); + "std::empty(vector) should have the same type as vector.empty()"); + EXPECT_EQ(vector.empty(), std::empty(vector)); } { std::array array = {{1, 2, 3, 4}}; static_assert( - std::is_same::value, - "base::empty(array) should have the same type as array.empty()"); - static_assert(base::empty(array) == array.empty(), - "base::empty(array) should be equal to array.empty()"); + "std::empty(array) should have the same type as array.empty()"); + static_assert(std::empty(array) == array.empty(), + "std::empty(array) should be equal to array.empty()"); } { int array[] = {1, 2, 3}; - static_assert(std::is_same::value, - "base::empty(array) should be of type bool"); - static_assert(!base::empty(array), "base::empty(array) should be false"); + static_assert(std::is_same::value, + "std::empty(array) should be of type bool"); + static_assert(!std::empty(array), "std::empty(array) should be false"); } { constexpr std::initializer_list il; - static_assert(std::is_same::value, - "base::empty(il) should be of type bool"); - static_assert(base::empty(il), "base::empty(il) should be true"); + static_assert(std::is_same::value, + "std::empty(il) should be of type bool"); + static_assert(std::empty(il), "std::empty(il) should be true"); } } @@ -94,61 +93,60 @@ TEST(Cxx17BackportTest, Data) { { std::vector vector = {1, 2, 3, 4, 5}; static_assert( - std::is_same::value, - "base::data(vector) should have the same type as vector.data()"); - EXPECT_EQ(vector.data(), base::data(vector)); + "std::data(vector) should have the same type as vector.data()"); + EXPECT_EQ(vector.data(), std::data(vector)); } { const std::string cstr = "const string"; static_assert( - std::is_same::value, - "base::data(cstr) should have the same type as cstr.data()"); + std::is_same::value, + "std::data(cstr) should have the same type as cstr.data()"); - EXPECT_EQ(cstr.data(), base::data(cstr)); + EXPECT_EQ(cstr.data(), std::data(cstr)); } { std::string str = "mutable string"; - static_assert(std::is_same::value, - "base::data(str) should be of type char*"); - EXPECT_EQ(str.data(), base::data(str)); + static_assert(std::is_same::value, + "std::data(str) should be of type char*"); + EXPECT_EQ(str.data(), std::data(str)); } { std::string empty_str; - static_assert(std::is_same::value, - "base::data(empty_str) should be of type char*"); - EXPECT_EQ(empty_str.data(), base::data(empty_str)); + static_assert(std::is_same::value, + "std::data(empty_str) should be of type char*"); + EXPECT_EQ(empty_str.data(), std::data(empty_str)); } { std::array array = {{1, 2, 3, 4}}; static_assert( - std::is_same::value, - "base::data(array) should have the same type as array.data()"); + std::is_same::value, + "std::data(array) should have the same type as array.data()"); // std::array::data() is not constexpr prior to C++17, hence the runtime // check. - EXPECT_EQ(array.data(), base::data(array)); + EXPECT_EQ(array.data(), std::data(array)); } { constexpr int array[] = {1, 2, 3}; - static_assert(std::is_same::value, - "base::data(array) should be of type const int*"); - static_assert(array == base::data(array), - "base::data(array) should be array"); + static_assert(std::is_same::value, + "std::data(array) should be of type const int*"); + static_assert(array == std::data(array), + "std::data(array) should be array"); } { constexpr std::initializer_list il; static_assert( - std::is_same::value, - "base::data(il) should have the same type as il.begin()"); - static_assert(il.begin() == base::data(il), - "base::data(il) should be equal to il.begin()"); + std::is_same::value, + "std::data(il) should have the same type as il.begin()"); + static_assert(il.begin() == std::data(il), + "std::data(il) should be equal to il.begin()"); } } diff --git a/base/debug/crash_logging.h b/base/debug/crash_logging.h index ae98753f8c7f14..c308e22e146f51 100644 --- a/base/debug/crash_logging.h +++ b/base/debug/crash_logging.h @@ -12,7 +12,6 @@ #include #include "base/base_export.h" -#include "base/cxx17_backports.h" #include "base/memory/raw_ptr.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_piece.h" @@ -125,7 +124,7 @@ class BASE_EXPORT ScopedCrashKeyString { // that restricts the name of a crash key to 40 characters. #define SCOPED_CRASH_KEY_STRING_INTERNAL2(category, name, nonce, data, \ key_size) \ - static_assert(::base::size(category "-" name) < 40, \ + static_assert(::std::size(category "-" name) < 40, \ "Crash key names must be shorter than 40 characters."); \ ::base::debug::ScopedCrashKeyString scoped_crash_key_helper##nonce( \ [] { \ diff --git a/base/debug/debugger_posix.cc b/base/debug/debugger_posix.cc index ca6a9d315a3586..ef5e47ada36185 100644 --- a/base/debug/debugger_posix.cc +++ b/base/debug/debugger_posix.cc @@ -17,7 +17,6 @@ #include #include "base/check_op.h" -#include "base/cxx17_backports.h" #include "base/notreached.h" #include "base/strings/string_util.h" #include "base/threading/platform_thread.h" @@ -100,13 +99,13 @@ bool BeingDebugged() { size_t info_size = sizeof(info); #if BUILDFLAG(IS_OPENBSD) - if (sysctl(mib, base::size(mib), NULL, &info_size, NULL, 0) < 0) + if (sysctl(mib, std::size(mib), NULL, &info_size, NULL, 0) < 0) return -1; mib[5] = (info_size / sizeof(struct kinfo_proc)); #endif - int sysctl_result = sysctl(mib, base::size(mib), &info, &info_size, NULL, 0); + int sysctl_result = sysctl(mib, std::size(mib), &info, &info_size, NULL, 0); DCHECK_EQ(sysctl_result, 0); if (sysctl_result != 0) { is_set = true; diff --git a/base/debug/proc_maps_linux_unittest.cc b/base/debug/proc_maps_linux_unittest.cc index ba190689d6559f..56d3106d9fded4 100644 --- a/base/debug/proc_maps_linux_unittest.cc +++ b/base/debug/proc_maps_linux_unittest.cc @@ -2,11 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/debug/proc_maps_linux.h" + #include #include -#include "base/cxx17_backports.h" -#include "base/debug/proc_maps_linux.h" #include "base/files/file_path.h" #include "base/path_service.h" #include "base/strings/stringprintf.h" @@ -172,7 +172,7 @@ TEST(ProcMapsTest, Permissions) { MappedMemoryRegion::EXECUTE | MappedMemoryRegion::PRIVATE}, }; - for (size_t i = 0; i < base::size(kTestCases); ++i) { + for (size_t i = 0; i < std::size(kTestCases); ++i) { SCOPED_TRACE( base::StringPrintf("kTestCases[%zu] = %s", i, kTestCases[i].input)); @@ -269,7 +269,7 @@ TEST(ProcMapsTest, MissingFields) { "00400000-0040b000 r-xp 00000000 794418 /bin/cat\n", // Missing device. }; - for (size_t i = 0; i < base::size(kTestCases); ++i) { + for (size_t i = 0; i < std::size(kTestCases); ++i) { SCOPED_TRACE(base::StringPrintf("kTestCases[%zu] = %s", i, kTestCases[i])); std::vector regions; EXPECT_FALSE(ParseProcMaps(kTestCases[i], ®ions)); @@ -286,7 +286,7 @@ TEST(ProcMapsTest, InvalidInput) { "00400000-0040b000 rwxp 00000000 fc:00 parse! /bin/cat\n", }; - for (size_t i = 0; i < base::size(kTestCases); ++i) { + for (size_t i = 0; i < std::size(kTestCases); ++i) { SCOPED_TRACE(base::StringPrintf("kTestCases[%zu] = %s", i, kTestCases[i])); std::vector regions; EXPECT_FALSE(ParseProcMaps(kTestCases[i], ®ions)); diff --git a/base/debug/stack_trace.cc b/base/debug/stack_trace.cc index 50abca1bf1a937..6a5bb4b40e60d8 100644 --- a/base/debug/stack_trace.cc +++ b/base/debug/stack_trace.cc @@ -10,7 +10,6 @@ #include #include "base/check_op.h" -#include "base/cxx17_backports.h" #include "build/build_config.h" #include "build/config/compiler/compiler_buildflags.h" @@ -216,14 +215,14 @@ uintptr_t GetStackEnd() { } #endif // BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS) -StackTrace::StackTrace() : StackTrace(base::size(trace_)) {} +StackTrace::StackTrace() : StackTrace(std::size(trace_)) {} StackTrace::StackTrace(size_t count) { - count_ = CollectStackTrace(trace_, std::min(count, base::size(trace_))); + count_ = CollectStackTrace(trace_, std::min(count, std::size(trace_))); } StackTrace::StackTrace(const void* const* trace, size_t count) { - count = std::min(count, base::size(trace_)); + count = std::min(count, std::size(trace_)); if (count) memcpy(trace_, trace, count * sizeof(trace_[0])); count_ = count; diff --git a/base/debug/stack_trace_fuchsia.cc b/base/debug/stack_trace_fuchsia.cc index a2ad5404984442..384018794869e3 100644 --- a/base/debug/stack_trace_fuchsia.cc +++ b/base/debug/stack_trace_fuchsia.cc @@ -21,7 +21,6 @@ #include #include "base/atomic_sequence_num.h" -#include "base/cxx17_backports.h" #include "base/debug/elf_reader.h" #include "base/logging.h" @@ -132,7 +131,7 @@ void SymbolMap::Populate() { // The process name may have a process type suffix at the end (e.g. // "context", "renderer", gpu"), which doesn't belong in the module list. // Trim the suffix from the name. - for (size_t i = 0; i < base::size(app_name) && app_name[i] != '\0'; ++i) { + for (size_t i = 0; i < std::size(app_name) && app_name[i] != '\0'; ++i) { if (app_name[i] == ':') { app_name[i] = 0; break; diff --git a/base/debug/stack_trace_posix.cc b/base/debug/stack_trace_posix.cc index b558155df0af85..31b8a4ca61972a 100644 --- a/base/debug/stack_trace_posix.cc +++ b/base/debug/stack_trace_posix.cc @@ -430,7 +430,7 @@ void StackDumpSignalHandler(int signal, siginfo_t* info, void* void_context) { const int kRegisterPadding = 16; #endif - for (size_t i = 0; i < base::size(registers); i++) { + for (size_t i = 0; i < std::size(registers); i++) { PrintToStderr(registers[i].label); internal::itoa_r(registers[i].value, buf, sizeof(buf), 16, kRegisterPadding); diff --git a/base/feature_list_unittest.cc b/base/feature_list_unittest.cc index 5cddec58385057..052875b2672dc0 100644 --- a/base/feature_list_unittest.cc +++ b/base/feature_list_unittest.cc @@ -9,7 +9,6 @@ #include #include -#include "base/cxx17_backports.h" #include "base/feature_list_buildflags.h" #include "base/format_macros.h" #include "base/memory/read_only_shared_memory_region.h" @@ -82,7 +81,7 @@ TEST_F(FeatureListTest, InitializeFromCommandLine) { {"OnByDefault", "OnByDefault,OffByDefault", false, false}, }; - for (size_t i = 0; i < base::size(test_cases); ++i) { + for (size_t i = 0; i < std::size(test_cases); ++i) { const auto& test_case = test_cases[i]; SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: [%s] [%s]", i, test_case.enable_features, @@ -173,7 +172,7 @@ TEST_F(FeatureListTest, FieldTrialOverrides) { }; FieldTrial::ActiveGroup active_group; - for (size_t i = 0; i < base::size(test_cases); ++i) { + for (size_t i = 0; i < std::size(test_cases); ++i) { const auto& test_case = test_cases[i]; SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]", i)); @@ -391,7 +390,7 @@ TEST_F(FeatureListTest, AssociateReportingFieldTrial) { const char kForcedOnGroupName[] = "ForcedOn"; const char kForcedOffGroupName[] = "ForcedOff"; - for (size_t i = 0; i < base::size(test_cases); ++i) { + for (size_t i = 0; i < std::size(test_cases); ++i) { const auto& test_case = test_cases[i]; SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: [%s] [%s]", i, test_case.enable_features, @@ -727,7 +726,7 @@ TEST(FeatureListAccessorTest, InitializeFromCommandLine) { FeatureList::OVERRIDE_DISABLE_FEATURE}, }; - for (size_t i = 0; i < base::size(test_cases); ++i) { + for (size_t i = 0; i < std::size(test_cases); ++i) { const auto& test_case = test_cases[i]; SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: [%s] [%s]", i, test_case.enable_features, diff --git a/base/files/file_path.h b/base/files/file_path.h index 2ef1c223eb31ca..b75dc08bfc5864 100644 --- a/base/files/file_path.h +++ b/base/files/file_path.h @@ -169,7 +169,7 @@ class BASE_EXPORT FilePath { // when composing pathnames. static const CharType kSeparators[]; - // base::size(kSeparators). + // std::size(kSeparators). static const size_t kSeparatorsLength; // A special path component meaning "this directory." diff --git a/base/files/file_path_constants.cc b/base/files/file_path_constants.cc index 8794f12a4e50e0..dcf3316d449a26 100644 --- a/base/files/file_path_constants.cc +++ b/base/files/file_path_constants.cc @@ -4,7 +4,6 @@ #include -#include "base/cxx17_backports.h" #include "base/files/file_path.h" namespace base { @@ -15,7 +14,7 @@ const FilePath::CharType FilePath::kSeparators[] = FILE_PATH_LITERAL("\\/"); const FilePath::CharType FilePath::kSeparators[] = FILE_PATH_LITERAL("/"); #endif // FILE_PATH_USES_WIN_SEPARATORS -const size_t FilePath::kSeparatorsLength = base::size(kSeparators); +const size_t FilePath::kSeparatorsLength = std::size(kSeparators); const FilePath::CharType FilePath::kCurrentDirectory[] = FILE_PATH_LITERAL("."); const FilePath::CharType FilePath::kParentDirectory[] = FILE_PATH_LITERAL(".."); diff --git a/base/files/file_path_unittest.cc b/base/files/file_path_unittest.cc index 6e2fcdf5bbecc1..49433d78342b91 100644 --- a/base/files/file_path_unittest.cc +++ b/base/files/file_path_unittest.cc @@ -2,12 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/files/file_path.h" + #include #include -#include "base/cxx17_backports.h" -#include "base/files/file_path.h" #include "base/files/safe_base_name.h" #include "base/strings/utf_string_conversions.h" #include "build/build_config.h" @@ -27,7 +27,7 @@ #define FPL(x) FILE_PATH_LITERAL(x) // This macro constructs strings which can contain NULs. -#define FPS(x) FilePath::StringType(FPL(x), base::size(FPL(x)) - 1) +#define FPS(x) FilePath::StringType(FPL(x), std::size(FPL(x)) - 1) namespace base { @@ -148,7 +148,7 @@ TEST_F(FilePathTest, DirName) { #endif // FILE_PATH_USES_WIN_SEPARATORS }; - for (size_t i = 0; i < base::size(cases); ++i) { + for (size_t i = 0; i < std::size(cases); ++i) { FilePath input(cases[i].input); FilePath observed = input.DirName(); EXPECT_EQ(FilePath::StringType(cases[i].expected), observed.value()) << @@ -235,7 +235,7 @@ TEST_F(FilePathTest, BaseName) { #endif // FILE_PATH_USES_WIN_SEPARATORS }; - for (size_t i = 0; i < base::size(cases); ++i) { + for (size_t i = 0; i < std::size(cases); ++i) { FilePath input(cases[i].input); FilePath observed = input.BaseName(); EXPECT_EQ(FilePath::StringType(cases[i].expected), observed.value()) << @@ -313,7 +313,7 @@ TEST_F(FilePathTest, Append) { #endif // FILE_PATH_USES_WIN_SEPARATORS }; - for (size_t i = 0; i < base::size(cases); ++i) { + for (size_t i = 0; i < std::size(cases); ++i) { FilePath root(cases[i].inputs[0]); FilePath::StringType leaf(cases[i].inputs[1]); FilePath observed_str = root.Append(leaf); @@ -392,7 +392,7 @@ TEST_F(FilePathTest, StripTrailingSeparators) { #endif // FILE_PATH_USES_WIN_SEPARATORS }; - for (size_t i = 0; i < base::size(cases); ++i) { + for (size_t i = 0; i < std::size(cases); ++i) { FilePath input(cases[i].input); FilePath observed = input.StripTrailingSeparators(); EXPECT_EQ(FilePath::StringType(cases[i].expected), observed.value()) << @@ -464,7 +464,7 @@ TEST_F(FilePathTest, IsAbsoluteOrNetwork) { #endif // FILE_PATH_USES_WIN_SEPARATORS }; - for (size_t i = 0; i < base::size(cases); ++i) { + for (size_t i = 0; i < std::size(cases); ++i) { FilePath input(cases[i].input); bool observed_is_absolute = input.IsAbsolute(); EXPECT_EQ(cases[i].expected_is_absolute, observed_is_absolute) << @@ -513,7 +513,7 @@ TEST_F(FilePathTest, PathComponentsTest) { #endif // FILE_PATH_USES_WIN_SEPARATORS }; - for (size_t i = 0; i < base::size(cases); ++i) { + for (size_t i = 0; i < std::size(cases); ++i) { FilePath input(cases[i].input); std::vector comps = input.GetComponents(); @@ -571,7 +571,7 @@ TEST_F(FilePathTest, IsParentTest) { #endif // FILE_PATH_USES_WIN_SEPARATORS }; - for (size_t i = 0; i < base::size(cases); ++i) { + for (size_t i = 0; i < std::size(cases); ++i) { FilePath parent(cases[i].inputs[0]); FilePath child(cases[i].inputs[1]); @@ -653,7 +653,7 @@ TEST_F(FilePathTest, AppendRelativePathTest) { const FilePath base(FPL("blah")); - for (size_t i = 0; i < base::size(cases); ++i) { + for (size_t i = 0; i < std::size(cases); ++i) { FilePath parent(cases[i].inputs[0]); FilePath child(cases[i].inputs[1]); { @@ -720,7 +720,7 @@ TEST_F(FilePathTest, EqualityTest) { #endif // FILE_PATH_USES_WIN_SEPARATORS }; - for (size_t i = 0; i < base::size(cases); ++i) { + for (size_t i = 0; i < std::size(cases); ++i) { FilePath a(cases[i].inputs[0]); FilePath b(cases[i].inputs[1]); @@ -729,7 +729,7 @@ TEST_F(FilePathTest, EqualityTest) { b.value(); } - for (size_t i = 0; i < base::size(cases); ++i) { + for (size_t i = 0; i < std::size(cases); ++i) { FilePath a(cases[i].inputs[0]); FilePath b(cases[i].inputs[1]); @@ -817,7 +817,7 @@ TEST_F(FilePathTest, Extension2) { }; // clang-format on - for (size_t i = 0; i < base::size(cases); ++i) { + for (size_t i = 0; i < std::size(cases); ++i) { FilePath path(cases[i].input); FilePath::StringType extension = path.Extension(); FilePath::StringType final_extension = path.FinalExtension(); @@ -827,7 +827,7 @@ TEST_F(FilePathTest, Extension2) { << "i: " << i << ", path: " << path.value(); } - for (size_t i = 0; i < base::size(double_extension_cases); ++i) { + for (size_t i = 0; i < std::size(double_extension_cases); ++i) { FilePath path(double_extension_cases[i].input); FilePath::StringType extension = path.Extension(); EXPECT_EQ(double_extension_cases[i].expected, extension) @@ -895,7 +895,7 @@ TEST_F(FilePathTest, InsertBeforeExtension) { { { FPL("/bar/baz/foo.exe"), FPL(" (1)") }, FPL("/bar/baz/foo (1).exe") }, { { FPL("/bar/baz/..////"), FPL(" (1)") }, FPL("") }, }; - for (unsigned int i = 0; i < base::size(cases); ++i) { + for (unsigned int i = 0; i < std::size(cases); ++i) { FilePath path(cases[i].inputs[0]); FilePath result = path.InsertBeforeExtension(cases[i].inputs[1]); EXPECT_EQ(cases[i].expected, result.value()) @@ -923,7 +923,7 @@ TEST_F(FilePathTest, RemoveExtension) { { FPL("/foo.bar/foo"), FPL("/foo.bar/foo") }, { FPL("/foo.bar/..////"), FPL("/foo.bar/..////") }, }; - for (size_t i = 0; i < base::size(cases); ++i) { + for (size_t i = 0; i < std::size(cases); ++i) { FilePath path(cases[i].input); FilePath removed = path.RemoveExtension(); FilePath removed_final = path.RemoveFinalExtension(); @@ -936,7 +936,7 @@ TEST_F(FilePathTest, RemoveExtension) { const FilePath::StringPieceType tarballs[] = { FPL("foo.tar.gz"), FPL("foo.tar.xz"), FPL("foo.tar.bz2"), FPL("foo.tar.Z"), FPL("foo.tar.bz")}; - for (size_t i = 0; i < base::size(tarballs); ++i) { + for (size_t i = 0; i < std::size(tarballs); ++i) { FilePath path(FPL("foo.tar.gz")); FilePath removed = path.RemoveExtension(); FilePath removed_final = path.RemoveFinalExtension(); @@ -977,7 +977,7 @@ TEST_F(FilePathTest, ReplaceExtension) { { { FPL("/foo.bar/foo"), FPL("baz") }, FPL("/foo.bar/foo.baz") }, { { FPL("/foo.bar/..////"), FPL("baz") }, FPL("") }, }; - for (unsigned int i = 0; i < base::size(cases); ++i) { + for (unsigned int i = 0; i < std::size(cases); ++i) { FilePath path(cases[i].inputs[0]); FilePath replaced = path.ReplaceExtension(cases[i].inputs[1]); EXPECT_EQ(cases[i].expected, replaced.value()) << "i: " << i << @@ -1015,7 +1015,7 @@ TEST_F(FilePathTest, AddExtension) { { { FPL("/foo.bar/foo"), FPL("baz") }, FPL("/foo.bar/foo.baz") }, { { FPL("/foo.bar/..////"), FPL("baz") }, FPL("") }, }; - for (unsigned int i = 0; i < base::size(cases); ++i) { + for (unsigned int i = 0; i < std::size(cases); ++i) { FilePath path(cases[i].inputs[0]); FilePath added = path.AddExtension(cases[i].inputs[1]); EXPECT_EQ(cases[i].expected, added.value()) << "i: " << i << @@ -1061,7 +1061,7 @@ TEST_F(FilePathTest, MatchesExtension) { #endif }; - for (size_t i = 0; i < base::size(cases); ++i) { + for (size_t i = 0; i < std::size(cases); ++i) { FilePath path(cases[i].inputs[0]); FilePath::StringType ext(cases[i].inputs[1]); @@ -1110,7 +1110,7 @@ TEST_F(FilePathTest, MatchesFinalExtension) { #endif }; - for (size_t i = 0; i < base::size(cases); ++i) { + for (size_t i = 0; i < std::size(cases); ++i) { FilePath path(cases[i].inputs[0]); FilePath::StringType ext(cases[i].inputs[1]); @@ -1187,7 +1187,7 @@ TEST_F(FilePathTest, CompareIgnoreCase) { #endif }; - for (size_t i = 0; i < base::size(cases); ++i) { + for (size_t i = 0; i < std::size(cases); ++i) { FilePath::StringType s1(cases[i].inputs[0]); FilePath::StringType s2(cases[i].inputs[1]); int result = FilePath::CompareIgnoreCase(s1, s2); @@ -1222,7 +1222,7 @@ TEST_F(FilePathTest, ReferencesParent) { { FPL("a/b/c"), false }, }; - for (size_t i = 0; i < base::size(cases); ++i) { + for (size_t i = 0; i < std::size(cases); ++i) { FilePath input(cases[i].input); bool observed = input.ReferencesParent(); EXPECT_EQ(cases[i].expected, observed) << @@ -1236,7 +1236,7 @@ TEST_F(FilePathTest, FromASCII) { {FPL("!#$%&'()"), "!#$%&'()"}, }; - for (size_t i = 0; i < base::size(cases); ++i) { + for (size_t i = 0; i < std::size(cases); ++i) { FilePath from_ascii = FilePath::FromASCII(cases[i].utf8); EXPECT_EQ(FilePath::StringType(cases[i].native), from_ascii.value()) << "i: " << i << ", input: " << cases[i].utf8; @@ -1258,7 +1258,7 @@ TEST_F(FilePathTest, FromUTF8Unsafe_And_AsUTF8Unsafe) { ScopedLocale locale("en_US.UTF-8"); #endif - for (size_t i = 0; i < base::size(cases); ++i) { + for (size_t i = 0; i < std::size(cases); ++i) { // Test FromUTF8Unsafe() works. FilePath from_utf8 = FilePath::FromUTF8Unsafe(cases[i].utf8); EXPECT_EQ(cases[i].native, from_utf8.value()) @@ -1353,7 +1353,7 @@ TEST_F(FilePathTest, NormalizePathSeparators) { { FPL("foo/\\bar/\\"), FPL("foo\\\\bar\\\\") }, { FPL("/\\foo\\/bar"), FPL("\\\\foo\\\\bar") }, }; - for (size_t i = 0; i < base::size(cases); ++i) { + for (size_t i = 0; i < std::size(cases); ++i) { FilePath input(cases[i].input); FilePath observed = input.NormalizePathSeparators(); EXPECT_EQ(FilePath::StringType(cases[i].expected), observed.value()) << @@ -1410,7 +1410,7 @@ TEST_F(FilePathTest, ContentUriTest) { { FPL("content%2a%2f%2f"), false }, }; - for (size_t i = 0; i < base::size(cases); ++i) { + for (size_t i = 0; i < std::size(cases); ++i) { FilePath input(cases[i].input); bool observed = input.IsContentUri(); EXPECT_EQ(cases[i].expected, observed) << diff --git a/base/files/file_path_watcher_fsevents.cc b/base/files/file_path_watcher_fsevents.cc index 2ff9af04fbe706..689e5c2886dbf5 100644 --- a/base/files/file_path_watcher_fsevents.cc +++ b/base/files/file_path_watcher_fsevents.cc @@ -11,7 +11,6 @@ #include "base/bind.h" #include "base/check.h" -#include "base/cxx17_backports.h" #include "base/files/file_util.h" #include "base/lazy_instance.h" #include "base/mac/scoped_cftyperef.h" @@ -222,7 +221,7 @@ void FilePathWatcherFSEvents::UpdateEventStream( CFStringRef paths_array[] = { cf_path.get(), cf_dir_path.get() }; ScopedCFTypeRef watched_paths( CFArrayCreate(NULL, reinterpret_cast(paths_array), - base::size(paths_array), &kCFTypeArrayCallBacks)); + std::size(paths_array), &kCFTypeArrayCallBacks)); FSEventStreamContext context; context.version = 0; diff --git a/base/files/file_proxy_unittest.cc b/base/files/file_proxy_unittest.cc index 1323e4f22e5bee..c9c8019a8607da 100644 --- a/base/files/file_proxy_unittest.cc +++ b/base/files/file_proxy_unittest.cc @@ -10,7 +10,6 @@ #include #include "base/bind.h" -#include "base/cxx17_backports.h" #include "base/files/file.h" #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" @@ -301,7 +300,7 @@ TEST_F(FileProxyTest, GetInfo) { TEST_F(FileProxyTest, Read) { // Setup. const char expected_data[] = "bleh"; - int expected_bytes = base::size(expected_data); + int expected_bytes = std::size(expected_data); ASSERT_EQ(expected_bytes, base::WriteFile(TestPath(), expected_data, expected_bytes)); @@ -328,7 +327,7 @@ TEST_F(FileProxyTest, WriteAndFlush) { CreateProxy(File::FLAG_CREATE | File::FLAG_WRITE, &proxy); const char data[] = "foo!"; - int data_bytes = base::size(data); + int data_bytes = std::size(data); { RunLoop run_loop; proxy.Write(0, data, data_bytes, diff --git a/base/files/file_util_posix.cc b/base/files/file_util_posix.cc index 6663259b56af4d..c814cebed71354 100644 --- a/base/files/file_util_posix.cc +++ b/base/files/file_util_posix.cc @@ -25,7 +25,6 @@ #include "base/command_line.h" #include "base/containers/contains.h" #include "base/containers/stack.h" -#include "base/cxx17_backports.h" #include "base/environment.h" #include "base/files/file_enumerator.h" #include "base/files/file_path.h" @@ -490,8 +489,7 @@ bool ReadSymbolicLink(const FilePath& symlink_path, FilePath* target_path) { DCHECK(!symlink_path.empty()); DCHECK(target_path); char buf[PATH_MAX]; - ssize_t count = - ::readlink(symlink_path.value().c_str(), buf, base::size(buf)); + ssize_t count = ::readlink(symlink_path.value().c_str(), buf, std::size(buf)); #if BUILDFLAG(IS_ANDROID) && defined(__LP64__) // A few 64-bit Android L/M devices return INT_MAX instead of -1 here for @@ -1063,7 +1061,7 @@ bool VerifyPathControlledByAdmin(const FilePath& path) { ScopedBlockingCall scoped_blocking_call(FROM_HERE, BlockingType::MAY_BLOCK); std::set allowed_group_ids; - for (int i = 0, ie = base::size(kAdminGroupNames); i < ie; ++i) { + for (int i = 0, ie = std::size(kAdminGroupNames); i < ie; ++i) { struct group *group_record = getgrnam(kAdminGroupNames[i]); if (!group_record) { DPLOG(ERROR) << "Could not get the group ID of group \"" diff --git a/base/files/file_util_unittest.cc b/base/files/file_util_unittest.cc index e3b6b7f45e8cea..a57f38d4be4119 100644 --- a/base/files/file_util_unittest.cc +++ b/base/files/file_util_unittest.cc @@ -20,7 +20,6 @@ #include "base/bind.h" #include "base/callback_helpers.h" #include "base/command_line.h" -#include "base/cxx17_backports.h" #include "base/environment.h" #include "base/files/file.h" #include "base/files/file_enumerator.h" @@ -351,7 +350,7 @@ std::wstring ReadTextFile(const FilePath& filename) { file.open(filename.value()); #endif // BUILDFLAG(IS_WIN) EXPECT_TRUE(file.is_open()); - file.getline(contents, size(contents)); + file.getline(contents, std::size(contents)); file.close(); return std::wstring(contents); } @@ -2545,7 +2544,7 @@ TEST_F(FileUtilTest, GetTempDirTest) { ASSERT_EQ(0, ::_tdupenv_s(&original_tmp, &original_tmp_size, kTmpKey)); // original_tmp may be NULL. - for (unsigned int i = 0; i < size(kTmpValues); ++i) { + for (unsigned int i = 0; i < std::size(kTmpValues); ++i) { FilePath path; ::_tputenv_s(kTmpKey, kTmpValues[i]); GetTempDir(&path); @@ -4152,7 +4151,7 @@ TEST_F(FileUtilTest, PreReadFile_ExistingFile_ExactSize) { CreateTextFile(text_file, bogus_content); EXPECT_TRUE( - PreReadFile(text_file, /*is_executable=*/false, base::size(bogus_content)) + PreReadFile(text_file, /*is_executable=*/false, std::size(bogus_content)) .succeeded()); } @@ -4161,7 +4160,7 @@ TEST_F(FileUtilTest, PreReadFile_ExistingFile_OverSized) { CreateTextFile(text_file, bogus_content); EXPECT_TRUE(PreReadFile(text_file, /*is_executable=*/false, - base::size(bogus_content) * 2) + std::size(bogus_content) * 2) .succeeded()); } @@ -4170,7 +4169,7 @@ TEST_F(FileUtilTest, PreReadFile_ExistingFile_UnderSized) { CreateTextFile(text_file, bogus_content); EXPECT_TRUE(PreReadFile(text_file, /*is_executable=*/false, - base::size(bogus_content) / 2) + std::size(bogus_content) / 2) .succeeded()); } diff --git a/base/files/file_util_win.cc b/base/files/file_util_win.cc index 90116ac7192dda..444cd14a4e5a62 100644 --- a/base/files/file_util_win.cc +++ b/base/files/file_util_win.cc @@ -5,6 +5,7 @@ #include "base/files/file_util.h" #include + #include #include #include @@ -20,7 +21,6 @@ #include "base/bind.h" #include "base/callback.h" -#include "base/cxx17_backports.h" #include "base/debug/alias.h" #include "base/files/file_enumerator.h" #include "base/files/file_path.h" @@ -382,10 +382,10 @@ bool ReplaceFile(const FilePath& from_path, // Alias paths for investigation of shutdown hangs. crbug.com/1054164 FilePath::CharType from_path_str[MAX_PATH]; base::wcslcpy(from_path_str, from_path.value().c_str(), - base::size(from_path_str)); + std::size(from_path_str)); base::debug::Alias(from_path_str); FilePath::CharType to_path_str[MAX_PATH]; - base::wcslcpy(to_path_str, to_path.value().c_str(), base::size(to_path_str)); + base::wcslcpy(to_path_str, to_path.value().c_str(), std::size(to_path_str)); base::debug::Alias(to_path_str); // Assume that |to_path| already exists and try the normal replace. This will @@ -935,7 +935,7 @@ int GetMaximumPathComponentLength(const FilePath& path) { wchar_t volume_path[MAX_PATH]; if (!GetVolumePathNameW(path.NormalizePathSeparators().value().c_str(), - volume_path, size(volume_path))) { + volume_path, std::size(volume_path))) { return -1; } diff --git a/base/files/important_file_writer.cc b/base/files/important_file_writer.cc index 69fd3f22a8cfb5..6cc86fb257feb3 100644 --- a/base/files/important_file_writer.cc +++ b/base/files/important_file_writer.cc @@ -16,7 +16,6 @@ #include "base/callback_helpers.h" #include "base/check.h" #include "base/critical_closure.h" -#include "base/cxx17_backports.h" #include "base/debug/alias.h" #include "base/files/file.h" #include "base/files/file_path.h" @@ -155,7 +154,7 @@ bool ImportantFileWriter::WriteFileAtomicallyImpl(const FilePath& path, // hits a DCHECK because creation fails with no indication why. Pull the path // onto the stack so that we can see if it is malformed in some odd way. wchar_t path_copy[MAX_PATH]; - base::wcslcpy(path_copy, path.value().c_str(), base::size(path_copy)); + base::wcslcpy(path_copy, path.value().c_str(), std::size(path_copy)); base::debug::Alias(path_copy); #endif // BUILDFLAG(IS_WIN) && DCHECK_IS_ON() @@ -169,7 +168,7 @@ bool ImportantFileWriter::WriteFileAtomicallyImpl(const FilePath& path, char path[128]; } file_info; file_info.data_size = data.size(); - strlcpy(file_info.path, path.value().c_str(), base::size(file_info.path)); + strlcpy(file_info.path, path.value().c_str(), std::size(file_info.path)); debug::Alias(&file_info); #endif diff --git a/base/hash/md5_constexpr_unittest.cc b/base/hash/md5_constexpr_unittest.cc index dba6bbae5d9b1e..da2e283fa38d02 100644 --- a/base/hash/md5_constexpr_unittest.cc +++ b/base/hash/md5_constexpr_unittest.cc @@ -4,7 +4,6 @@ #include "base/hash/md5_constexpr.h" -#include "base/cxx17_backports.h" #include "base/hash/md5.h" #include "testing/gtest/include/gtest/gtest.h" @@ -21,7 +20,7 @@ constexpr MD5CE::IntermediateData MD5CE::kInitialIntermediateData; // A constexpr comparison operator for MD5Results, allowing compile time tests // to be expressed. constexpr bool Equal(const MD5Digest& lhs, const MD5Digest& rhs) { - for (size_t i = 0; i < base::size(lhs.a); ++i) { + for (size_t i = 0; i < std::size(lhs.a); ++i) { if (lhs.a[i] != rhs.a[i]) return false; } @@ -38,18 +37,18 @@ static_assert(MD5Hash32Constexpr(kMessage0) == 0xF96B697Dul, "incorrect MD5Hash32 implementation"); constexpr char kMessage1[] = "The quick brown fox jumps over the lazy dog"; -static_assert(MD5Hash64Constexpr(kMessage1, base::size(kMessage1) - 1) == +static_assert(MD5Hash64Constexpr(kMessage1, std::size(kMessage1) - 1) == 0x9E107D9D372BB682ull, "incorrect MD5Hash64 implementation"); -static_assert(MD5Hash32Constexpr(kMessage1, base::size(kMessage1) - 1) == +static_assert(MD5Hash32Constexpr(kMessage1, std::size(kMessage1) - 1) == 0x9E107D9Dul, "incorrect MD5Hash32 implementation"); // Comparison operator for checking that the constexpr MD5 implementation // matches the default implementation. void ExpectEqual(const MD5Digest& lhs, const MD5Digest& rhs) { - for (size_t i = 0; i < base::size(lhs.a); ++i) + for (size_t i = 0; i < std::size(lhs.a); ++i) EXPECT_EQ(lhs.a[i], rhs.a[i]); } diff --git a/base/i18n/break_iterator_unittest.cc b/base/i18n/break_iterator_unittest.cc index dd05231d969047..a9ba8e879efbd3 100644 --- a/base/i18n/break_iterator_unittest.cc +++ b/base/i18n/break_iterator_unittest.cc @@ -5,9 +5,9 @@ #include "base/i18n/break_iterator.h" #include + #include -#include "base/cxx17_backports.h" #include "base/ranges/algorithm.h" #include "base/strings/string_piece.h" #include "base/strings/string_util.h" @@ -506,7 +506,7 @@ TEST(BreakIteratorTest, BreakCharacter) { } BreakIterator iter(text, BreakIterator::BREAK_CHARACTER); ASSERT_TRUE(iter.Init()); - for (size_t i = 0; i < base::size(kCharacters); ++i) { + for (size_t i = 0; i < std::size(kCharacters); ++i) { EXPECT_TRUE(iter.Advance()); EXPECT_EQ(characters[i], iter.GetString()); } diff --git a/base/i18n/build_utf8_validator_tables.cc b/base/i18n/build_utf8_validator_tables.cc index 302ac96eaa6487..bd8e042e354d7e 100644 --- a/base/i18n/build_utf8_validator_tables.cc +++ b/base/i18n/build_utf8_validator_tables.cc @@ -38,7 +38,6 @@ #include #include "base/command_line.h" -#include "base/cxx17_backports.h" #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/logging.h" @@ -72,7 +71,7 @@ const char kEpilog[] = "};\n" "\n" "const size_t kUtf8ValidatorTablesSize = " - "base::size(kUtf8ValidatorTables);\n" + "std::size(kUtf8ValidatorTables);\n" "\n" "} // namespace internal\n" "} // namespace base\n"; @@ -183,10 +182,10 @@ PairVector InitializeCharacters() { uint8_t bytes[4]; unsigned int offset = 0; UBool is_error = false; - U8_APPEND(bytes, offset, base::size(bytes), i, is_error); + U8_APPEND(bytes, offset, std::size(bytes), i, is_error); DCHECK(!is_error); DCHECK_GT(offset, 0u); - DCHECK_LE(offset, base::size(bytes)); + DCHECK_LE(offset, std::size(bytes)); Pair pair = {Character(bytes, bytes + offset), StringSet()}; vector.push_back(pair); } @@ -321,7 +320,7 @@ uint8_t MakeState(const StringSet& set, {static_cast(range.to() + 1), 1}}; states->push_back( State(new_state_initializer, - new_state_initializer + base::size(new_state_initializer))); + new_state_initializer + std::size(new_state_initializer))); const uint8_t new_state_number = base::checked_cast(states->size() - 1); CHECK(state_map->insert(std::make_pair(set, new_state_number)).second); @@ -355,7 +354,7 @@ std::vector GenerateStates(const PairVector& pairs) { {static_cast(range.to() + 1), 1}}; states[0].insert( states[0].end(), new_range_initializer, - new_range_initializer + base::size(new_range_initializer)); + new_range_initializer + std::size(new_range_initializer)); } } return states; @@ -431,7 +430,7 @@ int main(int argc, char* argv[]) { logging::LOG_TO_SYSTEM_DEBUG_LOG | logging::LOG_TO_STDERR; logging::InitLogging(settings); if (base::CommandLine::ForCurrentProcess()->HasSwitch("help")) { - fwrite(kHelpText, 1, base::size(kHelpText), stdout); + fwrite(kHelpText, 1, std::size(kHelpText), stdout); exit(EXIT_SUCCESS); } base::FilePath filename = diff --git a/base/i18n/file_util_icu_unittest.cc b/base/i18n/file_util_icu_unittest.cc index c4fa774fe8215d..62c3f20c8f71fc 100644 --- a/base/i18n/file_util_icu_unittest.cc +++ b/base/i18n/file_util_icu_unittest.cc @@ -148,7 +148,7 @@ static const struct normalize_name_encoding_test_cases { }; TEST_F(FileUtilICUTest, NormalizeFileNameEncoding) { - for (size_t i = 0; i < size(kNormalizeFileNameEncodingTestCases); i++) { + for (size_t i = 0; i < std::size(kNormalizeFileNameEncodingTestCases); i++) { FilePath path(kNormalizeFileNameEncodingTestCases[i].original_path); NormalizeFileNameEncoding(&path); EXPECT_EQ(FilePath(kNormalizeFileNameEncodingTestCases[i].normalized_path), diff --git a/base/i18n/icu_string_conversions_unittest.cc b/base/i18n/icu_string_conversions_unittest.cc index 626df463eb6630..bd8c19fd9ce266 100644 --- a/base/i18n/icu_string_conversions_unittest.cc +++ b/base/i18n/icu_string_conversions_unittest.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/i18n/icu_string_conversions.h" + #include #include #include @@ -10,9 +12,7 @@ #include #include "base/check_op.h" -#include "base/cxx17_backports.h" #include "base/format_macros.h" -#include "base/i18n/icu_string_conversions.h" #include "base/strings/string_piece.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" @@ -163,7 +163,7 @@ static const struct { }; TEST(ICUStringConversionsTest, ConvertBetweenCodepageAndUTF16) { - for (size_t i = 0; i < base::size(kConvertCodepageCases); ++i) { + for (size_t i = 0; i < std::size(kConvertCodepageCases); ++i) { SCOPED_TRACE(base::StringPrintf( "Test[%" PRIuS "]: ", i, kConvertCodepageCases[i].encoded, @@ -218,7 +218,7 @@ static const struct { }; TEST(ICUStringConversionsTest, ConvertToUtf8AndNormalize) { std::string result; - for (size_t i = 0; i < base::size(kConvertAndNormalizeCases); ++i) { + for (size_t i = 0; i < std::size(kConvertAndNormalizeCases); ++i) { SCOPED_TRACE(base::StringPrintf( "Test[%" PRIuS "]: ", i, kConvertAndNormalizeCases[i].encoded, diff --git a/base/i18n/rtl.cc b/base/i18n/rtl.cc index fec3f28a6d461d..c7f908458e90cd 100644 --- a/base/i18n/rtl.cc +++ b/base/i18n/rtl.cc @@ -10,7 +10,6 @@ #include #include "base/command_line.h" -#include "base/cxx17_backports.h" #include "base/files/file_path.h" #include "base/i18n/base_i18n_switches.h" #include "base/logging.h" @@ -203,7 +202,7 @@ TextDirection GetTextDirectionForLocaleInStartUp(const char* locale_name) { SplitStringPiece(locale_name, "-_", KEEP_WHITESPACE, SPLIT_WANT_ALL); const StringPiece& language_code = locale_split[0]; if (std::binary_search(kRTLLanguageCodes, - kRTLLanguageCodes + base::size(kRTLLanguageCodes), + kRTLLanguageCodes + std::size(kRTLLanguageCodes), language_code)) return RIGHT_TO_LEFT; return LEFT_TO_RIGHT; diff --git a/base/i18n/streaming_utf8_validator_unittest.cc b/base/i18n/streaming_utf8_validator_unittest.cc index c82fdc1cd7ad19..f0706b3484ad3a 100644 --- a/base/i18n/streaming_utf8_validator_unittest.cc +++ b/base/i18n/streaming_utf8_validator_unittest.cc @@ -11,7 +11,6 @@ #include -#include "base/cxx17_backports.h" #include "base/strings/string_piece.h" #include "testing/gtest/include/gtest/gtest.h" @@ -143,7 +142,7 @@ const char* const valid[] = {"\r", "\n", "a", "\xef\xbb\xbf", // UTF-8 BOM }; -const char* const* const valid_end = valid + base::size(valid); +const char* const* const valid_end = valid + std::size(valid); const char* const invalid[] = { // always invalid bytes @@ -176,7 +175,7 @@ const char* const invalid[] = { "\xfe\xff", "\xff\xfe", }; -const char* const* const invalid_end = invalid + base::size(invalid); +const char* const* const invalid_end = invalid + std::size(invalid); // A ForwardIterator which returns all the non-empty prefixes of the elements of // "valid". @@ -189,7 +188,7 @@ class PartialIterator { // This is a value type; the default copy constructor and assignment operator // generated by the compiler are used. - static PartialIterator end() { return PartialIterator(base::size(valid), 1); } + static PartialIterator end() { return PartialIterator(std::size(valid), 1); } PartialIterator& operator++() { Advance(); @@ -212,9 +211,9 @@ class PartialIterator { : index_(index), prefix_length_(prefix_length) {} void Advance() { - if (index_ < base::size(valid) && prefix_length_ < strlen(valid[index_])) + if (index_ < std::size(valid) && prefix_length_ < strlen(valid[index_])) ++prefix_length_; - while (index_ < base::size(valid) && + while (index_ < std::size(valid) && prefix_length_ == strlen(valid[index_])) { ++index_; prefix_length_ = 1; diff --git a/base/i18n/string_search_unittest.cc b/base/i18n/string_search_unittest.cc index 4a1606f074c50b..298eafa7ed6c32 100644 --- a/base/i18n/string_search_unittest.cc +++ b/base/i18n/string_search_unittest.cc @@ -2,14 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/i18n/string_search.h" + #include #include #include -#include "base/cxx17_backports.h" #include "base/i18n/rtl.h" -#include "base/i18n/string_search.h" #include "base/strings/utf_string_conversions.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/icu/source/i18n/unicode/usearch.h" @@ -361,7 +361,7 @@ TEST(StringSearchTest, RepeatingStringSearch) { {.match_index = match_index, .match_length = match_length}); } - ASSERT_EQ(base::size(kExpectation), results.size()); + ASSERT_EQ(std::size(kExpectation), results.size()); for (size_t i = 0; i < results.size(); ++i) { EXPECT_EQ(results[i].match_index, kExpectation[i].match_index); EXPECT_EQ(results[i].match_length, kExpectation[i].match_length); @@ -381,7 +381,7 @@ TEST(StringSearchTest, RepeatingStringSearch) { {.match_index = match_index, .match_length = match_length}); } - ASSERT_EQ(base::size(kExpectation), results.size()); + ASSERT_EQ(std::size(kExpectation), results.size()); for (size_t i = 0; i < results.size(); ++i) { EXPECT_EQ(results[i].match_index, kExpectation[i].match_index); EXPECT_EQ(results[i].match_length, kExpectation[i].match_length); diff --git a/base/i18n/utf8_validator_tables.cc b/base/i18n/utf8_validator_tables.cc index 085f08ebf6c7c1..5dc97276447f1a 100644 --- a/base/i18n/utf8_validator_tables.cc +++ b/base/i18n/utf8_validator_tables.cc @@ -6,7 +6,8 @@ // DO NOT EDIT. #include "base/i18n/utf8_validator_tables.h" -#include "base/cxx17_backports.h" + +#include namespace base { namespace internal { @@ -50,7 +51,7 @@ const uint8_t kUtf8ValidatorTables[] = { 0x81, // 0xa8 }; -const size_t kUtf8ValidatorTablesSize = base::size(kUtf8ValidatorTables); +const size_t kUtf8ValidatorTablesSize = std::size(kUtf8ValidatorTables); } // namespace internal } // namespace base diff --git a/base/ios/ios_util.mm b/base/ios/ios_util.mm index 6aa164c30b6196..c36a79a382f759 100644 --- a/base/ios/ios_util.mm +++ b/base/ios/ios_util.mm @@ -6,10 +6,8 @@ #import #import - #include -#include "base/cxx17_backports.h" #include "base/mac/foundation_util.h" #include "base/system/sys_info.h" @@ -54,7 +52,7 @@ bool IsRunningOnIOS15OrLater() { bool IsRunningOnOrLater(int32_t major, int32_t minor, int32_t bug_fix) { static const int32_t* current_version = OSVersionAsArray(); int32_t version[] = {major, minor, bug_fix}; - for (size_t i = 0; i < base::size(version); i++) { + for (size_t i = 0; i < std::size(version); i++) { if (current_version[i] != version[i]) return current_version[i] > version[i]; } diff --git a/base/json/json_reader_unittest.cc b/base/json/json_reader_unittest.cc index f4c71f7b526f37..16ebccb3eb89e2 100644 --- a/base/json/json_reader_unittest.cc +++ b/base/json/json_reader_unittest.cc @@ -9,7 +9,6 @@ #include #include "base/base_paths.h" -#include "base/cxx17_backports.h" #include "base/files/file_util.h" #include "base/logging.h" #include "base/path_service.h" @@ -767,7 +766,7 @@ TEST(JSONReaderTest, InvalidSanity) { "/* test *", "{\"foo\"", "{\"foo\":", " [", "\"\\u123g\"", "{\n\"eh:\n}", }; - for (size_t i = 0; i < base::size(kInvalidJson); ++i) { + for (size_t i = 0; i < std::size(kInvalidJson); ++i) { LOG(INFO) << "Sanity test " << i << ": <" << kInvalidJson[i] << ">"; JSONReader::ValueWithError root = JSONReader::ReadAndReturnValueWithError(kInvalidJson[i]); @@ -922,7 +921,7 @@ TEST(JSONReaderTest, ParseNumberErrors) { // clang-format on }; - for (unsigned int i = 0; i < base::size(kCases); ++i) { + for (unsigned int i = 0; i < std::size(kCases); ++i) { auto test_case = kCases[i]; SCOPED_TRACE(StringPrintf("case %u: \"%s\"", i, test_case.input)); @@ -963,7 +962,7 @@ TEST(JSONReaderTest, UnterminatedInputs) { // clang-format on }; - for (unsigned int i = 0; i < base::size(kCases); ++i) { + for (unsigned int i = 0; i < std::size(kCases); ++i) { auto* test_case = kCases[i]; SCOPED_TRACE(StringPrintf("case %u: \"%s\"", i, test_case)); @@ -1035,7 +1034,7 @@ TEST(JSONReaderTest, LineColumnCounting) { }, }; - for (unsigned int i = 0; i < base::size(kCases); ++i) { + for (unsigned int i = 0; i < std::size(kCases); ++i) { auto test_case = kCases[i]; SCOPED_TRACE(StringPrintf("case %u: \"%s\"", i, test_case.input)); @@ -1068,7 +1067,7 @@ TEST(JSONReaderTest, ChromiumExtensions) { {"[\"\\v\"]", JSON_ALLOW_VERT_TAB}, }; - for (size_t i = 0; i < base::size(kCases); ++i) { + for (size_t i = 0; i < std::size(kCases); ++i) { SCOPED_TRACE(testing::Message() << "case " << i); const auto& test_case = kCases[i]; diff --git a/base/json/string_escape_unittest.cc b/base/json/string_escape_unittest.cc index 601d92637df3e4..7cc66b52ff658f 100644 --- a/base/json/string_escape_unittest.cc +++ b/base/json/string_escape_unittest.cc @@ -6,7 +6,6 @@ #include -#include "base/cxx17_backports.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "testing/gtest/include/gtest/gtest.h" @@ -252,7 +251,7 @@ TEST(JSONStringEscapeTest, EscapeBytes) { } const char kEmbedNull[] = { '\xab', '\x39', '\0', '\x9f', '\xab' }; - std::string in(kEmbedNull, base::size(kEmbedNull)); + std::string in(kEmbedNull, std::size(kEmbedNull)); EXPECT_FALSE(IsStringUTF8AllowingNoncharacters(in)); EXPECT_EQ(std::string("\\u00AB9\\u0000\\u009F\\u00AB"), EscapeBytesAsInvalidJSONString(in, false)); diff --git a/base/logging.cc b/base/logging.cc index afb0b870fa974d..aa45657ddd4af3 100644 --- a/base/logging.cc +++ b/base/logging.cc @@ -143,7 +143,7 @@ VlogInfo* g_vlog_info = nullptr; VlogInfo* g_vlog_info_prev = nullptr; const char* const log_severity_names[] = {"INFO", "WARNING", "ERROR", "FATAL"}; -static_assert(LOGGING_NUM_SEVERITIES == base::size(log_severity_names), +static_assert(LOGGING_NUM_SEVERITIES == std::size(log_severity_names), "Incorrect number of log_severity_names"); const char* log_severity_name(int severity) { @@ -301,8 +301,8 @@ bool InitializeLogFileHandle() { // try the current directory wchar_t system_buffer[MAX_PATH]; system_buffer[0] = 0; - DWORD len = ::GetCurrentDirectory(base::size(system_buffer), system_buffer); - if (len == 0 || len > base::size(system_buffer)) + DWORD len = ::GetCurrentDirectory(std::size(system_buffer), system_buffer); + if (len == 0 || len > std::size(system_buffer)) return false; *g_log_file_name = system_buffer; @@ -714,7 +714,7 @@ LogMessage::~LogMessage() { // By default, messages are only readable by the admin group. Explicitly // make them readable by the user generating the messages. char euid_string[12]; - snprintf(euid_string, base::size(euid_string), "%d", geteuid()); + snprintf(euid_string, std::size(euid_string), "%d", geteuid()); asl_set(asl_message.get(), ASL_KEY_READ_UID, euid_string); // Map Chrome log severities to ASL log levels. @@ -877,7 +877,7 @@ LogMessage::~LogMessage() { tracker->RecordLogMessage(str_newline); char str_stack[1024]; - base::strlcpy(str_stack, str_newline.data(), base::size(str_stack)); + base::strlcpy(str_stack, str_newline.data(), std::size(str_stack)); base::debug::Alias(&str_stack); if (!GetLogAssertHandlerStack().empty()) { @@ -1005,7 +1005,7 @@ BASE_EXPORT std::string SystemErrorCodeToString(SystemErrorCode error_code) { char msgbuf[kErrorMessageBufferSize]; DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS; DWORD len = FormatMessageA(flags, nullptr, error_code, 0, msgbuf, - base::size(msgbuf), nullptr); + std::size(msgbuf), nullptr); if (len) { // Messages returned by system end with line breaks. return base::CollapseWhitespaceASCII(msgbuf, true) + diff --git a/base/mac/authorization_util.mm b/base/mac/authorization_util.mm index e1900a303be797..6247665ff8d8e3 100644 --- a/base/mac/authorization_util.mm +++ b/base/mac/authorization_util.mm @@ -10,7 +10,6 @@ #include -#include "base/cxx17_backports.h" #include "base/logging.h" #include "base/mac/bundle_locations.h" #include "base/mac/foundation_util.h" @@ -70,7 +69,7 @@ AuthorizationRef GetAuthorizationRightsWithPrompt( {kAuthorizationEnvironmentPrompt, prompt_length, (void*)prompt_c, 0} }; - AuthorizationEnvironment environment = {base::size(environment_items), + AuthorizationEnvironment environment = {std::size(environment_items), environment_items}; status = AuthorizationCopyRights(authorization, @@ -95,7 +94,7 @@ AuthorizationRef AuthorizationCreateToRunAsRoot(CFStringRef prompt) { AuthorizationItem right_items[] = { {kAuthorizationRightExecute, 0, NULL, 0} }; - AuthorizationRights rights = {base::size(right_items), right_items}; + AuthorizationRights rights = {std::size(right_items), right_items}; return GetAuthorizationRightsWithPrompt(&rights, prompt, 0); } diff --git a/base/mac/backup_util_unittest.mm b/base/mac/backup_util_unittest.mm index 854a41473e9617..f746e7d1a7812a 100644 --- a/base/mac/backup_util_unittest.mm +++ b/base/mac/backup_util_unittest.mm @@ -30,9 +30,9 @@ FilePath excluded_file_path = temp_dir_.GetPath().Append("excluded"); constexpr char placeholder_data[] = "All your base are belong to us!"; // Dump something real into the file. - ASSERT_EQ(checked_cast(base::size(placeholder_data)), + ASSERT_EQ(checked_cast(std::size(placeholder_data)), WriteFile(excluded_file_path, placeholder_data, - base::size(placeholder_data))); + std::size(placeholder_data))); // Initial state should be non-excluded. EXPECT_FALSE(GetBackupExclusion(excluded_file_path)); // Exclude the file. @@ -48,9 +48,9 @@ base::mac::FilePathToCFURL(excluded_file_path); constexpr char placeholder_data[] = "All your base are belong to us!"; - ASSERT_EQ(checked_cast(base::size(placeholder_data)), + ASSERT_EQ(checked_cast(std::size(placeholder_data)), WriteFile(excluded_file_path, placeholder_data, - base::size(placeholder_data))); + std::size(placeholder_data))); ASSERT_TRUE(SetBackupExclusion(excluded_file_path)); EXPECT_TRUE(GetBackupExclusion(excluded_file_path)) @@ -58,9 +58,9 @@ // Re-create the file. ASSERT_TRUE(DeleteFile(excluded_file_path)); - ASSERT_EQ(checked_cast(base::size(placeholder_data)), + ASSERT_EQ(checked_cast(std::size(placeholder_data)), WriteFile(excluded_file_path, placeholder_data, - base::size(placeholder_data))); + std::size(placeholder_data))); EXPECT_FALSE(GetBackupExclusion(excluded_file_path)) << "Re-created file should not be excluded from backup"; } diff --git a/base/mac/foundation_util.mm b/base/mac/foundation_util.mm index bd26c088c2340f..61641e1ad8a47a 100644 --- a/base/mac/foundation_util.mm +++ b/base/mac/foundation_util.mm @@ -10,7 +10,6 @@ #include -#include "base/cxx17_backports.h" #include "base/files/file_path.h" #include "base/logging.h" #include "base/mac/bundle_locations.h" @@ -158,7 +157,7 @@ FilePath GetUserLibraryPath() { // returns - path to the application bundle, or empty on error FilePath GetAppBundlePath(const FilePath& exec_name) { const char kExt[] = ".app"; - const size_t kExtLength = base::size(kExt) - 1; + const size_t kExtLength = std::size(kExt) - 1; // Split the path into components. std::vector components = exec_name.GetComponents(); diff --git a/base/mac/foundation_util_unittest.mm b/base/mac/foundation_util_unittest.mm index c48e2bf524509d..8fcfc003b9d75c 100644 --- a/base/mac/foundation_util_unittest.mm +++ b/base/mac/foundation_util_unittest.mm @@ -7,7 +7,6 @@ #include #include -#include "base/cxx17_backports.h" #include "base/files/file_path.h" #include "base/format_macros.h" #include "base/mac/scoped_cftyperef.h" @@ -275,12 +274,12 @@ CFStringRef keys[] = { CFSTR("one"), CFSTR("two"), CFSTR("three") }; CFNumberRef values[] = { cf_one, cf_two, cf_three }; - static_assert(base::size(keys) == base::size(values), + static_assert(std::size(keys) == std::size(values), "keys and values arrays must have the same size"); ScopedCFTypeRef test_dict(CFDictionaryCreate( kCFAllocatorDefault, reinterpret_cast(keys), - reinterpret_cast(values), base::size(values), + reinterpret_cast(values), std::size(values), &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); // GetValueFromDictionary<>(_, _) should produce the correct @@ -369,7 +368,7 @@ #endif // !defined(ARCH_CPU_64_BITS) }; - for (size_t i = 0; i < base::size(nsinteger_cases); ++i) { + for (size_t i = 0; i < std::size(nsinteger_cases); ++i) { EXPECT_EQ(nsinteger_cases[i].expected, StringPrintf("%" PRIdNS, nsinteger_cases[i].value)); EXPECT_EQ(nsinteger_cases[i].expected_hex, @@ -393,7 +392,7 @@ #endif // !defined(ARCH_CPU_64_BITS) }; - for (size_t i = 0; i < base::size(nsuinteger_cases); ++i) { + for (size_t i = 0; i < std::size(nsuinteger_cases); ++i) { EXPECT_EQ(nsuinteger_cases[i].expected, StringPrintf("%" PRIuNS, nsuinteger_cases[i].value)); EXPECT_EQ(nsuinteger_cases[i].expected_hex, diff --git a/base/mac/mac_util_unittest.mm b/base/mac/mac_util_unittest.mm index 4f0a5e50115192..8360b7c260feda 100644 --- a/base/mac/mac_util_unittest.mm +++ b/base/mac/mac_util_unittest.mm @@ -10,7 +10,6 @@ #include #include -#include "base/cxx17_backports.h" #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" @@ -61,7 +60,7 @@ "/", "/foo", "foo", "/foo/bar.", "foo/bar.", "/foo/bar./bazquux", "foo/bar./bazquux", "foo/.app", "//foo", }; - for (size_t i = 0; i < base::size(invalid_inputs); i++) { + for (size_t i = 0; i < std::size(invalid_inputs); i++) { out = GetAppBundlePath(FilePath(invalid_inputs[i])); EXPECT_TRUE(out.empty()) << "loop: " << i; } @@ -85,7 +84,7 @@ { "/Applications/Google Foo.app/bar/Foo Helper.app/quux/Foo Helper", "/Applications/Google Foo.app" }, }; - for (size_t i = 0; i < base::size(valid_inputs); i++) { + for (size_t i = 0; i < std::size(valid_inputs); i++) { out = GetAppBundlePath(FilePath(valid_inputs[i].in)); EXPECT_FALSE(out.empty()) << "loop: " << i; EXPECT_STREQ(valid_inputs[i].expected_out, diff --git a/base/mac/mach_port_rendezvous_unittest.cc b/base/mac/mach_port_rendezvous_unittest.cc index 4a140fdd64fdbe..a85833770eb24e 100644 --- a/base/mac/mach_port_rendezvous_unittest.cc +++ b/base/mac/mach_port_rendezvous_unittest.cc @@ -9,7 +9,6 @@ #include #include "base/at_exit.h" -#include "base/cxx17_backports.h" #include "base/mac/foundation_util.h" #include "base/mac/mach_logging.h" #include "base/strings/stringprintf.h" @@ -189,7 +188,7 @@ TEST_F(MachPortRendezvousServerTest, DestroyRight) { // insert_right MAKE_SEND_ONCE. }; - for (size_t i = 0; i < base::size(kCases); ++i) { + for (size_t i = 0; i < std::size(kCases); ++i) { SCOPED_TRACE(base::StringPrintf("case %zu", i).c_str()); const auto& test = kCases[i]; diff --git a/base/mac/os_crash_dumps.cc b/base/mac/os_crash_dumps.cc index 616b9b958ac98f..2f13e056849254 100644 --- a/base/mac/os_crash_dumps.cc +++ b/base/mac/os_crash_dumps.cc @@ -8,7 +8,6 @@ #include #include -#include "base/cxx17_backports.h" #include "base/logging.h" namespace base::mac { @@ -41,7 +40,7 @@ void DisableOSCrashDumps() { }; // For all these signals, just wire things up so we exit immediately. - for (size_t i = 0; i < base::size(signals_to_intercept); ++i) { + for (size_t i = 0; i < std::size(signals_to_intercept); ++i) { struct sigaction act = {}; act.sa_handler = ExitSignalHandler; diff --git a/base/memory/ref_counted_memory_unittest.cc b/base/memory/ref_counted_memory_unittest.cc index 5ee01656fb1c8d..62ac3173acef7d 100644 --- a/base/memory/ref_counted_memory_unittest.cc +++ b/base/memory/ref_counted_memory_unittest.cc @@ -51,7 +51,7 @@ TEST(RefCountedMemoryUnitTest, RefCountedBytes) { scoped_refptr mem2; { const unsigned char kData[] = {12, 11, 99}; - mem2 = MakeRefCounted(kData, size(kData)); + mem2 = MakeRefCounted(kData, std::size(kData)); } ASSERT_EQ(3U, mem2->size()); EXPECT_EQ(12U, mem2->front()[0]); diff --git a/base/message_loop/message_pump_mac.mm b/base/message_loop/message_pump_mac.mm index 36836673e97e53..981822b7385cbc 100644 --- a/base/message_loop/message_pump_mac.mm +++ b/base/message_loop/message_pump_mac.mm @@ -11,7 +11,6 @@ #include "base/auto_reset.h" #include "base/check_op.h" -#include "base/cxx17_backports.h" #include "base/feature_list.h" #include "base/mac/call_with_eh_frame.h" #include "base/mac/scoped_cftyperef.h" @@ -134,7 +133,7 @@ explicit MessagePumpScopedAutoreleasePool(MessagePumpCFRunLoopBase* pump) : // Process work when AppKit is highlighting an item on the main menubar. CFSTR("NSUnhighlightMenuRunLoopMode"), }; - static_assert(base::size(modes) == kNumModes, "mode size mismatch"); + static_assert(std::size(modes) == kNumModes, "mode size mismatch"); static_assert((1 << kNumModes) - 1 == kAllModesMask, "kAllModesMask not large enough"); diff --git a/base/metrics/metrics_hashes_unittest.cc b/base/metrics/metrics_hashes_unittest.cc index 84f41d49c81318..0cb05f1318df04 100644 --- a/base/metrics/metrics_hashes_unittest.cc +++ b/base/metrics/metrics_hashes_unittest.cc @@ -7,7 +7,6 @@ #include #include -#include "base/cxx17_backports.h" #include "base/format_macros.h" #include "base/strings/stringprintf.h" #include "testing/gtest/include/gtest/gtest.h" @@ -26,7 +25,7 @@ TEST(MetricsHashesTest, HashMetricName) { {"Forward", "0x67d2f6740a8eaebf"}, }; - for (size_t i = 0; i < base::size(cases); ++i) { + for (size_t i = 0; i < std::size(cases); ++i) { uint64_t hash = HashMetricName(cases[i].input); std::string hash_hex = base::StringPrintf("0x%016" PRIx64, hash); EXPECT_EQ(cases[i].output, hash_hex); @@ -44,7 +43,7 @@ TEST(MetricsHashesTest, HashMetricNameAs32Bits) { {"Forward", "0x67d2f674"}, }; - for (size_t i = 0; i < base::size(cases); ++i) { + for (size_t i = 0; i < std::size(cases); ++i) { uint32_t hash = HashMetricNameAs32Bits(cases[i].input); std::string hash_hex = base::StringPrintf("0x%08" PRIx32, hash); EXPECT_EQ(cases[i].output, hash_hex); diff --git a/base/metrics/sparse_histogram_unittest.cc b/base/metrics/sparse_histogram_unittest.cc index 862c75758e073b..6b6eda846d4b56 100644 --- a/base/metrics/sparse_histogram_unittest.cc +++ b/base/metrics/sparse_histogram_unittest.cc @@ -8,7 +8,6 @@ #include #include -#include "base/cxx17_backports.h" #include "base/logging.h" #include "base/memory/raw_ptr.h" #include "base/metrics/histogram_base.h" @@ -366,7 +365,7 @@ TEST_P(SparseHistogramTest, ExtremeValues) { {2147483647, 2147483648LL}, }; - for (size_t i = 0; i < base::size(cases); ++i) { + for (size_t i = 0; i < std::size(cases); ++i) { HistogramBase* histogram = SparseHistogram::FactoryGet(StringPrintf("ExtremeValues_%zu", i), HistogramBase::kUmaTargetedHistogramFlag); diff --git a/base/pickle_unittest.cc b/base/pickle_unittest.cc index bc623e3aa7ca7e..322f163e0067ee 100644 --- a/base/pickle_unittest.cc +++ b/base/pickle_unittest.cc @@ -12,8 +12,8 @@ #include #include -#include "base/cxx17_backports.h" #include "base/strings/utf_string_conversions.h" +#include "build/build_config.h" #include "testing/gtest/include/gtest/gtest.h" namespace base { @@ -37,7 +37,7 @@ const char testrawstring[] = "Hello new world"; // Test raw string writing // Test raw char16_t writing, assumes UTF16 encoding is ANSI for alpha chars. const char16_t testrawstring16[] = {'A', 'l', 'o', 'h', 'a', 0}; const char testdata[] = "AAA\0BBB\0"; -const int testdatalen = base::size(testdata) - 1; +const int testdatalen = std::size(testdata) - 1; // checks that the results can be read correctly from the Pickle void VerifyResult(const Pickle& pickle) { diff --git a/base/process/memory.cc b/base/process/memory.cc index e73c664e46ffc7..99162fae3431f8 100644 --- a/base/process/memory.cc +++ b/base/process/memory.cc @@ -40,7 +40,7 @@ NOINLINE void OnNoMemoryInternal(size_t size) { // Pass the size of the failed request in an exception argument. ULONG_PTR exception_args[] = {size}; ::RaiseException(base::win::kOomExceptionCode, EXCEPTION_NONCONTINUABLE, - base::size(exception_args), exception_args); + std::size(exception_args), exception_args); // Safety check, make sure process exits here. _exit(win::kOomExceptionCode); diff --git a/base/process/process_handle_freebsd.cc b/base/process/process_handle_freebsd.cc index 6cea2333b3e2ca..8fdb4c02a35e47 100644 --- a/base/process/process_handle_freebsd.cc +++ b/base/process/process_handle_freebsd.cc @@ -11,8 +11,6 @@ #include #include -#include "base/cxx17_backports.h" - namespace base { ProcessId GetParentProcessId(ProcessHandle process) { @@ -20,7 +18,7 @@ ProcessId GetParentProcessId(ProcessHandle process) { size_t length; int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, process }; - if (sysctl(mib, base::size(mib), &info, &length, NULL, 0) < 0) + if (sysctl(mib, std::size(mib), &info, &length, NULL, 0) < 0) return -1; return info.ki_ppid; @@ -33,7 +31,7 @@ FilePath GetProcessExecutablePath(ProcessHandle process) { length = sizeof(pathname); - if (sysctl(mib, base::size(mib), pathname, &length, NULL, 0) < 0 || + if (sysctl(mib, std::size(mib), pathname, &length, NULL, 0) < 0 || length == 0) { return FilePath(); } diff --git a/base/process/process_handle_openbsd.cc b/base/process/process_handle_openbsd.cc index 7856df5574de77..2b4bbac1036b9d 100644 --- a/base/process/process_handle_openbsd.cc +++ b/base/process/process_handle_openbsd.cc @@ -9,8 +9,6 @@ #include #include -#include "base/cxx17_backports.h" - namespace base { ProcessId GetParentProcessId(ProcessHandle process) { @@ -19,12 +17,12 @@ ProcessId GetParentProcessId(ProcessHandle process) { int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, process, sizeof(struct kinfo_proc), 0 }; - if (sysctl(mib, base::size(mib), NULL, &length, NULL, 0) < 0) + if (sysctl(mib, std::size(mib), NULL, &length, NULL, 0) < 0) return -1; mib[5] = (length / sizeof(struct kinfo_proc)); - if (sysctl(mib, base::size(mib), &info, &length, NULL, 0) < 0) + if (sysctl(mib, std::size(mib), &info, &length, NULL, 0) < 0) return -1; return info.p_ppid; @@ -36,10 +34,10 @@ FilePath GetProcessExecutablePath(ProcessHandle process) { int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, process, sizeof(struct kinfo_proc), 0 }; - if (sysctl(mib, base::size(mib), NULL, &len, NULL, 0) == -1) + if (sysctl(mib, std::size(mib), NULL, &len, NULL, 0) == -1) return FilePath(); mib[5] = (len / sizeof(struct kinfo_proc)); - if (sysctl(mib, base::size(mib), &kp, &len, NULL, 0) < 0) + if (sysctl(mib, std::size(mib), &kp, &len, NULL, 0) < 0) return FilePath(); if ((kp.p_flag & P_SYSTEM) != 0) return FilePath(); diff --git a/base/process/process_iterator_freebsd.cc b/base/process/process_iterator_freebsd.cc index bf0215b615d490..5603de9259f718 100644 --- a/base/process/process_iterator_freebsd.cc +++ b/base/process/process_iterator_freebsd.cc @@ -10,7 +10,6 @@ #include #include -#include "base/cxx17_backports.h" #include "base/logging.h" #include "base/strings/string_split.h" #include "base/strings/string_util.h" @@ -29,7 +28,7 @@ ProcessIterator::ProcessIterator(const ProcessFilter* filter) do { size_t len = 0; - if (sysctl(mib, base::size(mib), NULL, &len, NULL, 0) < 0) { + if (sysctl(mib, std::size(mib), NULL, &len, NULL, 0) < 0) { LOG(ERROR) << "failed to get the size needed for the process list"; kinfo_procs_.resize(0); done = true; @@ -40,7 +39,7 @@ ProcessIterator::ProcessIterator(const ProcessFilter* filter) num_of_kinfo_proc += 16; kinfo_procs_.resize(num_of_kinfo_proc); len = num_of_kinfo_proc * sizeof(struct kinfo_proc); - if (sysctl(mib, base::size(mib), &kinfo_procs_[0], &len, NULL, 0) < 0) { + if (sysctl(mib, std::size(mib), &kinfo_procs_[0], &len, NULL, 0) < 0) { // If we get a mem error, it just means we need a bigger buffer, so // loop around again. Anything else is a real error and give up. if (errno != ENOMEM) { @@ -78,14 +77,14 @@ bool ProcessIterator::CheckForNextProcess() { continue; length = 0; - if (sysctl(mib, base::size(mib), NULL, &length, NULL, 0) < 0) { + if (sysctl(mib, std::size(mib), NULL, &length, NULL, 0) < 0) { LOG(ERROR) << "failed to figure out the buffer size for a command line"; continue; } data.resize(length); - if (sysctl(mib, base::size(mib), &data[0], &length, NULL, 0) < 0) { + if (sysctl(mib, std::size(mib), &data[0], &length, NULL, 0) < 0) { LOG(ERROR) << "failed to fetch a commandline"; continue; } diff --git a/base/process/process_iterator_mac.cc b/base/process/process_iterator_mac.cc index 882f1665376157..caa2295070f530 100644 --- a/base/process/process_iterator_mac.cc +++ b/base/process/process_iterator_mac.cc @@ -10,7 +10,6 @@ #include #include -#include "base/cxx17_backports.h" #include "base/logging.h" #include "base/strings/string_split.h" #include "base/strings/string_util.h" @@ -35,7 +34,7 @@ ProcessIterator::ProcessIterator(const ProcessFilter* filter) do { // Get the size of the buffer size_t len = 0; - if (sysctl(mib, base::size(mib), NULL, &len, NULL, 0) < 0) { + if (sysctl(mib, std::size(mib), NULL, &len, NULL, 0) < 0) { DLOG(ERROR) << "failed to get the size needed for the process list"; kinfo_procs_.resize(0); done = true; @@ -47,7 +46,7 @@ ProcessIterator::ProcessIterator(const ProcessFilter* filter) kinfo_procs_.resize(num_of_kinfo_proc); len = num_of_kinfo_proc * sizeof(struct kinfo_proc); // Load the list of processes - if (sysctl(mib, base::size(mib), &kinfo_procs_[0], &len, NULL, 0) < 0) { + if (sysctl(mib, std::size(mib), &kinfo_procs_[0], &len, NULL, 0) < 0) { // If we get a mem error, it just means we need a bigger buffer, so // loop around again. Anything else is a real error and give up. if (errno != ENOMEM) { @@ -85,13 +84,13 @@ bool ProcessIterator::CheckForNextProcess() { // Find out what size buffer we need. size_t data_len = 0; - if (sysctl(mib, base::size(mib), NULL, &data_len, NULL, 0) < 0) { + if (sysctl(mib, std::size(mib), NULL, &data_len, NULL, 0) < 0) { DVPLOG(1) << "failed to figure out the buffer size for a commandline"; continue; } data.resize(data_len); - if (sysctl(mib, base::size(mib), &data[0], &data_len, NULL, 0) < 0) { + if (sysctl(mib, std::size(mib), &data[0], &data_len, NULL, 0) < 0) { DVPLOG(1) << "failed to fetch a commandline"; continue; } diff --git a/base/process/process_iterator_openbsd.cc b/base/process/process_iterator_openbsd.cc index 782d7015cc7584..8168c584bdb4a0 100644 --- a/base/process/process_iterator_openbsd.cc +++ b/base/process/process_iterator_openbsd.cc @@ -8,7 +8,6 @@ #include #include -#include "base/cxx17_backports.h" #include "base/logging.h" #include "base/strings/string_split.h" #include "base/strings/string_util.h" @@ -28,7 +27,7 @@ ProcessIterator::ProcessIterator(const ProcessFilter* filter) do { size_t len = 0; - if (sysctl(mib, base::size(mib), NULL, &len, NULL, 0) < 0) { + if (sysctl(mib, std::size(mib), NULL, &len, NULL, 0) < 0) { DLOG(ERROR) << "failed to get the size needed for the process list"; kinfo_procs_.resize(0); done = true; @@ -39,7 +38,7 @@ ProcessIterator::ProcessIterator(const ProcessFilter* filter) num_of_kinfo_proc += 16; kinfo_procs_.resize(num_of_kinfo_proc); len = num_of_kinfo_proc * sizeof(struct kinfo_proc); - if (sysctl(mib, base::size(mib), &kinfo_procs_[0], &len, NULL, 0) < 0) { + if (sysctl(mib, std::size(mib), &kinfo_procs_[0], &len, NULL, 0) < 0) { // If we get a mem error, it just means we need a bigger buffer, so // loop around again. Anything else is a real error and give up. if (errno != ENOMEM) { @@ -78,13 +77,13 @@ bool ProcessIterator::CheckForNextProcess() { // Find out what size buffer we need. size_t data_len = 0; - if (sysctl(mib, base::size(mib), NULL, &data_len, NULL, 0) < 0) { + if (sysctl(mib, std::size(mib), NULL, &data_len, NULL, 0) < 0) { DVPLOG(1) << "failed to figure out the buffer size for a commandline"; continue; } data.resize(data_len); - if (sysctl(mib, base::size(mib), &data[0], &data_len, NULL, 0) < 0) { + if (sysctl(mib, std::size(mib), &data[0], &data_len, NULL, 0) < 0) { DVPLOG(1) << "failed to fetch a commandline"; continue; } diff --git a/base/process/process_metrics_freebsd.cc b/base/process/process_metrics_freebsd.cc index 2c3c13edebade1..8557b644ec5c81 100644 --- a/base/process/process_metrics_freebsd.cc +++ b/base/process/process_metrics_freebsd.cc @@ -9,7 +9,6 @@ #include #include -#include "base/cxx17_backports.h" #include "base/memory/ptr_util.h" #include "base/process/process_metrics_iocounters.h" @@ -30,7 +29,7 @@ double ProcessMetrics::GetPlatformIndependentCPUUsage() { int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, process_}; size_t length = sizeof(info); - if (sysctl(mib, base::size(mib), &info, &length, NULL, 0) < 0) + if (sysctl(mib, std::size(mib), &info, &length, NULL, 0) < 0) return 0; return (info.ki_pctcpu / FSCALE) * 100.0; @@ -50,7 +49,7 @@ size_t GetSystemCommitCharge() { unsigned long mem_total, mem_free, mem_inactive; size_t length = sizeof(mem_total); - if (sysctl(mib, base::size(mib), &mem_total, &length, NULL, 0) < 0) + if (sysctl(mib, std::size(mib), &mem_total, &length, NULL, 0) < 0) return 0; length = sizeof(mem_free); diff --git a/base/process/process_metrics_openbsd.cc b/base/process/process_metrics_openbsd.cc index b5cafee0a9684f..1317a35a59be2a 100644 --- a/base/process/process_metrics_openbsd.cc +++ b/base/process/process_metrics_openbsd.cc @@ -9,7 +9,6 @@ #include #include -#include "base/cxx17_backports.h" #include "base/memory/ptr_util.h" #include "base/process/process_metrics_iocounters.h" @@ -31,12 +30,12 @@ static int GetProcessCPU(pid_t pid) { int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid, sizeof(struct kinfo_proc), 0 }; - if (sysctl(mib, base::size(mib), NULL, &length, NULL, 0) < 0) + if (sysctl(mib, std::size(mib), NULL, &length, NULL, 0) < 0) return -1; mib[5] = (length / sizeof(struct kinfo_proc)); - if (sysctl(mib, base::size(mib), &info, &length, NULL, 0) < 0) + if (sysctl(mib, std::size(mib), &info, &length, NULL, 0) < 0) return 0; return info.p_pctcpu; @@ -75,7 +74,7 @@ size_t GetSystemCommitCharge() { unsigned long mem_total, mem_free, mem_inactive; size_t len = sizeof(vmtotal); - if (sysctl(mib, base::size(mib), &vmtotal, &len, NULL, 0) < 0) + if (sysctl(mib, std::size(mib), &vmtotal, &len, NULL, 0) < 0) return 0; mem_total = vmtotal.t_vm; diff --git a/base/process/process_win.cc b/base/process/process_win.cc index f37a0a922923eb..fcc1ecd19e9742 100644 --- a/base/process/process_win.cc +++ b/base/process/process_win.cc @@ -186,7 +186,7 @@ Process::WaitExitStatus Process::WaitForExitOrEvent( HANDLE events[] = {Handle(), stop_event_handle.get()}; DWORD wait_result = - ::WaitForMultipleObjects(base::size(events), events, FALSE, INFINITE); + ::WaitForMultipleObjects(std::size(events), events, FALSE, INFINITE); if (wait_result == WAIT_OBJECT_0) { DWORD temp_code; // Don't clobber out-parameters in case of failure. diff --git a/base/profiler/chrome_unwind_info_android_unittest.cc b/base/profiler/chrome_unwind_info_android_unittest.cc index e33cf7c707a111..6eaeeb92cdd414 100644 --- a/base/profiler/chrome_unwind_info_android_unittest.cc +++ b/base/profiler/chrome_unwind_info_android_unittest.cc @@ -19,8 +19,8 @@ bool operator==(const FunctionTableEntry& e1, const FunctionTableEntry& e2) { e2.function_offset_table_byte_index); } -template -void ExpectSpanSizeAndContentsEqual(span actual, span expected) { +template +void ExpectSpanSizeAndContentsEqual(span actual, span expected) { EXPECT_EQ(actual.size(), expected.size()); if (actual.size() != expected.size()) { return; @@ -76,17 +76,13 @@ TEST(ChromeUnwindInfoAndroidTest, CreateUnwindInfo) { ASSERT_EQ(&data[256], reinterpret_cast( &unwind_info.unwind_instruction_table[0])); - ExpectSpanSizeAndContentsEqual(unwind_info.page_table, - make_span(page_table, size(page_table))); - ExpectSpanSizeAndContentsEqual( - unwind_info.function_table, - make_span(function_table, size(function_table))); - ExpectSpanSizeAndContentsEqual( - unwind_info.function_offset_table, - make_span(function_offset_table, size(function_offset_table))); - ExpectSpanSizeAndContentsEqual( - unwind_info.unwind_instruction_table, - make_span(unwind_instruction_table, size(unwind_instruction_table))); + ExpectSpanSizeAndContentsEqual(unwind_info.page_table, make_span(page_table)); + ExpectSpanSizeAndContentsEqual(unwind_info.function_table, + make_span(function_table)); + ExpectSpanSizeAndContentsEqual(unwind_info.function_offset_table, + make_span(function_offset_table)); + ExpectSpanSizeAndContentsEqual(unwind_info.unwind_instruction_table, + make_span(unwind_instruction_table)); } } // namespace base diff --git a/base/profiler/chrome_unwinder_android_v2_unittest.cc b/base/profiler/chrome_unwinder_android_v2_unittest.cc index b76d5d9596622c..67ea7a85a45137 100644 --- a/base/profiler/chrome_unwinder_android_v2_unittest.cc +++ b/base/profiler/chrome_unwinder_android_v2_unittest.cc @@ -1002,7 +1002,7 @@ void ExpectFramesEq(const std::vector& actual, TEST(ChromeUnwinderAndroidV2Test, TryUnwind) { const uint32_t page_table[] = {0, 2}; - const size_t number_of_pages = base::size(page_table); + const size_t number_of_pages = std::size(page_table); const size_t page_size = 1 << 17; const FunctionTableEntry function_table[] = { @@ -1044,10 +1044,10 @@ TEST(ChromeUnwinderAndroidV2Test, TryUnwind) { }; auto unwind_info = ChromeUnwindInfoAndroid{ - make_span(unwind_instruction_table, base::size(unwind_instruction_table)), - make_span(function_offset_table, base::size(function_offset_table)), - make_span(function_table, base::size(function_table)), - make_span(page_table, base::size(page_table)), + make_span(unwind_instruction_table, std::size(unwind_instruction_table)), + make_span(function_offset_table, std::size(function_offset_table)), + make_span(function_table, std::size(function_table)), + make_span(page_table, std::size(page_table)), }; ModuleCache module_cache; diff --git a/base/profiler/stack_sampling_profiler_unittest.cc b/base/profiler/stack_sampling_profiler_unittest.cc index 7e5a1452eed4dd..0f402ae637583c 100644 --- a/base/profiler/stack_sampling_profiler_unittest.cc +++ b/base/profiler/stack_sampling_profiler_unittest.cc @@ -634,7 +634,7 @@ PROFILER_TEST_F(StackSamplingProfilerTest, StopSafely) { params[1].sampling_interval = Milliseconds(1); params[1].samples_per_profile = 100000; - SampleRecordedCounter samples_recorded[size(params)]; + SampleRecordedCounter samples_recorded[std::size(params)]; ModuleCache module_cache1, module_cache2; TestProfilerInfo profiler_info0(target_thread_token, params[0], &module_cache1, &samples_recorded[0]); diff --git a/base/strings/abseil_string_number_conversions_unittest.cc b/base/strings/abseil_string_number_conversions_unittest.cc index 12e60ee43c6f39..dd8191f19e33c3 100644 --- a/base/strings/abseil_string_number_conversions_unittest.cc +++ b/base/strings/abseil_string_number_conversions_unittest.cc @@ -8,7 +8,6 @@ #include -#include "base/cxx17_backports.h" #include "base/strings/string_piece.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/abseil-cpp/absl/numeric/int128.h" @@ -93,7 +92,7 @@ TEST(AbseilStringNumberConversionsTest, HexStringToUInt128) { const char input[] = "0xc0ffee\0" "9"; - std::string input_string(input, base::size(input) - 1); + std::string input_string(input, std::size(input) - 1); absl::uint128 output; EXPECT_FALSE(HexStringToUInt128(input_string, &output)); EXPECT_EQ(0xc0ffeeU, output); diff --git a/base/strings/escape.cc b/base/strings/escape.cc index 5d832189c6fa55..23eac91f14e42b 100644 --- a/base/strings/escape.cc +++ b/base/strings/escape.cc @@ -96,7 +96,7 @@ bool UnescapeUTF8CharacterAtIndex(StringPiece escaped_text, // reach max character length number of bytes, or hit an unescaped // character. No need to check length of escaped_text, as // UnescapeUnsignedByteAtIndex checks lengths. - while (num_bytes < size(bytes) && + while (num_bytes < std::size(bytes) && UnescapeUnsignedByteAtIndex(escaped_text, index + num_bytes * 3, &bytes[num_bytes]) && CBU8_IS_TRAIL(bytes[num_bytes])) { @@ -441,4 +441,4 @@ bool ContainsEncodedBytes(StringPiece escaped_text, return false; } -} // namespace base \ No newline at end of file +} // namespace base diff --git a/base/strings/string_number_conversions_unittest.cc b/base/strings/string_number_conversions_unittest.cc index 572e9309c01e2f..8becfdefb43c6d 100644 --- a/base/strings/string_number_conversions_unittest.cc +++ b/base/strings/string_number_conversions_unittest.cc @@ -14,7 +14,6 @@ #include #include "base/bit_cast.h" -#include "base/cxx17_backports.h" #include "base/format_macros.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" @@ -155,7 +154,7 @@ TEST(StringNumberConversionsTest, StringToInt) { // embedded NUL characters. The NUL and extra data after it should be // interpreted as junk after the number. const char input[] = "6\06"; - std::string input_string(input, base::size(input) - 1); + std::string input_string(input, std::size(input) - 1); int output; EXPECT_FALSE(StringToInt(input_string, &output)); EXPECT_EQ(6, output); @@ -221,7 +220,7 @@ TEST(StringNumberConversionsTest, StringToUint) { // embedded NUL characters. The NUL and extra data after it should be // interpreted as junk after the number. const char input[] = "6\06"; - std::string input_string(input, base::size(input) - 1); + std::string input_string(input, std::size(input) - 1); unsigned output; EXPECT_FALSE(StringToUint(input_string, &output)); EXPECT_EQ(6U, output); @@ -291,7 +290,7 @@ TEST(StringNumberConversionsTest, StringToInt64) { // embedded NUL characters. The NUL and extra data after it should be // interpreted as junk after the number. const char input[] = "6\06"; - std::string input_string(input, base::size(input) - 1); + std::string input_string(input, std::size(input) - 1); int64_t output; EXPECT_FALSE(StringToInt64(input_string, &output)); EXPECT_EQ(6, output); @@ -358,7 +357,7 @@ TEST(StringNumberConversionsTest, StringToUint64) { // embedded NUL characters. The NUL and extra data after it should be // interpreted as junk after the number. const char input[] = "6\06"; - std::string input_string(input, base::size(input) - 1); + std::string input_string(input, std::size(input) - 1); uint64_t output; EXPECT_FALSE(StringToUint64(input_string, &output)); EXPECT_EQ(6U, output); @@ -427,7 +426,7 @@ TEST(StringNumberConversionsTest, StringToSizeT) { // embedded NUL characters. The NUL and extra data after it should be // interpreted as junk after the number. const char input[] = "6\06"; - std::string input_string(input, base::size(input) - 1); + std::string input_string(input, std::size(input) - 1); size_t output; EXPECT_FALSE(StringToSizeT(input_string, &output)); EXPECT_EQ(6U, output); @@ -486,7 +485,7 @@ TEST(StringNumberConversionsTest, HexStringToInt) { const char input[] = "0xc0ffee\0" "9"; - std::string input_string(input, base::size(input) - 1); + std::string input_string(input, std::size(input) - 1); int output; EXPECT_FALSE(HexStringToInt(input_string, &output)); EXPECT_EQ(0xc0ffee, output); @@ -553,7 +552,7 @@ TEST(StringNumberConversionsTest, HexStringToUInt) { const char input[] = "0xc0ffee\0" "9"; - std::string input_string(input, base::size(input) - 1); + std::string input_string(input, std::size(input) - 1); uint32_t output; EXPECT_FALSE(HexStringToUInt(input_string, &output)); EXPECT_EQ(0xc0ffeeU, output); @@ -614,7 +613,7 @@ TEST(StringNumberConversionsTest, HexStringToInt64) { const char input[] = "0xc0ffee\0" "9"; - std::string input_string(input, base::size(input) - 1); + std::string input_string(input, std::size(input) - 1); int64_t output; EXPECT_FALSE(HexStringToInt64(input_string, &output)); EXPECT_EQ(0xc0ffee, output); @@ -679,7 +678,7 @@ TEST(StringNumberConversionsTest, HexStringToUInt64) { const char input[] = "0xc0ffee\0" "9"; - std::string input_string(input, base::size(input) - 1); + std::string input_string(input, std::size(input) - 1); uint64_t output; EXPECT_FALSE(HexStringToUInt64(input_string, &output)); EXPECT_EQ(0xc0ffeeU, output); @@ -712,7 +711,7 @@ TEST(StringNumberConversionsTest, HexStringToBytesStringSpan) { 11, true}, }; - for (size_t test_i = 0; test_i < base::size(cases); ++test_i) { + for (size_t test_i = 0; test_i < std::size(cases); ++test_i) { const auto& test = cases[test_i]; std::string expected_output(test.output, test.output_len); @@ -855,7 +854,7 @@ TEST(StringNumberConversionsTest, StringToDouble) { -1.0000000000000001e-259, true}, }; - for (size_t i = 0; i < base::size(cases); ++i) { + for (size_t i = 0; i < std::size(cases); ++i) { SCOPED_TRACE( StringPrintf("case %" PRIuS " \"%s\"", i, cases[i].input.c_str())); double output; @@ -872,7 +871,7 @@ TEST(StringNumberConversionsTest, StringToDouble) { const char input[] = "3.14\0" "159"; - std::string input_string(input, base::size(input) - 1); + std::string input_string(input, std::size(input) - 1); double output; EXPECT_FALSE(StringToDouble(input_string, &output)); EXPECT_DOUBLE_EQ(3.14, output); @@ -901,12 +900,12 @@ TEST(StringNumberConversionsTest, DoubleToString) { // The following two values were seen in crashes in the wild. const char input_bytes[8] = {0, 0, 0, 0, '\xee', '\x6d', '\x73', '\x42'}; double input = 0; - memcpy(&input, input_bytes, base::size(input_bytes)); + memcpy(&input, input_bytes, std::size(input_bytes)); EXPECT_EQ("1.335179083776e+12", NumberToString(input)); const char input_bytes2[8] = {0, 0, 0, '\xa0', '\xda', '\x6c', '\x73', '\x42'}; input = 0; - memcpy(&input, input_bytes2, base::size(input_bytes2)); + memcpy(&input, input_bytes2, std::size(input_bytes2)); EXPECT_EQ("1.33489033216e+12", NumberToString(input)); } diff --git a/base/strings/string_util.cc b/base/strings/string_util.cc index 1bc53b35a16a0f..2ff7cec20b545e 100644 --- a/base/strings/string_util.cc +++ b/base/strings/string_util.cc @@ -22,7 +22,6 @@ #include #include "base/check_op.h" -#include "base/cxx17_backports.h" #include "base/no_destructor.h" #include "base/strings/string_util_internal.h" #include "base/strings/utf_string_conversion_utils.h" @@ -336,17 +335,17 @@ std::u16string FormatBytesUnlocalized(int64_t bytes) { size_t dimension = 0; const int kKilo = 1024; while (unit_amount >= kKilo && - dimension < base::size(kByteStringsUnlocalized) - 1) { + dimension < std::size(kByteStringsUnlocalized) - 1) { unit_amount /= kKilo; dimension++; } char buf[64]; if (bytes != 0 && dimension > 0 && unit_amount < 100) { - base::snprintf(buf, base::size(buf), "%.1lf%s", unit_amount, + base::snprintf(buf, std::size(buf), "%.1lf%s", unit_amount, kByteStringsUnlocalized[dimension]); } else { - base::snprintf(buf, base::size(buf), "%.0lf%s", unit_amount, + base::snprintf(buf, std::size(buf), "%.0lf%s", unit_amount, kByteStringsUnlocalized[dimension]); } diff --git a/base/strings/string_util_internal.h b/base/strings/string_util_internal.h index 9544500b799e0b..1e64412f55d4d0 100644 --- a/base/strings/string_util_internal.h +++ b/base/strings/string_util_internal.h @@ -523,7 +523,7 @@ template static std::basic_string JoinStringT(list_type parts, T sep) { - if (base::empty(parts)) + if (std::empty(parts)) return std::basic_string(); // Pre-allocate the eventual size of the string. Start with the size of all of diff --git a/base/strings/string_util_unittest.cc b/base/strings/string_util_unittest.cc index 01888cf4d383f0..e0a3f76d68e476 100644 --- a/base/strings/string_util_unittest.cc +++ b/base/strings/string_util_unittest.cc @@ -14,7 +14,6 @@ #include #include "base/bits.h" -#include "base/cxx17_backports.h" #include "base/strings/string_piece.h" #include "base/strings/utf_string_conversions.h" #include "build/build_config.h" @@ -218,14 +217,14 @@ TEST(StringUtilTest, TruncateUTF8ToByteSize) { { const char array[] = "\x00\x00\xc2\x81\xc2\x81"; - const std::string array_string(array, base::size(array)); + const std::string array_string(array, std::size(array)); EXPECT_TRUE(Truncated(array_string, 4, &output)); EXPECT_EQ(output.compare(std::string("\x00\x00\xc2\x81", 4)), 0); } { const char array[] = "\x00\xc2\x81\xc2\x81"; - const std::string array_string(array, base::size(array)); + const std::string array_string(array, std::size(array)); EXPECT_TRUE(Truncated(array_string, 4, &output)); EXPECT_EQ(output.compare(std::string("\x00\xc2\x81", 3)), 0); } @@ -292,7 +291,7 @@ TEST(StringUtilTest, TruncateUTF8ToByteSize) { { const char array[] = "\x00\x00\xfe\xff"; - const std::string array_string(array, base::size(array)); + const std::string array_string(array, std::size(array)); EXPECT_TRUE(Truncated(array_string, 4, &output)); EXPECT_EQ(output.compare(std::string("\x00\x00", 2)), 0); } @@ -306,7 +305,7 @@ TEST(StringUtilTest, TruncateUTF8ToByteSize) { } { const char array[] = "\xff\x00\x00\xfe"; - const std::string array_string(array, base::size(array)); + const std::string array_string(array, std::size(array)); EXPECT_TRUE(Truncated(array_string, 4, &output)); EXPECT_EQ(output.compare(std::string("\xff\x00\x00", 3)), 0); } @@ -536,7 +535,7 @@ TEST(StringUtilTest, IsStringASCII) { // Also, test that a non-ASCII character will be detected regardless of its // position inside the string. { - const size_t string_length = base::size(char_ascii) - 1; + const size_t string_length = std::size(char_ascii) - 1; for (size_t offset = 0; offset < 8; ++offset) { for (size_t len = 0, max_len = string_length - offset; len < max_len; ++len) { @@ -551,7 +550,7 @@ TEST(StringUtilTest, IsStringASCII) { } { - const size_t string_length = base::size(char16_ascii) - 1; + const size_t string_length = std::size(char16_ascii) - 1; for (size_t offset = 0; offset < 4; ++offset) { for (size_t len = 0, max_len = string_length - offset; len < max_len; ++len) { @@ -605,7 +604,7 @@ TEST(StringUtilTest, ConvertASCII) { L"0123ABCDwxyz \a\b\t\r\n!+,.~" }; - for (size_t i = 0; i < base::size(char_cases); ++i) { + for (size_t i = 0; i < std::size(char_cases); ++i) { EXPECT_TRUE(IsStringASCII(char_cases[i])); std::u16string utf16 = ASCIIToUTF16(char_cases[i]); EXPECT_EQ(WideToUTF16(wchar_cases[i]), utf16); @@ -624,7 +623,7 @@ TEST(StringUtilTest, ConvertASCII) { // Convert strings with an embedded NUL character. const char chars_with_nul[] = "test\0string"; - const int length_with_nul = base::size(chars_with_nul) - 1; + const int length_with_nul = std::size(chars_with_nul) - 1; std::string string_with_nul(chars_with_nul, length_with_nul); std::u16string string16_with_nul = ASCIIToUTF16(string_with_nul); EXPECT_EQ(static_cast(length_with_nul), @@ -1219,9 +1218,9 @@ TEST(StringUtilTest, LcpyTest) { { char dst[10]; wchar_t wdst[10]; - EXPECT_EQ(7U, strlcpy(dst, "abcdefg", base::size(dst))); + EXPECT_EQ(7U, strlcpy(dst, "abcdefg", std::size(dst))); EXPECT_EQ(0, memcmp(dst, "abcdefg", 8)); - EXPECT_EQ(7U, wcslcpy(wdst, L"abcdefg", base::size(wdst))); + EXPECT_EQ(7U, wcslcpy(wdst, L"abcdefg", std::size(wdst))); EXPECT_EQ(0, memcmp(wdst, L"abcdefg", sizeof(wchar_t) * 8)); } @@ -1242,9 +1241,9 @@ TEST(StringUtilTest, LcpyTest) { { char dst[8]; wchar_t wdst[8]; - EXPECT_EQ(7U, strlcpy(dst, "abcdefg", base::size(dst))); + EXPECT_EQ(7U, strlcpy(dst, "abcdefg", std::size(dst))); EXPECT_EQ(0, memcmp(dst, "abcdefg", 8)); - EXPECT_EQ(7U, wcslcpy(wdst, L"abcdefg", base::size(wdst))); + EXPECT_EQ(7U, wcslcpy(wdst, L"abcdefg", std::size(wdst))); EXPECT_EQ(0, memcmp(wdst, L"abcdefg", sizeof(wchar_t) * 8)); } @@ -1252,9 +1251,9 @@ TEST(StringUtilTest, LcpyTest) { { char dst[7]; wchar_t wdst[7]; - EXPECT_EQ(7U, strlcpy(dst, "abcdefg", base::size(dst))); + EXPECT_EQ(7U, strlcpy(dst, "abcdefg", std::size(dst))); EXPECT_EQ(0, memcmp(dst, "abcdef", 7)); - EXPECT_EQ(7U, wcslcpy(wdst, L"abcdefg", base::size(wdst))); + EXPECT_EQ(7U, wcslcpy(wdst, L"abcdefg", std::size(wdst))); EXPECT_EQ(0, memcmp(wdst, L"abcdef", sizeof(wchar_t) * 7)); } @@ -1262,9 +1261,9 @@ TEST(StringUtilTest, LcpyTest) { { char dst[3]; wchar_t wdst[3]; - EXPECT_EQ(7U, strlcpy(dst, "abcdefg", base::size(dst))); + EXPECT_EQ(7U, strlcpy(dst, "abcdefg", std::size(dst))); EXPECT_EQ(0, memcmp(dst, "ab", 3)); - EXPECT_EQ(7U, wcslcpy(wdst, L"abcdefg", base::size(wdst))); + EXPECT_EQ(7U, wcslcpy(wdst, L"abcdefg", std::size(wdst))); EXPECT_EQ(0, memcmp(wdst, L"ab", sizeof(wchar_t) * 3)); } } @@ -1504,7 +1503,7 @@ class WriteIntoTest : public testing::Test { // Using std::string(buffer.c_str()) instead of |buffer| truncates the // string at the first \0. EXPECT_EQ( - std::string(kOriginal, std::min(num_chars, base::size(kOriginal) - 1)), + std::string(kOriginal, std::min(num_chars, std::size(kOriginal) - 1)), std::string(buffer.c_str())); EXPECT_EQ(num_chars, buffer.size()); } diff --git a/base/strings/stringprintf.cc b/base/strings/stringprintf.cc index fa91ce4e37b95d..1a4048535cc5ac 100644 --- a/base/strings/stringprintf.cc +++ b/base/strings/stringprintf.cc @@ -9,7 +9,6 @@ #include -#include "base/cxx17_backports.h" #include "base/logging.h" #include "base/scoped_clear_last_error.h" #include "base/strings/string_util.h" @@ -64,17 +63,17 @@ static void StringAppendVT(std::basic_string* dst, va_copy(ap_copy, ap); base::ScopedClearLastError last_error; - int result = vsnprintfT(stack_buf, base::size(stack_buf), format, ap_copy); + int result = vsnprintfT(stack_buf, std::size(stack_buf), format, ap_copy); va_end(ap_copy); - if (result >= 0 && result < static_cast(base::size(stack_buf))) { + if (result >= 0 && result < static_cast(std::size(stack_buf))) { // It fit. dst->append(stack_buf, result); return; } // Repeatedly increase buffer size until it fits. - int mem_length = base::size(stack_buf); + int mem_length = std::size(stack_buf); while (true) { if (result < 0) { #if BUILDFLAG(IS_WIN) diff --git a/base/strings/utf_offset_string_conversions_unittest.cc b/base/strings/utf_offset_string_conversions_unittest.cc index b2526d006acdd9..aea9bd0484f28d 100644 --- a/base/strings/utf_offset_string_conversions_unittest.cc +++ b/base/strings/utf_offset_string_conversions_unittest.cc @@ -2,13 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/strings/utf_offset_string_conversions.h" + #include #include -#include "base/cxx17_backports.h" #include "base/strings/string_piece.h" -#include "base/strings/utf_offset_string_conversions.h" #include "testing/gtest/include/gtest/gtest.h" namespace base { @@ -66,7 +66,7 @@ TEST(UTFOffsetStringConversionsTest, AdjustOffset) { {{'A', 0xd800, 0xdf00, 'z'}, 3, 5}, {{'A', 0xd800, 0xdf00, 'z'}, 4, 6}, }; - for (size_t i = 0; i < base::size(utf16_to_utf8_cases); ++i) { + for (size_t i = 0; i < std::size(utf16_to_utf8_cases); ++i) { size_t offset = utf16_to_utf8_cases[i].input_offset; std::vector offsets; offsets.push_back(offset); @@ -117,8 +117,8 @@ TEST(UTFOffsetStringConversionsTest, AdjustOffsets) { adjustments.push_back(OffsetAdjuster::Adjustment(3, 3, 1)); OffsetAdjuster::AdjustOffsets(adjustments, &offsets); size_t expected_1[] = {0, 1, 2, 3, kNpos, kNpos, 4, 5, 6, 7}; - EXPECT_EQ(offsets.size(), base::size(expected_1)); - for (size_t i = 0; i < base::size(expected_1); ++i) + EXPECT_EQ(offsets.size(), std::size(expected_1)); + for (size_t i = 0; i < std::size(expected_1); ++i) EXPECT_EQ(expected_1[i], offsets[i]); } @@ -137,8 +137,8 @@ TEST(UTFOffsetStringConversionsTest, AdjustOffsets) { 0, kNpos, kNpos, 1, 2, kNpos, kNpos, kNpos, 4, 5, 6, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 10, 11, 12, 13, kNpos, kNpos, 14 }; - EXPECT_EQ(offsets.size(), base::size(expected_2)); - for (size_t i = 0; i < base::size(expected_2); ++i) + EXPECT_EQ(offsets.size(), std::size(expected_2)); + for (size_t i = 0; i < std::size(expected_2); ++i) EXPECT_EQ(expected_2[i], offsets[i]); } @@ -157,8 +157,8 @@ TEST(UTFOffsetStringConversionsTest, AdjustOffsets) { 0, kNpos, kNpos, 0, 1, kNpos, kNpos, kNpos, 5, 6, 7, 8, kNpos, kNpos, 11, 12, kNpos, 12 }; - EXPECT_EQ(offsets.size(), base::size(expected_3)); - for (size_t i = 0; i < base::size(expected_3); ++i) + EXPECT_EQ(offsets.size(), std::size(expected_3)); + for (size_t i = 0; i < std::size(expected_3); ++i) EXPECT_EQ(expected_3[i], offsets[i]); } } @@ -175,8 +175,8 @@ TEST(UTFOffsetStringConversionsTest, UnadjustOffsets) { adjustments.push_back(OffsetAdjuster::Adjustment(3, 3, 1)); OffsetAdjuster::UnadjustOffsets(adjustments, &offsets); size_t expected_1[] = {0, 1, 2, 3, 6, 7, 8, 9}; - EXPECT_EQ(offsets.size(), base::size(expected_1)); - for (size_t i = 0; i < base::size(expected_1); ++i) + EXPECT_EQ(offsets.size(), std::size(expected_1)); + for (size_t i = 0; i < std::size(expected_1); ++i) EXPECT_EQ(expected_1[i], offsets[i]); } @@ -194,8 +194,8 @@ TEST(UTFOffsetStringConversionsTest, UnadjustOffsets) { size_t expected_2[] = { 0, 3, 4, kNpos, 8, 9, 10, kNpos, kNpos, kNpos, 17, 18, 19, 20, 23 }; - EXPECT_EQ(offsets.size(), base::size(expected_2)); - for (size_t i = 0; i < base::size(expected_2); ++i) + EXPECT_EQ(offsets.size(), std::size(expected_2)); + for (size_t i = 0; i < std::size(expected_2); ++i) EXPECT_EQ(expected_2[i], offsets[i]); } @@ -215,8 +215,8 @@ TEST(UTFOffsetStringConversionsTest, UnadjustOffsets) { 4, kNpos, kNpos, kNpos, 8, 9, 10, 11, kNpos, kNpos, 14, 15 // this could just as easily be 17 }; - EXPECT_EQ(offsets.size(), base::size(expected_3)); - for (size_t i = 0; i < base::size(expected_3); ++i) + EXPECT_EQ(offsets.size(), std::size(expected_3)); + for (size_t i = 0; i < std::size(expected_3); ++i) EXPECT_EQ(expected_3[i], offsets[i]); } } diff --git a/base/strings/utf_string_conversions_unittest.cc b/base/strings/utf_string_conversions_unittest.cc index bdf9e7de5cb7f2..30550409635547 100644 --- a/base/strings/utf_string_conversions_unittest.cc +++ b/base/strings/utf_string_conversions_unittest.cc @@ -2,12 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/strings/utf_string_conversions.h" + #include -#include "base/cxx17_backports.h" #include "base/strings/string_piece.h" #include "base/strings/string_util.h" -#include "base/strings/utf_string_conversions.h" #include "build/build_config.h" #include "testing/gtest/include/gtest/gtest.h" @@ -189,14 +189,14 @@ TEST(UTFStringConversionsTest, ConvertMultiString) { '\0' }; std::u16string multistring16; - memcpy(WriteInto(&multistring16, base::size(multi16)), multi16, + memcpy(WriteInto(&multistring16, std::size(multi16)), multi16, sizeof(multi16)); - EXPECT_EQ(base::size(multi16) - 1, multistring16.length()); + EXPECT_EQ(std::size(multi16) - 1, multistring16.length()); std::string expected; - memcpy(WriteInto(&expected, base::size(multi)), multi, sizeof(multi)); - EXPECT_EQ(base::size(multi) - 1, expected.length()); + memcpy(WriteInto(&expected, std::size(multi)), multi, sizeof(multi)); + EXPECT_EQ(std::size(multi) - 1, expected.length()); const std::string& converted = UTF16ToUTF8(multistring16); - EXPECT_EQ(base::size(multi) - 1, converted.length()); + EXPECT_EQ(std::size(multi) - 1, converted.length()); EXPECT_EQ(expected, converted); } diff --git a/base/sync_socket_win.cc b/base/sync_socket_win.cc index b5dd24247fc36f..b35f8f31c0fda6 100644 --- a/base/sync_socket_win.cc +++ b/base/sync_socket_win.cc @@ -7,7 +7,6 @@ #include #include -#include "base/cxx17_backports.h" #include "base/logging.h" #include "base/rand_util.h" #include "base/threading/scoped_blocking_call.h" @@ -22,7 +21,7 @@ namespace { // in sandboxed scenarios as we might have by-name policies that allow pipe // creation. Also keep the secure random number generation. const wchar_t kPipeNameFormat[] = L"\\\\.\\pipe\\chrome.sync.%u.%u.%lu"; -const size_t kPipePathMax = base::size(kPipeNameFormat) + (3 * 10) + 1; +const size_t kPipePathMax = std::size(kPipeNameFormat) + (3 * 10) + 1; // To avoid users sending negative message lengths to Send/Receive // we clamp message lengths, which are size_t, to no more than INT_MAX. @@ -154,7 +153,7 @@ size_t CancelableFileOperation(Function operation, if (::GetLastError() == ERROR_IO_PENDING) { HANDLE events[] = { io_event->handle(), cancel_event->handle() }; const int wait_result = WaitForMultipleObjects( - base::size(events), events, FALSE, + std::size(events), events, FALSE, timeout_in_ms == INFINITE ? timeout_in_ms : static_cast( diff --git a/base/system/sys_info_chromeos.cc b/base/system/sys_info_chromeos.cc index 188552e6f1ebf9..fba0a0d6ab90a0 100644 --- a/base/system/sys_info_chromeos.cc +++ b/base/system/sys_info_chromeos.cc @@ -8,7 +8,6 @@ #include #include -#include "base/cxx17_backports.h" #include "base/environment.h" #include "base/files/file.h" #include "base/files/file_path.h" @@ -117,7 +116,7 @@ class ChromeOSVersionInfo { } // Parse the version from the first matching recognized version key. std::string version; - for (size_t i = 0; i < base::size(kLinuxStandardBaseVersionKeys); ++i) { + for (size_t i = 0; i < std::size(kLinuxStandardBaseVersionKeys); ++i) { std::string key = kLinuxStandardBaseVersionKeys[i]; if (GetLsbReleaseValue(key, &version) && !version.empty()) break; @@ -136,7 +135,7 @@ class ChromeOSVersionInfo { // Check release name for Chrome OS. std::string release_name; if (GetLsbReleaseValue(kChromeOsReleaseNameKey, &release_name)) { - for (size_t i = 0; i < base::size(kChromeOsReleaseNames); ++i) { + for (size_t i = 0; i < std::size(kChromeOsReleaseNames); ++i) { if (release_name == kChromeOsReleaseNames[i]) { is_running_on_chromeos_ = true; break; diff --git a/base/system/sys_info_ios.mm b/base/system/sys_info_ios.mm index 3bb3fd57320565..e278a18cdd5e0c 100644 --- a/base/system/sys_info_ios.mm +++ b/base/system/sys_info_ios.mm @@ -12,7 +12,6 @@ #include #include "base/check_op.h" -#include "base/cxx17_backports.h" #include "base/mac/scoped_mach_port.h" #include "base/notreached.h" #include "base/process/process_metrics.h" @@ -29,7 +28,7 @@ // system or the empty string on failure. std::string GetSysctlValue(const char* key_name) { char value[256]; - size_t len = base::size(value); + size_t len = std::size(value); if (sysctlbyname(key_name, &value, &len, nullptr, 0) == 0) { DCHECK_GE(len, 1u); DCHECK_EQ('\0', value[len - 1]); diff --git a/base/system/sys_info_mac.mm b/base/system/sys_info_mac.mm index c67480eb01c957..dc52dea129e85c 100644 --- a/base/system/sys_info_mac.mm +++ b/base/system/sys_info_mac.mm @@ -13,7 +13,6 @@ #include #include "base/check_op.h" -#include "base/cxx17_backports.h" #include "base/mac/mac_util.h" #include "base/mac/scoped_mach_port.h" #include "base/notreached.h" @@ -29,7 +28,7 @@ // system or the empty string on failure. std::string GetSysctlValue(const char* key_name) { char value[256]; - size_t len = base::size(value); + size_t len = std::size(value); if (sysctlbyname(key_name, &value, &len, nullptr, 0) == 0) { DCHECK_GE(len, 1u); DCHECK_EQ('\0', value[len - 1]); diff --git a/base/system/sys_info_openbsd.cc b/base/system/sys_info_openbsd.cc index 7f98054b924b36..8849960622414a 100644 --- a/base/system/sys_info_openbsd.cc +++ b/base/system/sys_info_openbsd.cc @@ -10,7 +10,6 @@ #include #include -#include "base/cxx17_backports.h" #include "base/notreached.h" namespace { @@ -34,7 +33,7 @@ int SysInfo::NumberOfProcessors() { int mib[] = {CTL_HW, HW_NCPU}; int ncpu; size_t size = sizeof(ncpu); - if (sysctl(mib, base::size(mib), &ncpu, &size, NULL, 0) < 0) { + if (sysctl(mib, std::size(mib), &ncpu, &size, NULL, 0) < 0) { NOTREACHED(); return 1; } @@ -58,7 +57,7 @@ uint64_t SysInfo::MaxSharedMemorySize() { int mib[] = {CTL_KERN, KERN_SHMINFO, KERN_SHMINFO_SHMMAX}; size_t limit; size_t size = sizeof(limit); - if (sysctl(mib, base::size(mib), &limit, &size, NULL, 0) < 0) { + if (sysctl(mib, std::size(mib), &limit, &size, NULL, 0) < 0) { NOTREACHED(); return 0; } @@ -69,8 +68,8 @@ uint64_t SysInfo::MaxSharedMemorySize() { std::string SysInfo::CPUModelName() { int mib[] = {CTL_HW, HW_MODEL}; char name[256]; - size_t len = base::size(name); - if (sysctl(mib, base::size(mib), name, &len, NULL, 0) < 0) { + size_t len = std::size(name); + if (sysctl(mib, std::size(mib), name, &len, NULL, 0) < 0) { NOTREACHED(); return std::string(); } diff --git a/base/task/sequence_manager/thread_controller_with_message_pump_impl_unittest.cc b/base/task/sequence_manager/thread_controller_with_message_pump_impl_unittest.cc index cd6081e6eb5a1b..7ce212d2689d97 100644 --- a/base/task/sequence_manager/thread_controller_with_message_pump_impl_unittest.cc +++ b/base/task/sequence_manager/thread_controller_with_message_pump_impl_unittest.cc @@ -902,9 +902,9 @@ TEST_F(ThreadControllerWithMessagePumpTest, // "ThreadController active" state at the end. for (auto& t : tasks) task_source_.AddTask(FROM_HERE, t.Get(), TimeTicks()); - for (size_t i = 0; i < size(tasks); ++i) { + for (size_t i = 0; i < std::size(tasks); ++i) { const TimeTicks expected_delayed_run_time = - i < size(tasks) - 1 ? TimeTicks() : TimeTicks::Max(); + i < std::size(tasks) - 1 ? TimeTicks() : TimeTicks::Max(); EXPECT_CALL(tasks[i], Run()); EXPECT_EQ(thread_controller_.DoWork().delayed_run_time, diff --git a/base/task/thread_pool/pooled_single_thread_task_runner_manager.cc b/base/task/thread_pool/pooled_single_thread_task_runner_manager.cc index a6c3172d0e6882..66f0f40c400323 100644 --- a/base/task/thread_pool/pooled_single_thread_task_runner_manager.cc +++ b/base/task/thread_pool/pooled_single_thread_task_runner_manager.cc @@ -10,7 +10,6 @@ #include "base/bind.h" #include "base/callback.h" -#include "base/cxx17_backports.h" #include "base/memory/ptr_util.h" #include "base/memory/raw_ptr.h" #include "base/ranges/algorithm.h" @@ -758,8 +757,8 @@ void PooledSingleThreadTaskRunnerManager::ReleaseSharedWorkerThreads() { #endif { CheckedAutoLock auto_lock(lock_); - for (size_t i = 0; i < base::size(shared_worker_threads_); ++i) { - for (size_t j = 0; j < base::size(shared_worker_threads_[i]); ++j) { + for (size_t i = 0; i < std::size(shared_worker_threads_); ++i) { + for (size_t j = 0; j < std::size(shared_worker_threads_[i]); ++j) { local_shared_worker_threads[i][j] = shared_worker_threads_[i][j]; shared_worker_threads_[i][j] = nullptr; #if BUILDFLAG(IS_WIN) @@ -771,8 +770,8 @@ void PooledSingleThreadTaskRunnerManager::ReleaseSharedWorkerThreads() { } } - for (size_t i = 0; i < base::size(local_shared_worker_threads); ++i) { - for (size_t j = 0; j < base::size(local_shared_worker_threads[i]); ++j) { + for (size_t i = 0; i < std::size(local_shared_worker_threads); ++i) { + for (size_t j = 0; j < std::size(local_shared_worker_threads[i]); ++j) { if (local_shared_worker_threads[i][j]) UnregisterWorkerThread(local_shared_worker_threads[i][j]); #if BUILDFLAG(IS_WIN) diff --git a/base/task/thread_pool/task_tracker.cc b/base/task/thread_pool/task_tracker.cc index cf270422f49f8d..61cc19c71bb5a9 100644 --- a/base/task/thread_pool/task_tracker.cc +++ b/base/task/thread_pool/task_tracker.cc @@ -45,7 +45,7 @@ using perfetto::protos::pbzero::ChromeTrackEvent; constexpr const char* kExecutionModeString[] = {"parallel", "sequenced", "single thread", "job"}; static_assert( - size(kExecutionModeString) == + std::size(kExecutionModeString) == static_cast(TaskSourceExecutionMode::kMax) + 1, "Array kExecutionModeString is out of sync with TaskSourceExecutionMode."); diff --git a/base/threading/hang_watcher.cc b/base/threading/hang_watcher.cc index 771879fd6e16e0..5cb6b27db86d77 100644 --- a/base/threading/hang_watcher.cc +++ b/base/threading/hang_watcher.cc @@ -446,7 +446,7 @@ HangWatcher::GetTimeSinceLastCriticalMemoryPressureCrashKey() { if (last_critical_memory_pressure_time.is_null()) { constexpr char kNoMemoryPressureMsg[] = "No critical memory pressure"; static_assert( - base::size(kNoMemoryPressureMsg) <= + std::size(kNoMemoryPressureMsg) <= static_cast(kCrashKeyContentSize), "The crash key is too small to hold \"No critical memory pressure\"."); return debug::ScopedCrashKeyString(crash_key, kNoMemoryPressureMsg); diff --git a/base/threading/platform_thread_unittest.cc b/base/threading/platform_thread_unittest.cc index 397afea3123d38..33082ac4f43461 100644 --- a/base/threading/platform_thread_unittest.cc +++ b/base/threading/platform_thread_unittest.cc @@ -2,14 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/threading/platform_thread.h" + #include #include "base/compiler_specific.h" -#include "base/cxx17_backports.h" #include "base/process/process.h" #include "base/synchronization/waitable_event.h" #include "base/test/scoped_feature_list.h" -#include "base/threading/platform_thread.h" #include "base/threading/threading_features.h" #include "build/build_config.h" #include "testing/gtest/include/gtest/gtest.h" @@ -74,11 +74,11 @@ TEST(PlatformThreadTest, TrivialJoin) { TEST(PlatformThreadTest, TrivialJoinTimesTen) { TrivialThread thread[10]; - PlatformThreadHandle handle[base::size(thread)]; + PlatformThreadHandle handle[std::size(thread)]; for (auto& n : thread) ASSERT_FALSE(n.run_event().IsSignaled()); - for (size_t n = 0; n < base::size(thread); n++) + for (size_t n = 0; n < std::size(thread); n++) ASSERT_TRUE(PlatformThread::Create(0, &thread[n], &handle[n])); for (auto n : handle) PlatformThread::Join(n); @@ -101,11 +101,11 @@ TEST(PlatformThreadTest, TrivialDetach) { TEST(PlatformThreadTest, TrivialDetachTimesTen) { TrivialThread thread[10]; - PlatformThreadHandle handle[base::size(thread)]; + PlatformThreadHandle handle[std::size(thread)]; for (auto& n : thread) ASSERT_FALSE(n.run_event().IsSignaled()); - for (size_t n = 0; n < base::size(thread); n++) { + for (size_t n = 0; n < std::size(thread); n++) { ASSERT_TRUE(PlatformThread::Create(0, &thread[n], &handle[n])); PlatformThread::Detach(handle[n]); } @@ -209,17 +209,17 @@ TEST(PlatformThreadTest, FunctionTimesTen) { PlatformThreadId main_thread_id = PlatformThread::CurrentId(); FunctionTestThread thread[10]; - PlatformThreadHandle handle[base::size(thread)]; + PlatformThreadHandle handle[std::size(thread)]; for (const auto& n : thread) ASSERT_FALSE(n.IsRunning()); - for (size_t n = 0; n < base::size(thread); n++) + for (size_t n = 0; n < std::size(thread); n++) ASSERT_TRUE(PlatformThread::Create(0, &thread[n], &handle[n])); for (auto& n : thread) n.WaitForTerminationReady(); - for (size_t n = 0; n < base::size(thread); n++) { + for (size_t n = 0; n < std::size(thread); n++) { ASSERT_TRUE(thread[n].IsRunning()); EXPECT_NE(thread[n].thread_id(), main_thread_id); diff --git a/base/threading/sequence_local_storage_slot_unittest.cc b/base/threading/sequence_local_storage_slot_unittest.cc index 487f0e631c3b3c..17f43c7f00975e 100644 --- a/base/threading/sequence_local_storage_slot_unittest.cc +++ b/base/threading/sequence_local_storage_slot_unittest.cc @@ -6,7 +6,6 @@ #include -#include "base/cxx17_backports.h" #include "base/memory/ptr_util.h" #include "base/threading/sequence_local_storage_map.h" #include "testing/gtest/include/gtest/gtest.h" @@ -133,14 +132,14 @@ TEST(SequenceLocalStorageSlotMultipleMapTest, EmplaceGetMultipleMapsOneSlot) { // Set the value of the slot to be the index of the current // SequenceLocalStorageMaps in the vector - for (unsigned int i = 0; i < base::size(sequence_local_storage_maps); ++i) { + for (unsigned int i = 0; i < std::size(sequence_local_storage_maps); ++i) { internal::ScopedSetSequenceLocalStorageMapForCurrentThread scoped_sequence_local_storage(&sequence_local_storage_maps[i]); slot.emplace(i); } - for (unsigned int i = 0; i < base::size(sequence_local_storage_maps); ++i) { + for (unsigned int i = 0; i < std::size(sequence_local_storage_maps); ++i) { internal::ScopedSetSequenceLocalStorageMapForCurrentThread scoped_sequence_local_storage(&sequence_local_storage_maps[i]); diff --git a/base/time/pr_time_unittest.cc b/base/time/pr_time_unittest.cc index d319384cb95677..0952bacdbe8698 100644 --- a/base/time/pr_time_unittest.cc +++ b/base/time/pr_time_unittest.cc @@ -6,7 +6,6 @@ #include #include "base/compiler_specific.h" -#include "base/cxx17_backports.h" #include "base/third_party/nspr/prtime.h" #include "base/time/time.h" #include "build/build_config.h" @@ -79,7 +78,7 @@ TEST_F(PRTimeTest, ParseTimeTest1) { char time_buf[64] = {}; #if BUILDFLAG(IS_WIN) localtime_s(&local_time, ¤t_time); - asctime_s(time_buf, base::size(time_buf), &local_time); + asctime_s(time_buf, std::size(time_buf), &local_time); #elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) localtime_r(¤t_time, &local_time); asctime_r(&local_time, time_buf); diff --git a/base/time/time_mac.mm b/base/time/time_mac.mm index 1a1a44c674b9c9..51f602b86b96d9 100644 --- a/base/time/time_mac.mm +++ b/base/time/time_mac.mm @@ -14,7 +14,6 @@ #include #include -#include "base/cxx17_backports.h" #include "base/logging.h" #include "base/mac/mach_logging.h" #include "base/mac/scoped_cftyperef.h" @@ -108,7 +107,7 @@ int64_t ComputeCurrentTicks() { struct timeval boottime; int mib[2] = {CTL_KERN, KERN_BOOTTIME}; size_t size = sizeof(boottime); - int kr = sysctl(mib, base::size(mib), &boottime, &size, nullptr, 0); + int kr = sysctl(mib, std::size(mib), &boottime, &size, nullptr, 0); DCHECK_EQ(KERN_SUCCESS, kr); base::TimeDelta time_difference = base::subtle::TimeNowIgnoringOverride() - (base::Time::FromTimeT(boottime.tv_sec) + diff --git a/base/time/time_unittest.cc b/base/time/time_unittest.cc index 9fc050141eb0b1..92971a9ef5632a 100644 --- a/base/time/time_unittest.cc +++ b/base/time/time_unittest.cc @@ -13,7 +13,6 @@ #include "base/build_time.h" #include "base/check_op.h" #include "base/compiler_specific.h" -#include "base/cxx17_backports.h" #include "base/environment.h" #include "base/test/gtest_util.h" #include "base/threading/platform_thread.h" @@ -478,7 +477,7 @@ TEST_F(TimeTest, ParseTimeTest1) { char time_buf[64] = {}; #if BUILDFLAG(IS_WIN) localtime_s(&local_time, ¤t_time); - asctime_s(time_buf, base::size(time_buf), &local_time); + asctime_s(time_buf, std::size(time_buf), &local_time); #elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) localtime_r(¤t_time, &local_time); asctime_r(&local_time, time_buf); diff --git a/base/trace_event/builtin_categories.h b/base/trace_event/builtin_categories.h index 107516329273ee..083a46a96bf969 100644 --- a/base/trace_event/builtin_categories.h +++ b/base/trace_event/builtin_categories.h @@ -5,8 +5,10 @@ #ifndef BASE_TRACE_EVENT_BUILTIN_CATEGORIES_H_ #define BASE_TRACE_EVENT_BUILTIN_CATEGORIES_H_ +#include +#include + #include "base/base_export.h" -#include "base/cxx17_backports.h" #include "base/trace_event/common/trace_event_common.h" #include "base/tracing_buildflags.h" #include "build/build_config.h" @@ -420,9 +422,7 @@ class BASE_EXPORT BuiltinCategories { } // Returns the amount of built-in categories in the registry. - static constexpr size_t Size() { - return base::size(kBuiltinCategories); - } + static constexpr size_t Size() { return std::size(kBuiltinCategories); } // Where in the builtin category list to start when populating the // about://tracing UI. @@ -526,13 +526,13 @@ class BASE_EXPORT BuiltinCategories { // Returns whether |category| is used only for testing. static constexpr bool IsCategoryForTesting(const char* category) { return IsStringInArray(category, kCategoriesForTesting, - base::size(kCategoriesForTesting)); + std::size(kCategoriesForTesting)); } // Returns whether |category| is registered in the builtin list. static constexpr bool IsBuiltinCategory(const char* category) { return IsStringInArray(category, kBuiltinCategories, - base::size(kBuiltinCategories)); + std::size(kBuiltinCategories)); } }; diff --git a/base/trace_event/heap_profiler_allocation_context_tracker.cc b/base/trace_event/heap_profiler_allocation_context_tracker.cc index 8901a901a8b23e..1c0a6c5b327b17 100644 --- a/base/trace_event/heap_profiler_allocation_context_tracker.cc +++ b/base/trace_event/heap_profiler_allocation_context_tracker.cc @@ -12,7 +12,6 @@ #include "base/atomicops.h" #include "base/check_op.h" -#include "base/cxx17_backports.h" #include "base/debug/debugging_buildflags.h" #include "base/debug/leak_annotations.h" #include "base/debug/stack_trace.h" @@ -197,17 +196,17 @@ bool AllocationContextTracker::GetContextSnapshot(AllocationContext* ctx) { #if !BUILDFLAG(IS_NACL) // We don't build base/debug/stack_trace.cc for NaCl. #if BUILDFLAG(IS_ANDROID) && BUILDFLAG(CAN_UNWIND_WITH_CFI_TABLE) const void* frames[Backtrace::kMaxFrameCount + 1]; - static_assert(base::size(frames) >= Backtrace::kMaxFrameCount, + static_assert(std::size(frames) >= Backtrace::kMaxFrameCount, "not requesting enough frames to fill Backtrace"); size_t frame_count = CFIBacktraceAndroid::GetInitializedInstance()->Unwind( - frames, base::size(frames)); + frames, std::size(frames)); #elif BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS) const void* frames[Backtrace::kMaxFrameCount + 1]; - static_assert(base::size(frames) >= Backtrace::kMaxFrameCount, + static_assert(std::size(frames) >= Backtrace::kMaxFrameCount, "not requesting enough frames to fill Backtrace"); size_t frame_count = debug::TraceStackFramePointers( - frames, base::size(frames), + frames, std::size(frames), 1 /* exclude this function from the trace */); #else // Fall-back to capturing the stack with base::debug::StackTrace, diff --git a/base/trace_event/memory_dump_manager.cc b/base/trace_event/memory_dump_manager.cc index 2bf5b8e4639cb5..d4a18dda57f3f4 100644 --- a/base/trace_event/memory_dump_manager.cc +++ b/base/trace_event/memory_dump_manager.cc @@ -296,7 +296,7 @@ MemoryDumpManager::GetOrCreateBgTaskRunnerLocked() { void MemoryDumpManager::CreateProcessDump(const MemoryDumpRequestArgs& args, ProcessMemoryDumpCallback callback) { char guid_str[20]; - snprintf(guid_str, base::size(guid_str), "0x%" PRIx64, args.dump_guid); + snprintf(guid_str, std::size(guid_str), "0x%" PRIx64, args.dump_guid); TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(kTraceCategory, "ProcessMemoryDump", TRACE_ID_LOCAL(args.dump_guid), "dump_guid", TRACE_STR_COPY(guid_str)); diff --git a/base/values.cc b/base/values.cc index fcb00bfc31c4b2..9c87c811fb4854 100644 --- a/base/values.cc +++ b/base/values.cc @@ -45,7 +45,7 @@ namespace { const char* const kTypeNames[] = {"null", "boolean", "integer", "double", "string", "binary", "dictionary", "list"}; -static_assert(base::size(kTypeNames) == +static_assert(std::size(kTypeNames) == static_cast(Value::Type::LIST) + 1, "kTypeNames Has Wrong Size"); @@ -295,7 +295,7 @@ Value::~Value() = default; // static const char* Value::GetTypeName(Value::Type type) { DCHECK_GE(static_cast(type), 0); - DCHECK_LT(static_cast(type), base::size(kTypeNames)); + DCHECK_LT(static_cast(type), std::size(kTypeNames)); return kTypeNames[static_cast(type)]; } @@ -1837,7 +1837,7 @@ std::ostream& operator<<(std::ostream& out, const Value::List& list) { std::ostream& operator<<(std::ostream& out, const Value::Type& type) { if (static_cast(type) < 0 || - static_cast(type) >= base::size(kTypeNames)) + static_cast(type) >= std::size(kTypeNames)) return out << "Invalid Type (index = " << static_cast(type) << ")"; return out << Value::GetTypeName(type); } diff --git a/base/vlog.cc b/base/vlog.cc index dbef83136ce931..9ee90cebdf4dfb 100644 --- a/base/vlog.cc +++ b/base/vlog.cc @@ -9,7 +9,6 @@ #include #include -#include "base/cxx17_backports.h" #include "base/logging.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_split.h" @@ -93,7 +92,7 @@ base::StringPiece GetModule(base::StringPiece file) { base::StringPiece::size_type extension_start = module.rfind('.'); module = module.substr(0, extension_start); static const char kInlSuffix[] = "-inl"; - static const int kInlSuffixLen = base::size(kInlSuffix) - 1; + static const int kInlSuffixLen = std::size(kInlSuffix) - 1; if (base::EndsWith(module, kInlSuffix)) module.remove_suffix(kInlSuffixLen); return module; diff --git a/base/win/access_token.cc b/base/win/access_token.cc index 89c3ccb52cb8bb..0e34b82cf55de8 100644 --- a/base/win/access_token.cc +++ b/base/win/access_token.cc @@ -6,7 +6,6 @@ #include -#include "base/cxx17_backports.h" #include "base/strings/stringprintf.h" namespace base { @@ -117,7 +116,7 @@ std::wstring AccessToken::Privilege::GetName() const { LUID luid; luid.LowPart = luid_.LowPart; luid.HighPart = luid_.HighPart; - DWORD size = base::size(name); + DWORD size = std::size(name); if (!::LookupPrivilegeName(nullptr, &luid, name, &size)) return base::StringPrintf(L"%08X-%08X", luid.HighPart, luid.LowPart); return name; diff --git a/base/win/i18n.cc b/base/win/i18n.cc index 851da4da957025..d03ab9380897c5 100644 --- a/base/win/i18n.cc +++ b/base/win/i18n.cc @@ -33,7 +33,7 @@ bool GetPreferredUILanguageList(GetPreferredUILanguages_Fn function, } std::wstring buffer(buffer_length, '\0'); - if (!function(call_flags, &language_count, base::data(buffer), + if (!function(call_flags, &language_count, std::data(buffer), &buffer_length) || !language_count) { DPCHECK(!language_count) << "Failed getting preferred UI languages."; diff --git a/base/win/scoped_process_information_unittest.cc b/base/win/scoped_process_information_unittest.cc index 0800e17cbf51af..631856ac056752 100644 --- a/base/win/scoped_process_information_unittest.cc +++ b/base/win/scoped_process_information_unittest.cc @@ -55,7 +55,7 @@ void ScopedProcessInformationTest::DoCreateProcess( STARTUPINFO startup_info = {}; startup_info.cb = sizeof(startup_info); - EXPECT_TRUE(::CreateProcess(nullptr, base::data(cmd_line), nullptr, nullptr, + EXPECT_TRUE(::CreateProcess(nullptr, std::data(cmd_line), nullptr, nullptr, false, 0, nullptr, nullptr, &startup_info, process_handle)); } diff --git a/base/win/shortcut_unittest.cc b/base/win/shortcut_unittest.cc index f97b0049a5272b..c4b7efb2f22013 100644 --- a/base/win/shortcut_unittest.cc +++ b/base/win/shortcut_unittest.cc @@ -8,7 +8,6 @@ #include -#include "base/cxx17_backports.h" #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" @@ -39,7 +38,7 @@ class ShortcutTest : public testing::Test { { const FilePath target_file( temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Target 1.txt"))); - WriteFile(target_file, kFileContents, base::size(kFileContents)); + WriteFile(target_file, kFileContents, std::size(kFileContents)); link_properties_.set_target(target_file); link_properties_.set_working_dir(temp_dir_.GetPath()); @@ -62,7 +61,7 @@ class ShortcutTest : public testing::Test { { const FilePath target_file_2( temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Target 2.txt"))); - WriteFile(target_file_2, kFileContents2, base::size(kFileContents2)); + WriteFile(target_file_2, kFileContents2, std::size(kFileContents2)); FilePath icon_path_2; CreateTemporaryFileInDir(temp_dir_.GetPath(), &icon_path_2); @@ -160,8 +159,8 @@ TEST_F(ShortcutTest, CreateAndResolveShortcut) { FilePath resolved_name; EXPECT_TRUE(ResolveShortcut(link_file_, &resolved_name, nullptr)); - char read_contents[base::size(kFileContents)]; - base::ReadFile(resolved_name, read_contents, base::size(read_contents)); + char read_contents[std::size(kFileContents)]; + base::ReadFile(resolved_name, read_contents, std::size(read_contents)); EXPECT_STREQ(kFileContents, read_contents); } @@ -177,8 +176,8 @@ TEST_F(ShortcutTest, ResolveShortcutWithArgs) { std::wstring args; EXPECT_TRUE(ResolveShortcut(link_file_, &resolved_name, &args)); - char read_contents[base::size(kFileContents)]; - base::ReadFile(resolved_name, read_contents, base::size(read_contents)); + char read_contents[std::size(kFileContents)]; + base::ReadFile(resolved_name, read_contents, std::size(read_contents)); EXPECT_STREQ(kFileContents, read_contents); EXPECT_EQ(link_properties_.arguments, args); } @@ -244,8 +243,8 @@ TEST_F(ShortcutTest, UpdateShortcutUpdateOnlyTargetAndResolve) { FilePath resolved_name; EXPECT_TRUE(ResolveShortcut(link_file_, &resolved_name, nullptr)); - char read_contents[base::size(kFileContents2)]; - base::ReadFile(resolved_name, read_contents, base::size(read_contents)); + char read_contents[std::size(kFileContents2)]; + base::ReadFile(resolved_name, read_contents, std::size(read_contents)); EXPECT_STREQ(kFileContents2, read_contents); } diff --git a/base/win/win_util_unittest.cc b/base/win/win_util_unittest.cc index 1972d5dee96d84..10c7ea53025d77 100644 --- a/base/win/win_util_unittest.cc +++ b/base/win/win_util_unittest.cc @@ -7,7 +7,6 @@ #include #include "base/containers/contains.h" -#include "base/cxx17_backports.h" #include "base/files/file_path.h" #include "base/scoped_native_library.h" #include "base/strings/string_util.h" @@ -84,7 +83,7 @@ TEST(BaseWinUtilTest, WStringFromGUID) { auto guid_wstring = WStringFromGUID(kGuid); EXPECT_EQ(guid_wstring, kGuidStr); wchar_t guid_wchar[39]; - ::StringFromGUID2(kGuid, guid_wchar, base::size(guid_wchar)); + ::StringFromGUID2(kGuid, guid_wchar, std::size(guid_wchar)); EXPECT_STREQ(guid_wstring.c_str(), guid_wchar); ScopedCoMem clsid_string; ::StringFromCLSID(kGuid, &clsid_string); diff --git a/chrome/browser/ash/power/auto_screen_brightness/gaussian_trainer.cc b/chrome/browser/ash/power/auto_screen_brightness/gaussian_trainer.cc index 44ee6c4c924b6a..c1c13ba27363dd 100644 --- a/chrome/browser/ash/power/auto_screen_brightness/gaussian_trainer.cc +++ b/chrome/browser/ash/power/auto_screen_brightness/gaussian_trainer.cc @@ -9,6 +9,7 @@ #include #include "ash/constants/ash_features.h" +#include "base/cxx17_backports.h" #include "base/logging.h" #include "base/metrics/field_trial_params.h" #include "base/metrics/histogram_functions.h" diff --git a/media/capture/video/chromeos/camera_app_device_impl.cc b/media/capture/video/chromeos/camera_app_device_impl.cc index 8164864945d1b4..c70d144bfa67aa 100644 --- a/media/capture/video/chromeos/camera_app_device_impl.cc +++ b/media/capture/video/chromeos/camera_app_device_impl.cc @@ -6,6 +6,7 @@ #include +#include "base/cxx17_backports.h" #include "base/task/bind_post_task.h" #include "base/time/time.h" #include "gpu/ipc/common/gpu_memory_buffer_impl.h" diff --git a/media/gpu/vaapi/test/vp8_decoder.cc b/media/gpu/vaapi/test/vp8_decoder.cc index 39cbfe236e163b..57fcd3f6c17976 100644 --- a/media/gpu/vaapi/test/vp8_decoder.cc +++ b/media/gpu/vaapi/test/vp8_decoder.cc @@ -7,6 +7,7 @@ #include #include +#include "base/cxx17_backports.h" #include "media/filters/ivf_parser.h" #include "media/gpu/vaapi/test/macros.h" #include "media/parsers/vp8_parser.h"