diff --git a/include/protozero/basic_pbf_builder.hpp b/include/protozero/basic_pbf_builder.hpp index 0ede726fa..78db80b3a 100644 --- a/include/protozero/basic_pbf_builder.hpp +++ b/include/protozero/basic_pbf_builder.hpp @@ -67,7 +67,7 @@ class basic_pbf_builder : public basic_pbf_writer { * @param tag Tag of the field that will be written */ template - basic_pbf_builder(basic_pbf_writer& parent_writer, P tag) noexcept : + basic_pbf_builder(basic_pbf_writer& parent_writer, P tag) : basic_pbf_writer{parent_writer, pbf_tag_type(tag)} { } diff --git a/test/include/packed_access.hpp b/test/include/packed_access.hpp index 95154b5d4..92eb03c70 100644 --- a/test/include/packed_access.hpp +++ b/test/include/packed_access.hpp @@ -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")); @@ -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 @@ -273,8 +273,8 @@ TEST_CASE("write from different types of iterators: " PBF_TYPE_NAME) { using test_type = uint32_t; #endif - std::istream_iterator eod; - std::istream_iterator it(sdata); + const std::istream_iterator eod; + const std::istream_iterator it(sdata); pw.ADD_TYPE(1, it, eod); } diff --git a/test/include/test.hpp b/test/include/test.hpp index 876e37efb..b004ade32 100644 --- a/test/include/test.hpp +++ b/test/include/test.hpp @@ -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 #include diff --git a/test/t/bytes/reader_test_cases.cpp b/test/t/bytes/reader_test_cases.cpp index cf49e11a5..0ef4ce51b 100644 --- a/test/t/bytes/reader_test_cases.cpp +++ b/test/t/bytes/reader_test_cases.cpp @@ -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); } diff --git a/test/t/message/reader_test_cases.cpp b/test/t/message/reader_test_cases.cpp index dab0c8104..6b85dc047 100644 --- a/test/t/message/reader_test_cases.cpp +++ b/test/t/message/reader_test_cases.cpp @@ -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"); diff --git a/test/t/nested/reader_test_cases.cpp b/test/t/nested/reader_test_cases.cpp index 0c35d53e9..c39b5ab43 100644 --- a/test/t/nested/reader_test_cases.cpp +++ b/test/t/nested/reader_test_cases.cpp @@ -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); } @@ -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); } @@ -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); } diff --git a/test/t/repeated_packed_bool/reader_test_cases.cpp b/test/t/repeated_packed_bool/reader_test_cases.cpp index fff24b73e..a40c94fd4 100644 --- a/test/t/repeated_packed_bool/reader_test_cases.cpp +++ b/test/t/repeated_packed_bool/reader_test_cases.cpp @@ -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")); @@ -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")); diff --git a/test/t/repeated_packed_fixed32/writer_test_cases.cpp b/test/t/repeated_packed_fixed32/writer_test_cases.cpp index f7531f241..63bb6ca98 100644 --- a/test/t/repeated_packed_fixed32/writer_test_cases.cpp +++ b/test/t/repeated_packed_fixed32/writer_test_cases.cpp @@ -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 eod; - std::istream_iterator it(sdata); + const std::istream_iterator eod; + const std::istream_iterator it(sdata); pw.template add_packed_fixed(1, it, eod); } diff --git a/test/t/rollback/reader_test_cases.cpp b/test/t/rollback/reader_test_cases.cpp index 31634dcd1..bcd66dc62 100644 --- a/test/t/rollback/reader_test_cases.cpp +++ b/test/t/rollback/reader_test_cases.cpp @@ -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); @@ -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); } } diff --git a/test/t/vector_tile/reader_test_cases.cpp b/test/t/vector_tile/reader_test_cases.cpp index e9ea33a84..dee492277 100644 --- a/test/t/vector_tile/reader_test_cases.cpp +++ b/test/t/vector_tile/reader_test_cases.cpp @@ -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; @@ -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; diff --git a/test/unit/test_exceptions.cpp b/test/unit/test_exceptions.cpp index 1c4170cc8..1cb0c85c8 100644 --- a/test/unit/test_exceptions.cpp +++ b/test/unit/test_exceptions.cpp @@ -2,32 +2,32 @@ #include 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"}); } diff --git a/test/unit/test_iterators.cpp b/test/unit/test_iterators.cpp index d9b35ada1..1a3d68488 100644 --- a/test/unit/test_iterators.cpp +++ b/test/unit/test_iterators.cpp @@ -2,10 +2,10 @@ #include TEST_CASE("default constructed varint_iterators are equal") { - protozero::const_varint_iterator a{}; - protozero::const_varint_iterator b{}; + const protozero::const_varint_iterator a{}; + const protozero::const_varint_iterator b{}; - protozero::iterator_range> r{}; + const protozero::iterator_range> r{}; REQUIRE(a == a); REQUIRE(a == b); diff --git a/tools/pbf-decoder.cpp b/tools/pbf-decoder.cpp index c911f5962..268ddb551 100644 --- a/tools/pbf-decoder.cpp +++ b/tools/pbf-decoder.cpp @@ -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) { @@ -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(file.rdbuf()), std::istreambuf_iterator()}; }