Skip to content

Commit ad4ff1f

Browse files
authored
Merge pull request #2320 from joto/clang-tidy
Various clang-tidy fixes
2 parents fd172b4 + 6a9e325 commit ad4ff1f

File tree

9 files changed

+81
-66
lines changed

9 files changed

+81
-66
lines changed

.clang-tidy

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
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,-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-*,-boost-use-ranges,-bugprone-chained-comparison,-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-math-missing-parentheses,-readability-named-parameter,-readability-magic-numbers'
33
#
44
# cppcoreguidelines-pro-type-cstyle-cast
55
# google-build-using-namespace
66
# google-readability-casting
77
# llvm-header-guard
88
# llvm-include-order
99
# hicpp-named-parameter
10+
# readability-math-missing-parentheses
1011
# readability-named-parameter
1112
# Differ from our style guidelines
1213
#
@@ -19,6 +20,12 @@ Checks: '*,-abseil-*,-altera-*,-android-cloexec-*,-bugprone-easily-swappable-par
1920
# android-cloexec-*
2021
# O_CLOEXEC isn't available on Windows
2122
#
23+
# boost-use-ranges
24+
# Not applicable, we don't want to rely on more code from boost.
25+
#
26+
# bugprone-chained-comparison
27+
# Triggerd by the Catch library in many places.
28+
#
2229
# bugprone-easily-swappable-parameters
2330
# Can't always be avoided.
2431
#

src/flex-lua-geom.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ geom::geometry_t *unpack_geometry(lua_State *lua_state, int n) noexcept
3636
return static_cast<geom::geometry_t *>(user_data);
3737
}
3838

39+
namespace {
40+
3941
/**
4042
* This function is called by Lua garbage collection when a geometry object
4143
* needs cleaning up. It calls the destructor of the C++ object. After that
@@ -51,8 +53,6 @@ int geom_gc(lua_State *lua_state) noexcept
5153
return 0;
5254
}
5355

54-
namespace {
55-
5656
// The following functions are called when their counterparts in Lua are
5757
// called on geometry objects.
5858

src/gen/gen-base.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void gen_base_t::dbprepare(std::string_view stmt, std::string const &templ)
103103
{
104104
template_t sql_template{templ};
105105
sql_template.set_params(get_params());
106-
return connection().prepare(stmt, fmt::runtime(sql_template.render()));
106+
connection().prepare(stmt, fmt::runtime(sql_template.render()));
107107
}
108108

109109
void gen_base_t::dbprepare(std::string_view stmt, params_t const &tmp_params,
@@ -112,7 +112,7 @@ void gen_base_t::dbprepare(std::string_view stmt, params_t const &tmp_params,
112112
template_t sql_template{templ};
113113
sql_template.set_params(get_params());
114114
sql_template.set_params(tmp_params);
115-
return connection().prepare(stmt, fmt::runtime(sql_template.render()));
115+
connection().prepare(stmt, fmt::runtime(sql_template.render()));
116116
}
117117

118118
void gen_base_t::raster_table_preprocess(std::string const &table)

src/gen/gen-rivers.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ gen_rivers_t::gen_rivers_t(pg_conn_t *connection, bool append, params_t *params)
4141
get_params().get_string("src_areas")));
4242
}
4343

44+
namespace {
45+
4446
/// The data for a graph edge in the waterway network.
4547
struct edge_t
4648
{
@@ -76,8 +78,6 @@ bool operator<(geom::point_t a, edge_t const &b) noexcept
7678
return a < b.points[0];
7779
}
7880

79-
namespace {
80-
8181
void follow_chain_and_set_width(
8282
edge_t const &edge, std::vector<edge_t> *edges,
8383
std::map<geom::point_t, uint8_t> const &node_order,

src/gen/raster.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@
1616

1717
#include <string>
1818

19+
namespace {
20+
1921
template <typename T>
2022
void append(std::string *str, T value)
2123
{
2224
str->append(reinterpret_cast<char *>(&value), sizeof(T));
2325
}
2426

27+
} // anonymous namespace
28+
2529
void add_raster_header(std::string *wkb, wkb_raster_header const &data)
2630
{
2731
append(wkb, data.endianness);

src/output-flex.cpp

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,54 @@ void check_for_object(lua_State *lua_state, char const *const function_name)
334334
function_name);
335335
}
336336

337+
/**
338+
* Expects a Lua (hash) table on the stack, reads the field with name of the
339+
* 'type' parameter which must be either nil or a Lua (array) table, in which
340+
* case all (integer) ids in that table are reads into the 'ids' out
341+
* parameter.
342+
*/
343+
void get_object_ids(lua_State *lua_state, char const *const type, idlist_t *ids)
344+
{
345+
lua_getfield(lua_state, -1, type);
346+
int const ltype = lua_type(lua_state, -1);
347+
348+
if (ltype == LUA_TNIL) {
349+
lua_pop(lua_state, 1);
350+
return;
351+
}
352+
353+
if (ltype != LUA_TTABLE) {
354+
lua_pop(lua_state, 1);
355+
throw fmt_error(
356+
"Table returned from select_relation_members() contains '{}' "
357+
"field, but it isn't an array table.",
358+
type);
359+
}
360+
361+
if (!luaX_is_array(lua_state)) {
362+
lua_pop(lua_state, 1);
363+
throw fmt_error(
364+
"Table returned from select_relation_members() contains '{}' "
365+
"field, but it isn't an array table.",
366+
type);
367+
}
368+
369+
luaX_for_each(lua_state, [&]() {
370+
osmid_t const id = lua_tointeger(lua_state, -1);
371+
if (id == 0) {
372+
throw fmt_error(
373+
"Table returned from select_relation_members() contains "
374+
"'{}' field, which must contain an array of non-zero "
375+
"integer node ids.",
376+
type);
377+
}
378+
379+
ids->push_back(id);
380+
});
381+
382+
lua_pop(lua_state, 1);
383+
}
384+
337385
} // anonymous namespace
338386

