Skip to content

Commit

Permalink
enable clang-tidy readability-static-definition-in-anonymous-namespac…
Browse files Browse the repository at this point in the history
…e check (grpc#28033)
  • Loading branch information
markdroth authored Nov 17, 2021
1 parent 2ea8e50 commit 1050eed
Show file tree
Hide file tree
Showing 26 changed files with 78 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
# - readability-else-after-return
# - readability-implicit-bool-conversion
# - readability-redundant-declaration
# - readability-static-definition-in-anonymous-namespace
#
Checks: '-*,
abseil-*,
Expand Down Expand Up @@ -115,6 +114,7 @@ Checks: '-*,
readability-redundant-function-ptr-dereference,
readability-redundant-smartptr-get,
readability-simplify-boolean-expr,
readability-static-definition-in-anonymous-namespace,
readability-string-compare,
readability-uniqueptr-delete-release'
WarningsAsErrors: '*'
Expand Down
2 changes: 1 addition & 1 deletion src/core/ext/filters/client_channel/resolver_registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class RegistryState {
UniquePtr<char> default_prefix_;
};

static RegistryState* g_state = nullptr;
RegistryState* g_state = nullptr;

} // namespace

Expand Down
8 changes: 4 additions & 4 deletions src/core/ext/transport/chttp2/transport/flow_control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ bool g_test_only_transport_flow_control_window_check;

