From a97a3f65b4698e280af5d138fcda1101f48021de Mon Sep 17 00:00:00 2001 From: Kevin Li Date: Fri, 23 Aug 2024 16:34:36 +0800 Subject: [PATCH] fix some warning --- copts.bzl | 10 ++++++---- src/babylon/anyflow/builtin/expression.cpp | 8 ++++---- src/babylon/application_context.cpp | 6 +++--- src/babylon/application_context.h | 6 +++--- src/babylon/concurrent/bounded_queue.hpp | 12 ++++++------ src/babylon/concurrent/vector.hpp | 6 +++--- src/babylon/executor.cpp | 4 ++-- src/babylon/executor.hpp | 12 ++++++------ src/babylon/logging/log_entry.h | 4 ++-- src/babylon/move_only_function.hpp | 8 ++++---- src/babylon/reusable/message.cpp | 16 ++++++++-------- src/babylon/type_traits.hpp | 2 +- test/concurrent/test_garbage_collector.cpp | 6 +++--- test/reusable/test_memory_resource.cpp | 4 ++-- test/test_any.cpp | 8 ++++---- test/test_future.cpp | 2 +- test/test_move_only_function.cpp | 12 ++++++------ test/test_string.cpp | 12 ++++++------ 18 files changed, 70 insertions(+), 68 deletions(-) diff --git a/copts.bzl b/copts.bzl index 92a9ea06..92a43f41 100644 --- a/copts.bzl +++ b/copts.bzl @@ -20,9 +20,9 @@ BABYLON_CLANG_COPTS = ['-faligned-new', '-Weverything', '-Wno-unknown-warning-op # 但是这个场景下的隐藏本身是无害的,目前也还没有很好的方法做命名区分 '-Wno-shadow-field', # TODO(lijiang01): 逐步梳理清除 - '-Wno-shadow-field-in-constructor', '-Wno-gnu-anonymous-struct', '-Wno-nested-anon-types', - '-Wno-shadow-uncaptured-local', '-Wno-weak-vtables', '-Wno-float-conversion', '-Wno-switch-enum', - '-Wno-shadow', '-Wno-array-bounds-pointer-arithmetic', '-Wno-cast-align', '-Wno-vla-extension', + '-Wno-weak-vtables', '-Wno-float-conversion', '-Wno-switch-enum', + '-Wno-gnu-anonymous-struct', '-Wno-nested-anon-types', + '-Wno-array-bounds-pointer-arithmetic', '-Wno-cast-align', '-Wno-vla-extension', '-Wno-unneeded-member-function', '-Wno-deprecated-declarations'] BABYLON_COPTS = select({ @@ -44,7 +44,9 @@ BABYLON_TEST_COPTS = BABYLON_COPTS + select({ # 跨符号转换对单测自身并无大碍,且可以简化单测实现 '-Wno-sign-conversion', # googletest-1.15开始使用了c++17属性 - '-Wno-c++17-attribute-extensions' + '-Wno-c++17-attribute-extensions', + # 单测中使用了一些变量简写有意进行了无害隐藏 + '-Wno-shadow', ], '//conditions:default': [], }) diff --git a/src/babylon/anyflow/builtin/expression.cpp b/src/babylon/anyflow/builtin/expression.cpp index e31d87bb..3dffb1a5 100644 --- a/src/babylon/anyflow/builtin/expression.cpp +++ b/src/babylon/anyflow/builtin/expression.cpp @@ -523,11 +523,11 @@ struct ConditionalExpression struct NonConditionalExpression : public grammar()> { NonConditionalExpression( - expression::Option& option, - ::std::unordered_map<::std::string, size_t>& variable_indexes) noexcept + expression::Option& input_option, + ::std::unordered_map<::std::string, size_t>& input_variable_indexes) noexcept : base_type(start, "non_conditional_expression"), - option(option), - variable_indexes(variable_indexes) { + option(input_option), + variable_indexes(input_variable_indexes) { start = expression[0].alias(); expression[0] = expression[12].alias(); expression[12] = diff --git a/src/babylon/application_context.cpp b/src/babylon/application_context.cpp index 1d4e46a5..d906c33a 100644 --- a/src/babylon/application_context.cpp +++ b/src/babylon/application_context.cpp @@ -7,9 +7,9 @@ BABYLON_NAMESPACE_BEGIN //////////////////////////////////////////////////////////////////////////////// // ApplicationContext::OffsetDeleter begin void ApplicationContext::OffsetDeleter::operator()(void* ptr) noexcept { - if (deleter) { - auto address = reinterpret_cast(ptr) + offset; - deleter(reinterpret_cast(address)); + if (_deleter) { + auto address = reinterpret_cast(ptr) + _offset; + _deleter(reinterpret_cast(address)); } } // ApplicationContext::OffsetDeleter end diff --git a/src/babylon/application_context.h b/src/babylon/application_context.h index 0d8d9789..d47a34dd 100644 --- a/src/babylon/application_context.h +++ b/src/babylon/application_context.h @@ -135,8 +135,8 @@ class ApplicationContext::OffsetDeleter { void operator()(void* ptr) noexcept; private: - void (*deleter)(void*) {nullptr}; - ptrdiff_t offset {0}; + void (*_deleter)(void*) {nullptr}; + ptrdiff_t _offset {0}; }; class ApplicationContext::ComponentHolder { @@ -421,7 +421,7 @@ inline ApplicationContext::OffsetDeleter::OffsetDeleter( inline ApplicationContext::OffsetDeleter::OffsetDeleter( void (*deleter)(void*), ptrdiff_t offset) noexcept - : deleter {deleter}, offset {offset} {} + : _deleter {deleter}, _offset {offset} {} // ApplicationContext::OffsetDeleter end //////////////////////////////////////////////////////////////////////////////// diff --git a/src/babylon/concurrent/bounded_queue.hpp b/src/babylon/concurrent/bounded_queue.hpp index 6c9e77d0..b67a9d49 100644 --- a/src/babylon/concurrent/bounded_queue.hpp +++ b/src/babylon/concurrent/bounded_queue.hpp @@ -554,10 +554,10 @@ inline size_t ConcurrentBoundedQueue::try_push_n(C&& callback, return try_deal_n_continuously( ::std::forward(callback), index, end_index - index); } else { - size_t num = next_round_begin_index - index; + size_t continuous_num = next_round_begin_index - index; size_t pushed = try_deal_n_continuously( - ::std::forward(callback), index, num); - if (pushed < num) { + ::std::forward(callback), index, continuous_num); + if (pushed < continuous_num) { return pushed; } return pushed + try_deal_n_continuously( @@ -714,10 +714,10 @@ inline size_t ConcurrentBoundedQueue::try_pop_n(C&& callback, return try_deal_n_continuously( ::std::forward(callback), index, end_index - index); } else { - size_t num = next_round_begin_index - index; + size_t continuous_num = next_round_begin_index - index; size_t poped = try_deal_n_continuously( - ::std::forward(callback), index, num); - if (poped < num) { + ::std::forward(callback), index, continuous_num); + if (poped < continuous_num) { return poped; } return poped + try_deal_n_continuously( diff --git a/src/babylon/concurrent/vector.hpp b/src/babylon/concurrent/vector.hpp index f17d6df3..01b94f76 100644 --- a/src/babylon/concurrent/vector.hpp +++ b/src/babylon/concurrent/vector.hpp @@ -188,9 +188,9 @@ inline void ConcurrentVector::Snapshot::copy_n(IT begin, size_t size, size_t offset) { for_each(offset, offset + size, [&](T* iter, T* end) { - auto size = end - iter; - ::std::copy_n(begin, size, iter); - begin += size; + auto num = end - iter; + ::std::copy_n(begin, num, iter); + begin += num; }); } diff --git a/src/babylon/executor.cpp b/src/babylon/executor.cpp index fd35db08..d80e182b 100644 --- a/src/babylon/executor.cpp +++ b/src/babylon/executor.cpp @@ -68,8 +68,8 @@ AlwaysUseNewThreadExecutor& AlwaysUseNewThreadExecutor::instance() noexcept { int AlwaysUseNewThreadExecutor::invoke( MoveOnlyFunction&& function) noexcept { ::std::thread(::std::bind( - [](MoveOnlyFunction& function) { - function(); + [](MoveOnlyFunction& captured_function) { + captured_function(); }, ::std::move(function))) .detach(); diff --git a/src/babylon/executor.hpp b/src/babylon/executor.hpp index 6563f914..61c59c73 100644 --- a/src/babylon/executor.hpp +++ b/src/babylon/executor.hpp @@ -16,10 +16,10 @@ inline Future::type, F> Executor::execute( Promise promise; auto future = promise.get_future(); MoveOnlyFunction function {::std::bind( - [](Promise& promise, DC& callable, - typename ::std::decay::type&... args) { - run_and_set(promise, normalize(::std::move(callable)), - ::std::move(args)...); + [](Promise& captured_promise, DC& captured_callable, + typename ::std::decay::type&... captured_args) { + run_and_set(captured_promise, normalize(::std::move(captured_callable)), + ::std::move(captured_args)...); }, ::std::move(promise), uncomposable_bind_argument(::std::forward(callable)), @@ -35,8 +35,8 @@ template inline int Executor::submit(C&& callable, Args&&... args) noexcept { typedef typename ::std::decay::type DC; MoveOnlyFunction function {::std::bind( - [](DC& callable, typename ::std::decay::type&... args) { - normalize(::std::move(callable))(::std::move(args)...); + [](DC& captured_callable, typename ::std::decay::type&... captured_args) { + normalize(::std::move(captured_callable))(::std::move(captured_args)...); }, uncomposable_bind_argument(::std::forward(callable)), uncomposable_bind_argument(::std::forward(args))...)}; diff --git a/src/babylon/logging/log_entry.h b/src/babylon/logging/log_entry.h index 3576b948..c0a33acc 100644 --- a/src/babylon/logging/log_entry.h +++ b/src/babylon/logging/log_entry.h @@ -31,9 +31,9 @@ class LogEntry { ::std::vector& iov) noexcept; private: - void pages_append_to_iovec(char** pages, size_t size, size_t page_size, + static void pages_append_to_iovec(char** pages, size_t size, size_t page_size, ::std::vector& iov) noexcept; - void page_table_append_to_iovec(PageTable& page_table, size_t size, + static void page_table_append_to_iovec(PageTable& page_table, size_t size, size_t page_size, ::std::vector& iov) noexcept; diff --git a/src/babylon/move_only_function.hpp b/src/babylon/move_only_function.hpp index 50f44f1f..1ee0c8e4 100644 --- a/src/babylon/move_only_function.hpp +++ b/src/babylon/move_only_function.hpp @@ -80,12 +80,12 @@ inline R MoveOnlyFunction::operator()(Args... args) const { //////////////////////////////////////////////////////////////////////////////// // UncomposableBindArgument begin template -inline UncomposableBindArgument::UncomposableBindArgument(T&& value) - : value(::std::move(value)) {} +inline UncomposableBindArgument::UncomposableBindArgument(T&& input_value) + : value(::std::move(input_value)) {} template -inline UncomposableBindArgument::UncomposableBindArgument(const T& value) - : value(value) {} +inline UncomposableBindArgument::UncomposableBindArgument(const T& input_value) + : value(input_value) {} template inline UncomposableBindArgument::operator T&() noexcept { diff --git a/src/babylon/reusable/message.cpp b/src/babylon/reusable/message.cpp index 075ce73c..d7cd3749 100644 --- a/src/babylon/reusable/message.cpp +++ b/src/babylon/reusable/message.cpp @@ -29,18 +29,18 @@ void MessageAllocationMetadata::reserve( } MessageAllocationMetadata::FieldAllocationMetadata::FieldAllocationMetadata( - const ::google::protobuf::FieldDescriptor* descriptor) noexcept - : descriptor(descriptor) {} + const ::google::protobuf::FieldDescriptor* input_descriptor) noexcept + : descriptor(input_descriptor) {} MessageAllocationMetadata::FieldAllocationMetadata::FieldAllocationMetadata( - const ::google::protobuf::FieldDescriptor* descriptor, - const ::google::protobuf::Message* default_message) noexcept - : descriptor(descriptor), default_message(default_message) {} + const ::google::protobuf::FieldDescriptor* input_descriptor, + const ::google::protobuf::Message* input_default_message) noexcept + : descriptor(input_descriptor), default_message(input_default_message) {} MessageAllocationMetadata::FieldAllocationMetadata::FieldAllocationMetadata( - const ::google::protobuf::FieldDescriptor* descriptor, - const ::std::string* default_string) noexcept - : descriptor(descriptor), default_string(default_string) {} + const ::google::protobuf::FieldDescriptor* input_descriptor, + const ::std::string* input_default_string) noexcept + : descriptor(input_descriptor), default_string(input_default_string) {} void MessageAllocationMetadata::FieldAllocationMetadata::update( const ::google::protobuf::Message& message, diff --git a/src/babylon/type_traits.hpp b/src/babylon/type_traits.hpp index aa82c292..3824742a 100644 --- a/src/babylon/type_traits.hpp +++ b/src/babylon/type_traits.hpp @@ -17,7 +17,7 @@ BABYLON_NAMESPACE_BEGIN /////////////////////////////////////////////////////////////////////////////// // Id begin -inline constexpr Id::Id(StringView name) noexcept : name {name} {} +inline constexpr Id::Id(StringView name_value) noexcept : name {name_value} {} inline constexpr bool Id::operator==(const Id& other) const noexcept { return this == &other; diff --git a/test/concurrent/test_garbage_collector.cpp b/test/concurrent/test_garbage_collector.cpp index 9c8b32cd..a4152062 100644 --- a/test/concurrent/test_garbage_collector.cpp +++ b/test/concurrent/test_garbage_collector.cpp @@ -15,16 +15,16 @@ struct GarbageCollectorTest : public ::testing::Test { Reclaimer& operator=(Reclaimer&&) = default; Reclaimer(::std::promise&& promise) - : promise {::std::move(promise)} {} + : _promise {::std::move(promise)} {} void operator()() noexcept { times++; - promise.set_value(); + _promise.set_value(); } static size_t times; - ::std::promise promise; + ::std::promise _promise; }; virtual void SetUp() override { diff --git a/test/reusable/test_memory_resource.cpp b/test/reusable/test_memory_resource.cpp index ba61cab4..eb52e412 100644 --- a/test/reusable/test_memory_resource.cpp +++ b/test/reusable/test_memory_resource.cpp @@ -346,8 +346,8 @@ TEST(SwissMemoryResource, compatible_with_protobuf_in_asan_mode) { // 反复reserve会触发protobuf 4.x的重用功能 // 内部有对应的asan poison标记动作 // 验证和MemoryResource的标记可兼容 - for (int i = 0; i < 10; ++i) { - message->mutable_m()->add_rp(i); + for (int k = 0; k < 10; ++k) { + message->mutable_m()->add_rp(k); } } } diff --git a/test/test_any.cpp b/test/test_any.cpp index d4a3add2..6dae0496 100644 --- a/test/test_any.cpp +++ b/test/test_any.cpp @@ -153,12 +153,12 @@ TEST(any, create_with_or_without_value) { TEST(any, reusable) { struct S { - S(size_t& destruct_num) : destruct_num(destruct_num) {} - S(const S& other) : destruct_num(other.destruct_num) {} + S(size_t& destruct_num) : _destruct_num(destruct_num) {} + S(const S& other) : _destruct_num(other._destruct_num) {} ~S() { - destruct_num++; + _destruct_num++; } - size_t& destruct_num; + size_t& _destruct_num; }; size_t destruct_num = 0; S obj(destruct_num); diff --git a/test/test_future.cpp b/test/test_future.cpp index a491fb1f..73ee5f33 100644 --- a/test/test_future.cpp +++ b/test/test_future.cpp @@ -297,7 +297,7 @@ TEST(future, concurrent_works_fine) { ::std::to_string(step_two_value[i])); } - for (size_t i = 0; i < times; ++i) { + for (size_t j = 0; j < times; ++j) { ::std::vector<::std::thread> threads; ::std::vector> promises; ::std::vector> futures; diff --git a/test/test_move_only_function.cpp b/test/test_move_only_function.cpp index eebcc519..4d31a8f6 100644 --- a/test/test_move_only_function.cpp +++ b/test/test_move_only_function.cpp @@ -60,12 +60,12 @@ TEST(move_only_function, construct_from_moveable_callable_only) { TEST(move_only_function, callable_move_with_function) { typedef MoveOnlyFunction<::std::string(::std::string)> MOF; struct S { - S(::std::string prefix) : prefix(prefix) {} + S(::std::string prefix) : _prefix(prefix) {} ::std::string operator()(::std::string value) { - prefix += value; - return prefix; + _prefix += value; + return _prefix; } - ::std::string prefix; + ::std::string _prefix; }; { S s("10086"); @@ -165,8 +165,8 @@ TEST(move_only_function, result_forward_out) { // NRVO { auto s = MOF([]() { - S s; - return s; + S obj; + return obj; })(); ASSERT_EQ(0, s.copy); ASSERT_EQ(0, s.move); diff --git a/test/test_string.cpp b/test/test_string.cpp index 4058073d..a3c48c85 100644 --- a/test/test_string.cpp +++ b/test/test_string.cpp @@ -73,12 +73,12 @@ TEST(string, recognize_string_with_resize) { typedef char* pointer; typedef size_t size_type; void resize(size_t size) { - this->size = size + 25; + _size = size + 25; } char& operator[](size_t) { - return reinterpret_cast(size); + return reinterpret_cast(_size); } - size_t size {0}; + size_t _size {0}; } s; ASSERT_EQ(7 + 25, *reinterpret_cast(resize_uninitialized(s, 7))); ASSERT_EQ(12 + 25, *reinterpret_cast(resize_uninitialized(s, 12))); @@ -89,12 +89,12 @@ TEST(string, recognize_string_with_resize_default_init_function) { typedef char* pointer; typedef size_t size_type; void __resize_default_init(size_t size) { - this->size = size; + _size = size; } char& operator[](int) { - return *reinterpret_cast(size); + return *reinterpret_cast(_size); } - size_t size; + size_t _size; } s; ASSERT_EQ(7, reinterpret_cast(resize_uninitialized(s, 7))); ASSERT_EQ(12, reinterpret_cast(resize_uninitialized(s, 12)));