Skip to content

Commit

Permalink
fix some warning
Browse files Browse the repository at this point in the history
  • Loading branch information
oathdruid committed Aug 23, 2024
1 parent 6d2a1eb commit a97a3f6
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 68 deletions.
10 changes: 6 additions & 4 deletions copts.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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': [],
})
8 changes: 4 additions & 4 deletions src/babylon/anyflow/builtin/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,11 +523,11 @@ struct ConditionalExpression
struct NonConditionalExpression
: public grammar<const char*, space_type, ::std::tuple<size_t, size_t>()> {
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] =
Expand Down
6 changes: 3 additions & 3 deletions src/babylon/application_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ BABYLON_NAMESPACE_BEGIN
////////////////////////////////////////////////////////////////////////////////
// ApplicationContext::OffsetDeleter begin
void ApplicationContext::OffsetDeleter::operator()(void* ptr) noexcept {
if (deleter) {
auto address = reinterpret_cast<intptr_t>(ptr) + offset;
deleter(reinterpret_cast<void*>(address));
if (_deleter) {
auto address = reinterpret_cast<intptr_t>(ptr) + _offset;
_deleter(reinterpret_cast<void*>(address));
}
}
// ApplicationContext::OffsetDeleter end
Expand Down
6 changes: 3 additions & 3 deletions src/babylon/application_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
////////////////////////////////////////////////////////////////////////////////

Expand Down
12 changes: 6 additions & 6 deletions src/babylon/concurrent/bounded_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,10 +554,10 @@ inline size_t ConcurrentBoundedQueue<T, S>::try_push_n(C&& callback,
return try_deal_n_continuously<CONCURRENT, USE_FUTEX_WAKE, true>(
::std::forward<C>(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<CONCURRENT, USE_FUTEX_WAKE, true>(
::std::forward<C>(callback), index, num);
if (pushed < num) {
::std::forward<C>(callback), index, continuous_num);
if (pushed < continuous_num) {
return pushed;
}
return pushed + try_deal_n_continuously<CONCURRENT, USE_FUTEX_WAKE, true>(
Expand Down Expand Up @@ -714,10 +714,10 @@ inline size_t ConcurrentBoundedQueue<T, S>::try_pop_n(C&& callback,
return try_deal_n_continuously<CONCURRENT, USE_FUTEX_WAKE, false>(
::std::forward<C>(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<CONCURRENT, USE_FUTEX_WAKE, false>(
::std::forward<C>(callback), index, num);
if (poped < num) {
::std::forward<C>(callback), index, continuous_num);
if (poped < continuous_num) {
return poped;
}
return poped + try_deal_n_continuously<CONCURRENT, USE_FUTEX_WAKE, false>(
Expand Down
6 changes: 3 additions & 3 deletions src/babylon/concurrent/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ inline void ConcurrentVector<T, BLOCK_SIZE>::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;
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/babylon/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ AlwaysUseNewThreadExecutor& AlwaysUseNewThreadExecutor::instance() noexcept {
int AlwaysUseNewThreadExecutor::invoke(
MoveOnlyFunction<void(void)>&& function) noexcept {
::std::thread(::std::bind(
[](MoveOnlyFunction<void(void)>& function) {
function();
[](MoveOnlyFunction<void(void)>& captured_function) {
captured_function();
},
::std::move(function)))
.detach();
Expand Down
12 changes: 6 additions & 6 deletions src/babylon/executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ inline Future<typename InvokeResult<C, Args...>::type, F> Executor::execute(
Promise<R, F> promise;
auto future = promise.get_future();
MoveOnlyFunction<void(void)> function {::std::bind(
[](Promise<R, F>& promise, DC& callable,
typename ::std::decay<Args>::type&... args) {
run_and_set(promise, normalize(::std::move(callable)),
::std::move(args)...);
[](Promise<R, F>& captured_promise, DC& captured_callable,
typename ::std::decay<Args>::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<C>(callable)),
Expand All @@ -35,8 +35,8 @@ template <typename C, typename... Args>
inline int Executor::submit(C&& callable, Args&&... args) noexcept {
typedef typename ::std::decay<C>::type DC;
MoveOnlyFunction<void(void)> function {::std::bind(
[](DC& callable, typename ::std::decay<Args>::type&... args) {
normalize(::std::move(callable))(::std::move(args)...);
[](DC& captured_callable, typename ::std::decay<Args>::type&... captured_args) {
normalize(::std::move(captured_callable))(::std::move(captured_args)...);
},
uncomposable_bind_argument(::std::forward<C>(callable)),
uncomposable_bind_argument(::std::forward<Args>(args))...)};
Expand Down
4 changes: 2 additions & 2 deletions src/babylon/logging/log_entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class LogEntry {
::std::vector<struct ::iovec>& 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<struct ::iovec>& 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<struct ::iovec>& iov) noexcept;

Expand Down
8 changes: 4 additions & 4 deletions src/babylon/move_only_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ inline R MoveOnlyFunction<R(Args...)>::operator()(Args... args) const {
////////////////////////////////////////////////////////////////////////////////
// UncomposableBindArgument begin
template <typename T>
inline UncomposableBindArgument<T>::UncomposableBindArgument(T&& value)
: value(::std::move(value)) {}
inline UncomposableBindArgument<T>::UncomposableBindArgument(T&& input_value)
: value(::std::move(input_value)) {}

template <typename T>
inline UncomposableBindArgument<T>::UncomposableBindArgument(const T& value)
: value(value) {}
inline UncomposableBindArgument<T>::UncomposableBindArgument(const T& input_value)
: value(input_value) {}

template <typename T>
inline UncomposableBindArgument<T>::operator T&() noexcept {
Expand Down
16 changes: 8 additions & 8 deletions src/babylon/reusable/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/babylon/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions test/concurrent/test_garbage_collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ struct GarbageCollectorTest : public ::testing::Test {
Reclaimer& operator=(Reclaimer&&) = default;

Reclaimer(::std::promise<void>&& 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<void> promise;
::std::promise<void> _promise;
};

virtual void SetUp() override {
Expand Down
4 changes: 2 additions & 2 deletions test/reusable/test_memory_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions test/test_any.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/test_future.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Promise<::std::string>> promises;
::std::vector<Future<::std::string>> futures;
Expand Down
12 changes: 6 additions & 6 deletions test/test_move_only_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions test/test_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char&>(size);
return reinterpret_cast<char&>(_size);
}
size_t size {0};
size_t _size {0};
} s;
ASSERT_EQ(7 + 25, *reinterpret_cast<size_t*>(resize_uninitialized(s, 7)));
ASSERT_EQ(12 + 25, *reinterpret_cast<size_t*>(resize_uninitialized(s, 12)));
Expand All @@ -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<char*>(size);
return *reinterpret_cast<char*>(_size);
}
size_t size;
size_t _size;
} s;
ASSERT_EQ(7, reinterpret_cast<intptr_t>(resize_uninitialized(s, 7)));
ASSERT_EQ(12, reinterpret_cast<intptr_t>(resize_uninitialized(s, 12)));
Expand Down

0 comments on commit a97a3f6

Please sign in to comment.