Skip to content

Commit 234cecd

Browse files
committed
Various fixes and clang-tidy configuration changes
Some function results have been casted to void to silence a clang-tidy warning. We are ignoring the results from IO operations because we can't do anything useful in those cases anyway.
1 parent ae35b32 commit 234cecd

File tree

11 files changed

+31
-18
lines changed

11 files changed

+31
-18
lines changed

.clang-tidy

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
Checks: '*,-altera-*,-android-cloexec-*,-cert-err58-cpp,-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-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-*,-bugprone-easily-swappable-parameters,-cert-err58-cpp,-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-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
@@ -10,12 +10,18 @@ Checks: '*,-altera-*,-android-cloexec-*,-cert-err58-cpp,-cppcoreguidelines-avoid
1010
# readability-named-parameter
1111
# Differ from our style guidelines
1212
#
13+
# abseil-*
14+
# Not applicable.
15+
#
1316
# altera-*
1417
# Not applicable.
1518
#
1619
# android-cloexec-*
1720
# O_CLOEXEC isn't available on Windows
1821
#
22+
# bugprone-easily-swappable-parameters
23+
# Can't always be avoided.
24+
#
1925
# cert-err58-cpp
2026
# There are many of these in the test code, most of them from the Catch
2127
# framework. Difficult to avoid.

src/expire-tiles.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ std::size_t output_tiles_to_file(quadkey_list_t const &tiles_maxzoom,
281281
fmt::print(outfile, "{}/{}/{}\n", tile.zoom(), tile.x(), tile.y());
282282
});
283283

284-
std::fclose(outfile);
284+
(void)std::fclose(outfile);
285285

286286
return count;
287287
}

src/logging.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ class logger
5555
str += fmt::format(ts, format_str, std::forward<TArgs>(args)...);
5656
str += '\n';
5757

58-
std::fputs(str.c_str(), stderr);
58+
if (std::fputs(str.c_str(), stderr) < 0) {
59+
throw std::runtime_error{"Can not write to log"};
60+
}
5961
}
6062

6163
bool log_sql() const noexcept { return m_log_sql; }

src/options.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ void long_usage(char const *arg0, bool verbose)
106106
char const *const name = program_name(arg0);
107107

