Skip to content

Commit 21f7e00

Browse files
authored
Merge pull request #2239 from joto/more-anon-ns
Refactors final cases of use of "static"
2 parents 0ccce1d + d2e58a0 commit 21f7e00

File tree

6 files changed

+23
-10
lines changed

6 files changed

+23
-10
lines changed

.clang-tidy

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
Checks: '*,-abseil-*,-altera-*,-android-cloexec-*,-bugprone-easily-swappable-parameters,-cert-err58-cpp,-cppcoreguidelines-avoid-do-while,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-avoid-non-const-global-variables,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-type-cstyle-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-pro-type-static-cast-downcast,-cppcoreguidelines-pro-type-vararg,-fuchsia-*,-google-readability-casting,-google-readability-todo,-hicpp-named-parameter,-hicpp-no-array-decay,-hicpp-vararg,-llvm-include-order,-llvm-header-guard,-llvmlibc-*,-misc-include-cleaner,-misc-no-recursion,-misc-use-anonymous-namespace,-modernize-use-nodiscard,-modernize-use-trailing-return-type,-readability-identifier-length,-readability-implicit-bool-conversion,-readability-named-parameter,-readability-magic-numbers'
2+
Checks: '*,-abseil-*,-altera-*,-android-cloexec-*,-bugprone-easily-swappable-parameters,-cert-err58-cpp,-cppcoreguidelines-avoid-do-while,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-avoid-non-const-global-variables,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-type-cstyle-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-pro-type-static-cast-downcast,-cppcoreguidelines-pro-type-vararg,-fuchsia-*,-google-readability-casting,-google-readability-todo,-hicpp-named-parameter,-hicpp-no-array-decay,-hicpp-vararg,-llvm-include-order,-llvm-header-guard,-llvmlibc-*,-misc-include-cleaner,-misc-no-recursion,-modernize-use-nodiscard,-modernize-use-trailing-return-type,-readability-identifier-length,-readability-implicit-bool-conversion,-readability-named-parameter,-readability-magic-numbers'
33
#
44
# cppcoreguidelines-pro-type-cstyle-cast
55
# google-build-using-namespace
@@ -65,9 +65,6 @@ Checks: '*,-abseil-*,-altera-*,-android-cloexec-*,-bugprone-easily-swappable-par
6565
# misc-no-recursion
6666
# Nothing wrong with recursion
6767
#
68-
# misc-use-anonymous-namespace (new in clang-tidy-16)
69-
# Lots of these, need some time to fix. (TODO)
70-
#
7168
# modernize-use-nodiscard
7269
# Doesn't really make the code clearer if it is all littered with
7370
# [[nodiscard]]. Looks like this warning is more suited for a library

src/gen/osm2pgsql-gen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
// context object.
6161
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
6262
#define TRAMPOLINE(func_name, lua_name) \
63-
static int lua_trampoline_##func_name(lua_State *lua_state) \
63+
int lua_trampoline_##func_name(lua_State *lua_state) \
6464
{ \
6565
try { \
6666
return static_cast<genproc_t *>(luaX_get_context(lua_state)) \

src/lua-utils.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ void *luaX_get_context(lua_State *lua_state) noexcept
3333

3434
#else
3535

36+
namespace {
37+
3638
// Unique key for lua registry
37-
static char const *osm2pgsql_output_flex = "osm2pgsql_output_flex";
39+
constexpr char const *const osm2pgsql_output_flex = "osm2pgsql_output_flex";
40+
41+
} // anonymous namespace
3842

3943
void luaX_set_context(lua_State *lua_state, void *ptr) noexcept
4044
{

src/output-flex.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,18 @@
5050
#include <string>
5151
#include <string_view>
5252

53+
namespace {
54+
5355
// Mutex used to coordinate access to Lua code
54-
static std::mutex lua_mutex;
56+
std::mutex lua_mutex;
5557

5658
// Lua can't call functions on C++ objects directly. This macro defines simple
5759
// C "trampoline" functions which are called from Lua which get the current
5860
// context (the output_flex_t object) and call the respective function on the
5961
// context object.
6062
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
6163
#define TRAMPOLINE(func_name, lua_name) \
62-
static int lua_trampoline_##func_name(lua_State *lua_state) \
64+
int lua_trampoline_##func_name(lua_State *lua_state) \
6365
{ \
6466
try { \
6567
return static_cast<output_flex_t *>(luaX_get_context(lua_state)) \
@@ -99,6 +101,8 @@ TRAMPOLINE(expire_output_schema, schema)
99101
TRAMPOLINE(expire_output_table, table)
100102
TRAMPOLINE(expire_output_tostring, __tostring)
101103

104+
} // anonymous namespace
105+
102106
prepared_lua_function_t::prepared_lua_function_t(lua_State *lua_state,
103107
calling_context context,
104108
char const *name, int nresults)

src/properties.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
#include <cassert>
1818
#include <cstdlib>
1919

20-
static constexpr char const *const properties_table = "osm2pgsql_properties";
20+
namespace {
21+
22+
constexpr char const *const properties_table = "osm2pgsql_properties";
23+
24+
} // anonymous namespace
2125

2226
properties_t::properties_t(connection_params_t connection_params,
2327
std::string schema)

src/wkb.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,9 @@ geom::geometry_t ewkb_to_geom(std::string_view wkb)
576576
return geom;
577577
}
578578

579-
static constexpr std::array<char, 256> const hex_table = {
579+
namespace {
580+
581+
constexpr std::array<char, 256> const hex_table = {
580582
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
581583
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
582584
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -587,6 +589,8 @@ static constexpr std::array<char, 256> const hex_table = {
587589
0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0,
588590
};
589591

592+
} // anonymous namespace
593+
590594
unsigned char decode_hex_char(char c) noexcept
591595
{
592596
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-constant-array-index)

0 commit comments

Comments
 (0)