339387
/**
@@ -899,54 +947,6 @@ void output_flex_t::pending_way(osmid_t id)
899947
get_mutex_and_call_lua_function(m_process_way, m_way_cache.get());
900948
}
901949

902-
/**
903-
* Expects a Lua (hash) table on the stack, reads the field with name of the
904-
* 'type' parameter which must be either nil or a Lua (array) table, in which
905-
* case all (integer) ids in that table are reads into the 'ids' out
906-
* parameter.
907-
*/
908-
void get_object_ids(lua_State *lua_state, char const *const type, idlist_t *ids)
909-
{
910-
lua_getfield(lua_state, -1, type);
911-
int const ltype = lua_type(lua_state, -1);
912-
913-
if (ltype == LUA_TNIL) {
914-
lua_pop(lua_state, 1);
915-
return;
916-
}
917-
918-
if (ltype != LUA_TTABLE) {
919-
lua_pop(lua_state, 1);
920-
throw fmt_error(
921-
"Table returned from select_relation_members() contains '{}' "
922-
"field, but it isn't an array table.",
923-
type);
924-
}
925-
926-
if (!luaX_is_array(lua_state)) {
927-
lua_pop(lua_state, 1);
928-
throw fmt_error(
929-
"Table returned from select_relation_members() contains '{}' "
930-
"field, but it isn't an array table.",
931-
type);
932-
}
933-
934-
luaX_for_each(lua_state, [&]() {
935-
osmid_t const id = lua_tointeger(lua_state, -1);
936-
if (id == 0) {
937-
throw fmt_error(
938-
"Table returned from select_relation_members() contains "
939-
"'{}' field, which must contain an array of non-zero "
940-
"integer node ids.",
941-
type);
942-
}
943-
944-
ids->push_back(id);
945-
});
946-
947-
lua_pop(lua_state, 1);
948-
}
949-
950950
void output_flex_t::select_relation_members()
951951
{
952952
if (!m_select_relation_members) {

tests/test-lua-utils.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
#include <lua.hpp>
1515

16+
namespace {
17+
1618
// Run the Lua code in "code" and then execute the function "func".
1719
template <typename FUNC>
1820
void test_lua(lua_State *lua_state, char const *code, FUNC&& func) {
@@ -25,6 +27,8 @@ void test_lua(lua_State *lua_state, char const *code, FUNC&& func) {
2527
REQUIRE(lua_gettop(lua_state) == 0);
2628
}
2729

30+
} // anonymous namespace
31+
2832
TEST_CASE("check luaX_is_empty_table", "[NoDB]")
2933
{
3034
std::shared_ptr<lua_State> lua_state{

tests/test-output-flex-example-configs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ testing::db::import_t db;
2525

2626
char const *const data_file = "liechtenstein-2013-08-03.osm.pbf";
2727

28-
} // anonymous namespace
29-
3028
std::vector<std::string> get_files() {
3129
// NOLINTNEXTLINE(concurrency-mt-unsafe)
3230
char const *env = std::getenv("EXAMPLE_FILES");
3331
REQUIRE(env);
3432
return osmium::split_string(env, ',', true);
3533
}
3634

35+
} // anonymous namespace
36+
3737
TEST_CASE("minimal test for flex example configs")
3838
{
3939
auto const files = get_files();

tests/test-output-flex-update.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ testing::db::import_t db;
1919

2020
char const *const conf_file = "test_output_flex.lua";
2121

22+
// Return a string with the schema name prepended to the table name.
23+
std::string with_schema(char const *table_name, options_t const &options)
24+
{
25+
if (options.dbschema.empty()) {
26+
return {table_name};
27+
}
28+
return options.dbschema + "." + table_name;
29+
}
30+
2231
} // anonymous namespace
2332

2433
struct options_slim_default
@@ -72,15 +81,6 @@ END
7281
}
7382
};
7483

75-
// Return a string with the schema name prepended to the table name.
76-
std::string with_schema(char const *table_name, options_t const &options)
77-
{
78-
if (options.dbschema.empty()) {
79-
return {table_name};
80-
}
81-
return options.dbschema + "." + table_name;
82-
}
83-
8484
TEMPLATE_TEST_CASE("updating a node", "", options_slim_default,
8585
options_slim_expire, options_slim_schema)
8686
{

0 commit comments

Comments
 (0)