Skip to content

Commit 84fc4d7

Browse files
authored
Silence clang-tidy warnings. (#918)
These warnings fell into 3 categories: Useful warnings — many, but already fixed. Scènes à faire — nothing to be done but suppress them. Painful advice — implemented here, accepting a small performance cost. One std::free() in strconv.cxx triggered three clang-tidy warnings — more than could fit on one healthy line. I didn't want blanket suppression, but as a compromise, it turned out that wildcards worked. (Perhaps I could have gotten by with a backslash-escaped newline in that comment, but that's just gruesome.) Blanket suppression of warning signs is of course a bad thing. But for now... clean yet thorough lint check!
1 parent e8d2a79 commit 84fc4d7

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

config/Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ am__can_run_installinfo = \
124124
esac
125125
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
126126
am__DIST_COMMON = $(srcdir)/Makefile.in compile config.guess \
127-
config.sub install-sh ltmain.sh missing mkinstalldirs
127+
config.sub depcomp install-sh ltmain.sh missing mkinstalldirs
128128
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
129129
ACLOCAL = @ACLOCAL@
130130
AMTAR = @AMTAR@

src/binarystring.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ std::shared_ptr<unsigned char>
3636
PQXX_COLD copy_to_buffer(void const *data, std::size_t len)
3737
{
3838
std::shared_ptr<unsigned char> ptr{
39+
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc,hicpp-no-malloc)
3940
static_cast<unsigned char *>(malloc(len + 1)), std::free};
4041
if (not ptr)
4142
throw std::bad_alloc{};

src/result.cxx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ void pqxx::internal::clear_result(pq::PGresult const *data) noexcept
4444
// This acts as a destructor, though implemented as a regular function so we
4545
// can pass it into a smart pointer. That's why I think it's kind of fair
4646
// to treat the PGresult as const.
47+
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
4748
PQclear(const_cast<pq::PGresult *>(data));
4849
}
4950

@@ -362,6 +363,7 @@ char const *pqxx::result::cmd_status() const noexcept
362363
// PQcmdStatus() can't take a PGresult const * because it returns a non-const
363364
// pointer into the PGresult's data, and that can't be changed without
364365
// breaking compatibility.
366+
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
365367
return PQcmdStatus(const_cast<internal::pq::PGresult *>(m_data.get()));
366368
}
367369

@@ -383,12 +385,13 @@ pqxx::oid pqxx::result::inserted_oid() const
383385

384386
pqxx::result::size_type pqxx::result::affected_rows() const
385387
{
386-
// PQcmdTuples() can't take a PGresult const * because it returns a non-const
387-
// pointer into the PGresult's data, and that can't be changed without
388-
// breaking compatibility.
389-
auto const rows_str{
388+
// PQcmdTuples() can't take a "PGresult const *" because it returns a
389+
// non-const pointer into the PGresult's data, and that can't be changed
390+
// without breaking compatibility.
391+
std::string_view const rows_str{
392+
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
390393
PQcmdTuples(const_cast<internal::pq::PGresult *>(m_data.get()))};
391-
return (rows_str[0] == '\0') ? 0 : size_type(atoi(rows_str));
394+
return from_string<size_type>(rows_str);
392395
}
393396

394397

src/strconv.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ wrap_to_chars(char *begin, char *end, T const &value)
151151
namespace pqxx::internal
152152
{
153153
template<typename T>
154+
// NOLINTNEXTLINE(readability-non-const-parameter)
154155
zview integral_traits<T>::to_buf(char *begin, char *end, T const &value)
155156
{
156157
static_assert(std::is_integral_v<T>);
@@ -236,6 +237,7 @@ std::string demangle_type_name(char const raw[])
236237
// When __cxa_demangle fails, it's guaranteed to return null.
237238
std::unique_ptr<char, void (*)(char *)> const demangled{
238239
abi::__cxa_demangle(raw, nullptr, nullptr, &status),
240+
// NOLINTNEXTLINE(*-no-malloc,cppcoreguidelines-owning-memory)
239241
[](char *x) { std::free(x); }};
240242
#else
241243
std::unique_ptr<char> demangled{};

src/util.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ constexpr std::array<char, 16u> hex_digits{
110110
/// Translate a number (must be between 0 and 16 exclusive) to a hex digit.
111111
constexpr char hex_digit(int c) noexcept
112112
{
113-
assert(c >= 0 and c < pqxx::internal::ssize(hex_digits));
114-
return hex_digits[static_cast<unsigned int>(c)];
113+
return hex_digits.at(static_cast<unsigned int>(c));
115114
}
116115

117116

@@ -207,6 +206,7 @@ void pqfreemem(void const *ptr) noexcept
207206
{
208207
// Why is it OK to const_cast here? Because this is the C equivalent to a
209208
// destructor. Those apply to const objects as well as non-const ones.
209+
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
210210
PQfreemem(const_cast<void *>(ptr));
211211
}
212212
} // namespace pqxx::internal::pq

0 commit comments

Comments
 (0)