namespace {

static constexpr const int kTracePadding = 30;
static constexpr const int64_t kMaxWindowUpdateSize = (1u << 31) - 1;
constexpr const int kTracePadding = 30;
constexpr const int64_t kMaxWindowUpdateSize = (1u << 31) - 1;

static char* fmt_int64_diff_str(int64_t old_val, int64_t new_val) {
char* fmt_int64_diff_str(int64_t old_val, int64_t new_val) {
std::string str;
if (old_val != new_val) {
str = absl::StrFormat("%" PRId64 " -> %" PRId64 "", old_val, new_val);
Expand All @@ -60,7 +60,7 @@ static char* fmt_int64_diff_str(int64_t old_val, int64_t new_val) {
return gpr_leftpad(str.c_str(), ' ', kTracePadding);
}

static char* fmt_uint32_diff_str(uint32_t old_val, uint32_t new_val) {
char* fmt_uint32_diff_str(uint32_t old_val, uint32_t new_val) {
std::string str;
if (old_val != new_val) {
str = absl::StrFormat("%" PRIu32 " -> %" PRIu32 "", old_val, new_val);
Expand Down
4 changes: 2 additions & 2 deletions src/core/ext/transport/chttp2/transport/hpack_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ static const int16_t emit_sub_tbl[249 * 16] = {

namespace {
// The alphabet used for base64 encoding binary metadata.
static constexpr char kBase64Alphabet[] =
constexpr char kBase64Alphabet[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

// An inverted table: for each value in kBase64Alphabet, table contains the
Expand All @@ -448,7 +448,7 @@ struct Base64InverseTable {
}
};

static GRPC_HPACK_CONSTEXPR_VALUE Base64InverseTable kBase64InverseTable;
GRPC_HPACK_CONSTEXPR_VALUE Base64InverseTable kBase64InverseTable;
} // namespace

// Input tracks the current byte through the input data and provides it
Expand Down
2 changes: 1 addition & 1 deletion src/core/ext/xds/certificate_provider_registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class RegistryState {
factories_;
};

static RegistryState* g_state = nullptr;
RegistryState* g_state = nullptr;

} // namespace

Expand Down
2 changes: 1 addition & 1 deletion src/core/lib/iomgr/buffer_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void extract_opt_stats_from_cmsg(ConnectionMetrics* metrics,
}
}

static int get_socket_tcp_info(tcp_info* info, int fd) {
int get_socket_tcp_info(tcp_info* info, int fd) {
memset(info, 0, sizeof(*info));
info->length = offsetof(tcp_info, length);
return getsockopt(fd, IPPROTO_TCP, TCP_INFO, info, &(info->length));
Expand Down
2 changes: 1 addition & 1 deletion src/core/lib/iomgr/call_combiner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ DebugOnlyTraceFlag grpc_call_combiner_trace(false, "call_combiner");
namespace {

// grpc_error LSB can be used
constexpr static intptr_t kErrorBit = 1;
constexpr intptr_t kErrorBit = 1;

grpc_error_handle DecodeCancelStateError(gpr_atm cancel_state) {
if (cancel_state & kErrorBit) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/lib/iomgr/executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
namespace grpc_core {
namespace {

static GPR_THREAD_LOCAL(ThreadState*) g_this_thread_state;
GPR_THREAD_LOCAL(ThreadState*) g_this_thread_state;

Executor* executors[static_cast<size_t>(ExecutorType::NUM_EXECUTORS)];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,9 @@ class grpc_fake_channel_security_connector final
char* target_name_override_;
};

static void fake_check_peer(
grpc_security_connector* /*sc*/, tsi_peer peer,
grpc_core::RefCountedPtr<grpc_auth_context>* auth_context,
grpc_closure* on_peer_checked) {
void fake_check_peer(grpc_security_connector* /*sc*/, tsi_peer peer,
grpc_core::RefCountedPtr<grpc_auth_context>* auth_context,
grpc_closure* on_peer_checked) {
const char* prop_name;
grpc_error_handle error = GRPC_ERROR_NONE;
*auth_context = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions src/core/lib/slice/percent_encoding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class UrlTable : public BitSet<256> {
}
};

static GRPC_PCTENCODE_CONSTEXPR_VALUE UrlTable g_url_table;
GRPC_PCTENCODE_CONSTEXPR_VALUE UrlTable g_url_table;

class CompatibleTable : public BitSet<256> {
public:
Expand All @@ -63,7 +63,7 @@ class CompatibleTable : public BitSet<256> {
}
};

static GRPC_PCTENCODE_CONSTEXPR_VALUE CompatibleTable g_compatible_table;
GRPC_PCTENCODE_CONSTEXPR_VALUE CompatibleTable g_compatible_table;

// Map PercentEncodingType to a lookup table of legal symbols for that encoding.
const BitSet<256>& LookupTableForPercentEncodingType(PercentEncodingType type) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/lib/surface/completion_queue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ namespace {
// with a cq cache will go into that cache, and
// will only be returned on the thread that initialized the cache.
// NOTE: Only one event will ever be cached.
static GPR_THREAD_LOCAL(grpc_cq_completion*) g_cached_event;
static GPR_THREAD_LOCAL(grpc_completion_queue*) g_cached_cq;
GPR_THREAD_LOCAL(grpc_cq_completion*) g_cached_event;
GPR_THREAD_LOCAL(grpc_completion_queue*) g_cached_cq;

struct plucker {
grpc_pollset_worker** worker;
Expand Down
28 changes: 14 additions & 14 deletions src/core/lib/surface/lame_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@ struct CallData {
CallCombiner* call_combiner;
};

static void lame_start_transport_stream_op_batch(
grpc_call_element* elem, grpc_transport_stream_op_batch* op) {
void lame_start_transport_stream_op_batch(grpc_call_element* elem,
grpc_transport_stream_op_batch* op) {
CallData* calld = static_cast<CallData*>(elem->call_data);
ChannelData* chand = static_cast<ChannelData*>(elem->channel_data);
grpc_transport_stream_op_batch_finish_with_failure(
op, GRPC_ERROR_REF(chand->error), calld->call_combiner);
}

static void lame_get_channel_info(grpc_channel_element* /*elem*/,
const grpc_channel_info* /*channel_info*/) {}
void lame_get_channel_info(grpc_channel_element* /*elem*/,
const grpc_channel_info* /*channel_info*/) {}

static void lame_start_transport_op(grpc_channel_element* elem,
grpc_transport_op* op) {
void lame_start_transport_op(grpc_channel_element* elem,
grpc_transport_op* op) {
ChannelData* chand = static_cast<ChannelData*>(elem->channel_data);
{
MutexLock lock(&chand->mu);
Expand All @@ -100,26 +100,26 @@ static void lame_start_transport_op(grpc_channel_element* elem,
}
}

static grpc_error_handle lame_init_call_elem(
grpc_call_element* elem, const grpc_call_element_args* args) {
grpc_error_handle lame_init_call_elem(grpc_call_element* elem,
const grpc_call_element_args* args) {
CallData* calld = static_cast<CallData*>(elem->call_data);
calld->call_combiner = args->call_combiner;
return GRPC_ERROR_NONE;
}

static void lame_destroy_call_elem(grpc_call_element* /*elem*/,
const grpc_call_final_info* /*final_info*/,
grpc_closure* then_schedule_closure) {
void lame_destroy_call_elem(grpc_call_element* /*elem*/,
const grpc_call_final_info* /*final_info*/,
grpc_closure* then_schedule_closure) {
ExecCtx::Run(DEBUG_LOCATION, then_schedule_closure, GRPC_ERROR_NONE);
}

static grpc_error_handle lame_init_channel_elem(
grpc_channel_element* elem, grpc_channel_element_args* args) {
grpc_error_handle lame_init_channel_elem(grpc_channel_element* elem,
grpc_channel_element_args* args) {
new (elem->channel_data) ChannelData(args);
return GRPC_ERROR_NONE;
}

static void lame_destroy_channel_elem(grpc_channel_element* elem) {
void lame_destroy_channel_elem(grpc_channel_element* elem) {
ChannelData* chand = static_cast<ChannelData*>(elem->channel_data);
chand->~ChannelData();
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/lib/surface/validate_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class LegalHeaderKeyBits : public grpc_core::BitSet<256> {
set('.');
}
};
static GRPC_VALIDATE_METADATA_CONSTEXPR_VALUE LegalHeaderKeyBits
GRPC_VALIDATE_METADATA_CONSTEXPR_VALUE LegalHeaderKeyBits
g_legal_header_key_bits;
} // namespace

Expand Down Expand Up @@ -112,7 +112,7 @@ class LegalHeaderNonBinValueBits : public grpc_core::BitSet<256> {
}
}
};
static GRPC_VALIDATE_METADATA_CONSTEXPR_VALUE LegalHeaderNonBinValueBits
GRPC_VALIDATE_METADATA_CONSTEXPR_VALUE LegalHeaderNonBinValueBits
g_legal_header_non_bin_value_bits;
} // namespace

Expand Down
30 changes: 15 additions & 15 deletions src/core/tsi/local_transport_security.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,21 @@ typedef struct local_tsi_handshaker {

/* --- tsi_handshaker_result methods implementation. --- */

static tsi_result handshaker_result_extract_peer(
const tsi_handshaker_result* /*self*/, tsi_peer* /*peer*/) {
tsi_result handshaker_result_extract_peer(const tsi_handshaker_result* /*self*/,
tsi_peer* /*peer*/) {
return TSI_OK;
}

static tsi_result handshaker_result_get_frame_protector_type(
tsi_result handshaker_result_get_frame_protector_type(
const tsi_handshaker_result* /*self*/,
tsi_frame_protector_type* frame_protector_type) {
*frame_protector_type = TSI_FRAME_PROTECTOR_NONE;
return TSI_OK;
}

static tsi_result handshaker_result_get_unused_bytes(
const tsi_handshaker_result* self, const unsigned char** bytes,
size_t* bytes_size) {
tsi_result handshaker_result_get_unused_bytes(const tsi_handshaker_result* self,
const unsigned char** bytes,
size_t* bytes_size) {
if (self == nullptr || bytes == nullptr || bytes_size == nullptr) {
gpr_log(GPR_ERROR, "Invalid arguments to get_unused_bytes()");
return TSI_INVALID_ARGUMENT;
Expand All @@ -80,7 +80,7 @@ static tsi_result handshaker_result_get_unused_bytes(
return TSI_OK;
}

static void handshaker_result_destroy(tsi_handshaker_result* self) {
void handshaker_result_destroy(tsi_handshaker_result* self) {
if (self == nullptr) {
return;
}
Expand All @@ -91,18 +91,18 @@ static void handshaker_result_destroy(tsi_handshaker_result* self) {
gpr_free(result);
}

static const tsi_handshaker_result_vtable result_vtable = {
const tsi_handshaker_result_vtable result_vtable = {
handshaker_result_extract_peer,
handshaker_result_get_frame_protector_type,
nullptr, /* handshaker_result_create_zero_copy_grpc_protector */
nullptr, /* handshaker_result_create_frame_protector */
handshaker_result_get_unused_bytes,
handshaker_result_destroy};

static tsi_result create_handshaker_result(bool is_client,
const unsigned char* received_bytes,
size_t received_bytes_size,
tsi_handshaker_result** self) {
tsi_result create_handshaker_result(bool is_client,
const unsigned char* received_bytes,
size_t received_bytes_size,
tsi_handshaker_result** self) {
if (self == nullptr) {
gpr_log(GPR_ERROR, "Invalid arguments to create_handshaker_result()");
return TSI_INVALID_ARGUMENT;
Expand All @@ -123,7 +123,7 @@ static tsi_result create_handshaker_result(bool is_client,

/* --- tsi_handshaker methods implementation. --- */

static tsi_result handshaker_next(
tsi_result handshaker_next(
tsi_handshaker* self, const unsigned char* received_bytes,
size_t received_bytes_size, const unsigned char** /*bytes_to_send*/,
size_t* bytes_to_send_size, tsi_handshaker_result** result,
Expand All @@ -143,7 +143,7 @@ static tsi_result handshaker_next(
return TSI_OK;
}

static void handshaker_destroy(tsi_handshaker* self) {
void handshaker_destroy(tsi_handshaker* self) {
if (self == nullptr) {
return;
}
Expand All @@ -152,7 +152,7 @@ static void handshaker_destroy(tsi_handshaker* self) {
gpr_free(handshaker);
}

static const tsi_handshaker_vtable handshaker_vtable = {
const tsi_handshaker_vtable handshaker_vtable = {
nullptr, /* get_bytes_to_send_to_peer -- deprecated */
nullptr, /* process_bytes_from_peer -- deprecated */
nullptr, /* get_result -- deprecated */
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/server/admin/admin_services.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ namespace grpc {

namespace {

static auto* g_channelz_service = new ChannelzService();
auto* g_channelz_service = new ChannelzService();
#if !defined(GRPC_NO_XDS) && !defined(DISABLED_XDS_PROTO_IN_CC)
static auto* g_csds = new xds::experimental::ClientStatusDiscoveryService();
auto* g_csds = new xds::experimental::ClientStatusDiscoveryService();
#endif // GRPC_NO_XDS or DISABLED_XDS_PROTO_IN_CC

} // namespace
Expand Down
2 changes: 1 addition & 1 deletion test/core/channel/channel_stack_builder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const grpc_channel_filter original_filter = {
grpc_channel_next_get_info,
"filter_name"};

static bool AddReplacementFilter(grpc_channel_stack_builder* builder) {
bool AddReplacementFilter(grpc_channel_stack_builder* builder) {
// Get rid of any other version of the filter, as determined by having the
// same name.
GPR_ASSERT(grpc_channel_stack_builder_remove_filter(builder,
Expand Down
25 changes: 12 additions & 13 deletions test/core/util/stack_tracer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@

namespace {

static constexpr int kPrintfPointerFieldWidth = 2 + 2 * sizeof(void*);
constexpr int kPrintfPointerFieldWidth = 2 + 2 * sizeof(void*);

static void DumpPCAndFrameSizeAndSymbol(void (*writerfn)(const char*, void*),
void* writerfn_arg, void* pc,
void* symbolize_pc, int framesize,
const char* const prefix) {
void DumpPCAndFrameSizeAndSymbol(void (*writerfn)(const char*, void*),
void* writerfn_arg, void* pc,
void* symbolize_pc, int framesize,
const char* const prefix) {
char tmp[1024];
const char* symbol = "(unknown)";
if (absl::Symbolize(symbolize_pc, tmp, sizeof(tmp))) {
Expand All @@ -52,9 +52,9 @@ static void DumpPCAndFrameSizeAndSymbol(void (*writerfn)(const char*, void*),
writerfn(buf, writerfn_arg);
}

static void DumpPCAndFrameSize(void (*writerfn)(const char*, void*),
void* writerfn_arg, void* pc, int framesize,
const char* const prefix) {
void DumpPCAndFrameSize(void (*writerfn)(const char*, void*),
void* writerfn_arg, void* pc, int framesize,
const char* const prefix) {
char buf[100];
if (framesize <= 0) {
snprintf(buf, sizeof(buf), "%s@ %*p (unknown)\n", prefix,
Expand All @@ -66,10 +66,9 @@ static void DumpPCAndFrameSize(void (*writerfn)(const char*, void*),
writerfn(buf, writerfn_arg);
}

static void DumpStackTrace(void* const stack[], int frame_sizes[], int depth,
bool symbolize_stacktrace,
void (*writerfn)(const char*, void*),
void* writerfn_arg) {
void DumpStackTrace(void* const stack[], int frame_sizes[], int depth,
bool symbolize_stacktrace,
void (*writerfn)(const char*, void*), void* writerfn_arg) {
for (int i = 0; i < depth; i++) {
if (symbolize_stacktrace) {
DumpPCAndFrameSizeAndSymbol(writerfn, writerfn_arg, stack[i],
Expand All @@ -82,7 +81,7 @@ static void DumpStackTrace(void* const stack[], int frame_sizes[], int depth,
}
}

static void DebugWriteToString(const char* data, void* str) {
void DebugWriteToString(const char* data, void* str) {
reinterpret_cast<std::string*>(str)->append(data);
}

Expand Down
3 changes: 1 addition & 2 deletions test/cpp/end2end/async_end2end_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ class TestScenario {
const std::string message_content;
};

static std::ostream& operator<<(std::ostream& out,
const TestScenario& scenario) {
std::ostream& operator<<(std::ostream& out, const TestScenario& scenario) {
return out << "TestScenario{inproc=" << (scenario.inproc ? "true" : "false")
<< ", credentials='" << scenario.credentials_type
<< ", health_check_service="
Expand Down
Loading

0 comments on commit 1050eed

Please sign in to comment.