108108
fmt::print(stdout, "\nUsage: {} [OPTIONS] OSM-FILE...\n", name);
109-
std::fputs(
109+
(void)std::fputs(
110110
"\nImport data from the OSM file(s) into a PostgreSQL database.\n\n\
111111
Full documentation is available at https://osm2pgsql.org/\n\n",
112112
stdout);
113113

114-
std::fputs("\
114+
(void)std::fputs("\
115115
Common options:\n\
116116
-a|--append Update existing osm2pgsql database with data from file.\n\
117117
-c|--create Import OSM data from file into database. This is the\n\
@@ -127,12 +127,12 @@ Common options:\n\
127127
-k|--hstore Add tags without column to an additional hstore column.\n",
128128
stdout);
129129
#ifdef HAVE_LUA
130-
std::fputs("\
130+
(void)std::fputs("\
131131
--tag-transform-script=SCRIPT Specify a Lua script to handle tag\n\
132132
filtering and normalisation (pgsql output only).\n",
133133
stdout);
134134
#endif
135-
std::fputs("\
135+
(void)std::fputs("\
136136
-s|--slim Store temporary data in the database. This switch is\n\
137137
required if you want to update with --append later.\n\
138138
--drop Only with --slim: drop temporary tables after import\n\
@@ -153,7 +153,7 @@ Database options:\n\
153153
stdout);
154154

155155
if (verbose) {
156-
std::fputs("\n\
156+
(void)std::fputs("\n\
157157
Logging options:\n\
158158
--log-level=LEVEL Set log level ('debug', 'info' (default), 'warn',\n\
159159
or 'error').\n\
@@ -470,6 +470,7 @@ options_t::options_t(int argc, char *argv[]) : options_t()
470470
// errors - setting it to zero seems to work, though. see
471471
// http://stackoverflow.com/questions/15179963/is-it-possible-to-repeat-getopt#15179990
472472
optind = 0;
473+
// NOLINTNEXTLINE(concurrency-mt-unsafe)
473474
while (-1 != (c = getopt_long(argc, argv, short_options, long_options,
474475
nullptr))) {
475476

@@ -621,7 +622,7 @@ options_t::options_t(int argc, char *argv[]) : options_t()
621622
break;
622623
case 'V': // --version
623624
print_version();
624-
exit(EXIT_SUCCESS);
625+
std::exit(EXIT_SUCCESS); // NOLINT(concurrency-mt-unsafe)
625626
break;
626627
case 215: // --middle-schema
627628
middle_dbschema = optarg;

src/options.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class options_t
8181
/**
8282
* Constructor parsing the options from the command line.
8383
*/
84+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
8485
options_t(int argc, char *argv[]);
8586

8687
/**

src/osmdata.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ class multithreaded_processor
314314
type, m_clones.size());
315315

316316
std::vector<std::future<void>> workers;
317-
317+
workers.reserve(m_clones.size() + 1);
318318
for (auto const &clone : m_clones) {
319319
workers.push_back(std::async(std::launch::async, run,
320320
std::cref(clone), &list, &m_mutex,

src/osmtypes.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class taglist_t
192192
template <typename T>
193193
void add_tag(char const *key, T&& value)
194194
{
195-
m_tags.emplace_back(key, std::move(value));
195+
m_tags.emplace_back(key, std::forward<T>(value));
196196
}
197197

198198
/// Add tag to list if there is no tag with that key yet

src/output-flex.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ static std::mutex lua_mutex;
5757
// C "trampoline" functions which are called from Lua which get the current
5858
// context (the output_flex_t object) and call the respective function on the
5959
// context object.
60+
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
6061
#define TRAMPOLINE(func_name, lua_name) \
6162
static int lua_trampoline_##func_name(lua_State *lua_state) \
6263
{ \

src/reprojection-generic-proj6.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ class generic_reprojection_t : public reprojection
8282
return trans_vis;
8383
}
8484

85-
geom::point_t transform(PJ *transformation,
86-
geom::point_t point) const noexcept
85+
static geom::point_t transform(PJ *transformation,
86+
geom::point_t point) noexcept
8787
{
8888
PJ_COORD c_in;
8989
c_in.lpzt.z = 0.0;

src/taginfo.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ bool read_style_file(std::string const &filename, export_list *exlist)
119119
}
120120

121121
if (fields < 3) {
122-
std::fclose(in);
122+
(void)std::fclose(in);
123123
throw fmt_error("Error reading style file line {} (fields={}).",
124124
lineno, fields);
125125
}
@@ -142,7 +142,7 @@ bool read_style_file(std::string const &filename, export_list *exlist)
142142
if ((temp.flags != FLAG_DELETE) &&
143143
((temp.name.find('?') != std::string::npos) ||
144144
(temp.name.find('*') != std::string::npos))) {
145-
std::fclose(in);
145+
(void)std::fclose(in);
146146
throw fmt_error("Wildcard '{}' in non-delete style entry.",
147147
temp.name);
148148
}
@@ -167,7 +167,7 @@ bool read_style_file(std::string const &filename, export_list *exlist)
167167

168168
//do we really want to completely quit on an unusable line?
169169
if (!kept) {
170-
std::fclose(in);
170+
(void)std::fclose(in);
171171
throw fmt_error("Weird style line {}:{}.", filename, lineno);
172172
}
173173

@@ -176,13 +176,13 @@ bool read_style_file(std::string const &filename, export_list *exlist)
176176

177177
if (std::ferror(in)) {
178178
int const err = errno;
179-
std::fclose(in);
179+
(void)std::fclose(in);
180180
throw std::system_error{
181181
err, std::system_category(),
182182
fmt::format("Error reading style file '{}'", filename)};
183183
}
184184

185-
std::fclose(in);
185+
(void)std::fclose(in);
186186

187187
if (!read_valid_column) {
188188
throw std::runtime_error{"Unable to parse any valid columns from "

0 commit comments

Comments
 (0)