Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang tidy fixes #119

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/protozero/basic_pbf_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class basic_pbf_builder : public basic_pbf_writer<TBuffer> {
* @param tag Tag of the field that will be written
*/
template <typename P>
basic_pbf_builder(basic_pbf_writer<TBuffer>& parent_writer, P tag) noexcept :
basic_pbf_builder(basic_pbf_writer<TBuffer>& parent_writer, P tag) :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're removing noexcept here, presumably because it was never actually noexcept in the first place?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. It was never noexcept, clang-tidy found that problem. We can not make it noexcept, so we have to remove the noexcept.

basic_pbf_writer<TBuffer>{parent_writer, pbf_tag_type(tag)} {
}

Expand Down
8 changes: 4 additions & 4 deletions test/include/packed_access.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ TEST_CASE("write repeated packed field using packed field: " PBF_TYPE_NAME) {

SECTION("empty - should do rollback") {
{
packed_field_type field{pw, 1};
const packed_field_type field{pw, 1};
}

REQUIRE(buffer == load_data("repeated_packed_" PBF_TYPE_NAME "/data-empty"));
Expand Down Expand Up @@ -264,7 +264,7 @@ TEST_CASE("write from different types of iterators: " PBF_TYPE_NAME) {
}

SECTION("from string") {
std::string data{"1 4 9 16 25"};
const std::string data{"1 4 9 16 25"};
std::stringstream sdata{data};

#if PBF_TYPE_IS_SIGNED
Expand All @@ -273,8 +273,8 @@ TEST_CASE("write from different types of iterators: " PBF_TYPE_NAME) {
using test_type = uint32_t;
#endif

std::istream_iterator<test_type> eod;
std::istream_iterator<test_type> it(sdata);
const std::istream_iterator<test_type> eod;
const std::istream_iterator<test_type> it(sdata);

pw.ADD_TYPE(1, it, eod);
}
Expand Down
2 changes: 1 addition & 1 deletion test/include/test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct assert_error : public std::runtime_error {
explicit assert_error(const char* what_arg) : std::runtime_error(what_arg) {
}
};
#define protozero_assert(x) if (!(x)) { throw assert_error{#x}; }
#define protozero_assert(x) if (!(x)) { throw assert_error{#x}; } // NOLINT(readability-simplify-boolean-expr)

#include <protozero/pbf_builder.hpp>
#include <protozero/pbf_message.hpp>
Expand Down
22 changes: 11 additions & 11 deletions test/t/bytes/reader_test_cases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,32 +91,32 @@ TEST_CASE("write bytes field using vectored approach") {
protozero::pbf_writer pw{buffer};

SECTION("using two strings") {
std::string d1{"foo"};
std::string d2{"bar"};
const std::string d1{"foo"};
const std::string d2{"bar"};

pw.add_bytes_vectored(1, d1, d2);
}

SECTION("using a string and a dataview") {
std::string d1{"foo"};
std::string d2{"bar"};
protozero::data_view dv{d2};
const std::string d1{"foo"};
const std::string d2{"bar"};
const protozero::data_view dv{d2};

pw.add_bytes_vectored(1, d1, dv);
}

SECTION("using three strings") {
std::string d1{"foo"};
std::string d2{"ba"};
std::string d3{"r"};
const std::string d1{"foo"};
const std::string d2{"ba"};
const std::string d3{"r"};

pw.add_bytes_vectored(1, d1, d2, d3);
}

SECTION("with empty string") {
std::string d1{"foo"};
std::string d2{};
std::string d3{"bar"};
const std::string d1{"foo"};
const std::string d2{};
const std::string d3{"bar"};

pw.add_bytes_vectored(1, d1, d2, d3);
}
Expand Down
2 changes: 1 addition & 1 deletion test/t/message/reader_test_cases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ TEST_CASE("write message field") {
}

SECTION("string with subwriter with reserved size") {
std::string str{"foobar"};
const std::string str{"foobar"};
const auto size = 1 /* tag */ + 1 /* length field */ + str.size();
protozero::pbf_writer pbf_submessage{pbf_test, 1, size};
pbf_submessage.add_string(1, "foobar");
Expand Down
14 changes: 7 additions & 7 deletions test/t/nested/reader_test_cases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ inline void check_empty(protozero::pbf_reader message) {
TEST_CASE("read nested message fields: string") {
const std::string buffer = load_data("nested/data-message");

protozero::pbf_reader message{buffer};
const protozero::pbf_reader message{buffer};
check(message);
}

TEST_CASE("read nested message fields: no submessage") {
const std::string buffer = load_data("nested/data-no-message");

protozero::pbf_reader message{buffer};
const protozero::pbf_reader message{buffer};
check_empty(message);
}

Expand Down Expand Up @@ -121,7 +121,7 @@ TEST_CASE("write nested message fields") {

pbf_test.add_int32(2, 77);

protozero::pbf_reader message{buffer_test};
const protozero::pbf_reader message{buffer_test};
check(message);
}

Expand All @@ -133,25 +133,25 @@ TEST_CASE("write nested message fields - no message") {
}

SECTION("empty string") {
std::string buffer_sub;
const std::string buffer_sub;

pbf_test.add_message(1, buffer_sub);
}

SECTION("string with pbf_writer") {
std::string buffer_sub;
protozero::pbf_writer pbf_sub{buffer_sub};
const protozero::pbf_writer pbf_sub{buffer_sub};

pbf_test.add_message(1, buffer_sub);
}

SECTION("string with subwriter") {
protozero::pbf_writer pbf_sub{pbf_test, 1};
const protozero::pbf_writer pbf_sub{pbf_test, 1};
}

pbf_test.add_int32(2, 77);

protozero::pbf_reader message{buffer_test};
const protozero::pbf_reader message{buffer_test};
check_empty(message);
}

4 changes: 2 additions & 2 deletions test/t/repeated_packed_bool/reader_test_cases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ TEST_CASE("write repeated packed bool field using packed_field_bool") {

SECTION("empty - should do rollback") {
{
protozero::packed_field_bool field{pw, 1};
const protozero::packed_field_bool field{pw, 1};
}

REQUIRE(buffer == load_data("repeated_packed_bool/data-empty"));
Expand Down Expand Up @@ -128,7 +128,7 @@ TEST_CASE("write repeated packed bool field using packed_field_bool with pbf_bui

SECTION("empty - should do rollback") {
{
protozero::packed_field_bool field{pw, msg::f};
const protozero::packed_field_bool field{pw, msg::f};
}

REQUIRE(buffer == load_data("repeated_packed_bool/data-empty"));
Expand Down
6 changes: 3 additions & 3 deletions test/t/repeated_packed_fixed32/writer_test_cases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ TEMPLATE_TEST_CASE("write from different types of iterators and check with libpr
}

SECTION("from string") {
std::string data = "1 4 9 16 25";
const std::string data = "1 4 9 16 25";
std::stringstream sdata(data);

std::istream_iterator<uint32_t> eod;
std::istream_iterator<uint32_t> it(sdata);
const std::istream_iterator<uint32_t> eod;
const std::istream_iterator<uint32_t> it(sdata);

pw.template add_packed_fixed<uint32_t>(1, it, eod);
}
Expand Down
4 changes: 2 additions & 2 deletions test/t/rollback/reader_test_cases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ TEST_CASE("rollback when using packed_field functions") {

SECTION("empty - should do rollback") {
{
protozero::packed_field_sint64 field{pw, 1};
const protozero::packed_field_sint64 field{pw, 1};
}

pw.add_int32(4, 123);
Expand Down Expand Up @@ -197,7 +197,7 @@ TEST_CASE("rollback on message is not allowed if there is a nested submessage")
{
protozero::pbf_writer pws{pw, 1};
pws.add_string(1, "foobar");
protozero::pbf_writer pws2{pws, 1};
const protozero::pbf_writer pws2{pws, 1};
REQUIRE_THROWS_AS(pws.rollback(), assert_error);
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/t/vector_tile/reader_test_cases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ TEST_CASE("reading vector tiles") {
int n_geomtype = 0;
while (item.next(3)) { // repeated message Layer
protozero::pbf_reader layer{item.get_message()};
std::string name = get_name(layer);
const std::string name = get_name(layer);
if (name == "road") {
while (layer.next(2)) { // repeated Feature
++n;
Expand Down Expand Up @@ -118,7 +118,7 @@ TEST_CASE("reading vector tiles") {
int n_geomtype = 0;
while (item.next(3)) { // repeated message Layer
protozero::pbf_reader layer{item.get_message()};
std::string name = get_name(layer);
const std::string name = get_name(layer);
if (name == "road") {
while (layer.next(2)) { // repeated Feature
++n;
Expand Down
12 changes: 6 additions & 6 deletions test/unit/test_exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@
#include <test.hpp>

TEST_CASE("exceptions messages for pbf exception") {
protozero::exception e;
const protozero::exception e;
REQUIRE(std::string{e.what()} == std::string{"pbf exception"});
}

TEST_CASE("exceptions messages for varint too long") {
protozero::varint_too_long_exception e;
const protozero::varint_too_long_exception e;
REQUIRE(std::string{e.what()} == std::string{"varint too long exception"});
}

TEST_CASE("exceptions messages for unknown pbf field type") {
protozero::unknown_pbf_wire_type_exception e;
const protozero::unknown_pbf_wire_type_exception e;
REQUIRE(std::string{e.what()} == std::string{"unknown pbf field type exception"});
}

TEST_CASE("exceptions messages for end of buffer") {
protozero::end_of_buffer_exception e;
const protozero::end_of_buffer_exception e;
REQUIRE(std::string{e.what()} == std::string{"end of buffer exception"});
}

TEST_CASE("exceptions messages for invalid tag") {
protozero::invalid_tag_exception e;
const protozero::invalid_tag_exception e;
REQUIRE(std::string{e.what()} == std::string{"invalid tag exception"});
}

TEST_CASE("exceptions messages for invalid length") {
protozero::invalid_length_exception e;
const protozero::invalid_length_exception e;
REQUIRE(std::string{e.what()} == std::string{"invalid length exception"});
}

6 changes: 3 additions & 3 deletions test/unit/test_iterators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#include <test.hpp>

TEST_CASE("default constructed varint_iterators are equal") {
protozero::const_varint_iterator<uint32_t> a{};
protozero::const_varint_iterator<uint32_t> b{};
const protozero::const_varint_iterator<uint32_t> a{};
const protozero::const_varint_iterator<uint32_t> b{};

protozero::iterator_range<protozero::const_varint_iterator<uint32_t>> r{};
const protozero::iterator_range<protozero::const_varint_iterator<uint32_t>> r{};

REQUIRE(a == a);
REQUIRE(a == b);
Expand Down
4 changes: 2 additions & 2 deletions tools/pbf-decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ bool decode_printable_string(std::stringstream& out, const protozero::data_view
bool decode_string(std::stringstream& out, const protozero::data_view view) {
static constexpr const std::size_t max_string_length = 60;

std::string str{view.data(), std::min(view.size(), max_string_length)};
const std::string str{view.data(), std::min(view.size(), max_string_length)};
out << '"';

for (const auto c : str) {
Expand Down Expand Up @@ -193,7 +193,7 @@ void print_help() {
}

std::string read_from_file(const char* filename) {
std::ifstream file{filename, std::ios::binary};
const std::ifstream file{filename, std::ios::binary};
return std::string{std::istreambuf_iterator<char>(file.rdbuf()),
std::istreambuf_iterator<char>()};
}
Expand Down
Loading