diff --git a/src/db-copy-mgr.hpp b/src/db-copy-mgr.hpp index 15ac9e319..bcc160cab 100644 --- a/src/db-copy-mgr.hpp +++ b/src/db-copy-mgr.hpp @@ -24,8 +24,8 @@ template class db_copy_mgr_t { public: - explicit db_copy_mgr_t(std::shared_ptr const &processor) - : m_processor(processor) + explicit db_copy_mgr_t(std::shared_ptr processor) + : m_processor(std::move(processor)) {} /** @@ -333,10 +333,10 @@ class db_copy_mgr_t for (char const *c = s; *c; ++c) { switch (*c) { case '"': - m_current->buffer += "\\\\\""; + m_current->buffer += R"(\\")"; break; case '\\': - m_current->buffer += "\\\\\\\\"; + m_current->buffer += R"(\\\\)"; break; case '\n': m_current->buffer += "\\n"; diff --git a/src/db-copy.hpp b/src/db-copy.hpp index 4400b2a02..2d49b9ae9 100644 --- a/src/db-copy.hpp +++ b/src/db-copy.hpp @@ -171,8 +171,8 @@ struct db_cmd_copy_t : public db_cmd_t virtual bool has_deletables() const noexcept = 0; virtual void delete_data(pg_conn_t *conn) = 0; - explicit db_cmd_copy_t(std::shared_ptr const &t) - : db_cmd_t(db_cmd_t::Cmd_copy), target(t) + explicit db_cmd_copy_t(std::shared_ptr t) + : db_cmd_t(db_cmd_t::Cmd_copy), target(std::move(t)) { buffer.reserve(Max_buf_size); } diff --git a/src/expire-tiles.cpp b/src/expire-tiles.cpp index df558f50d..a9b98bfc4 100644 --- a/src/expire-tiles.cpp +++ b/src/expire-tiles.cpp @@ -61,9 +61,9 @@ void tile_output_t::output_dirty_tile(tile_t const &tile) } expire_tiles::expire_tiles(uint32_t max_zoom, double max_bbox, - const std::shared_ptr &projection) -: m_projection(projection), m_max_bbox(max_bbox), m_maxzoom(max_zoom), - m_map_width(1U << m_maxzoom) + std::shared_ptr projection) +: m_projection(std::move(projection)), m_max_bbox(max_bbox), + m_maxzoom(max_zoom), m_map_width(1U << m_maxzoom) {} void expire_tiles::output_and_destroy(char const *filename, uint32_t minzoom) diff --git a/src/expire-tiles.hpp b/src/expire-tiles.hpp index 8e27452c7..328b28cd9 100644 --- a/src/expire-tiles.hpp +++ b/src/expire-tiles.hpp @@ -46,7 +46,7 @@ class expire_tiles { public: expire_tiles(uint32_t max_zoom, double max_bbox, - const std::shared_ptr &projection); + std::shared_ptr projection); bool enabled() const noexcept { return m_maxzoom != 0; } diff --git a/src/flex-table-column.cpp b/src/flex-table-column.cpp index a69c2a6a2..7c9adaf69 100644 --- a/src/flex-table-column.cpp +++ b/src/flex-table-column.cpp @@ -183,5 +183,5 @@ std::string flex_table_column_t::sql_modifiers() const std::string flex_table_column_t::sql_create() const { - return "\"{}\" {} {},"_format(m_name, sql_type_name(), sql_modifiers()); + return R"("{}" {} {},)"_format(m_name, sql_type_name(), sql_modifiers()); } diff --git a/src/flex-table.cpp b/src/flex-table.cpp index 44ccd72e6..253bd35d3 100644 --- a/src/flex-table.cpp +++ b/src/flex-table.cpp @@ -247,7 +247,7 @@ void table_connection_t::stop(bool updateable, bool append) m_db_connection->exec(sql); m_db_connection->exec("DROP TABLE {}"_format(table().full_name())); - m_db_connection->exec("ALTER TABLE {} RENAME TO \"{}\""_format( + m_db_connection->exec(R"(ALTER TABLE {} RENAME TO "{}")"_format( table().full_tmp_name(), table().name())); m_id_index_created = false; @@ -263,7 +263,7 @@ void table_connection_t::stop(bool updateable, bool append) // Use fillfactor 100 for un-updateable imports m_db_connection->exec( - "CREATE INDEX ON {} USING GIST (\"{}\") {} {}"_format( + R"(CREATE INDEX ON {} USING GIST ("{}") {} {})"_format( table().full_name(), table().geom_column().name(), (updateable ? "" : "WITH (fillfactor = 100)"), tablespace_clause(table().index_tablespace()))); diff --git a/src/gazetteer-style.cpp b/src/gazetteer-style.cpp index 230006aaf..292a4ea08 100644 --- a/src/gazetteer-style.cpp +++ b/src/gazetteer-style.cpp @@ -8,6 +8,7 @@ */ #include +#include #include #include @@ -337,7 +338,7 @@ void gazetteer_style_t::process_tags(osmium::OSMObject const &o) } } - if (flag & (SF_NAME | SF_REF)) { + if (flag & static_cast(SF_NAME | SF_REF)) { m_names.emplace_back(k, v); if (flag & SF_NAME) { is_named = true; @@ -465,9 +466,9 @@ void gazetteer_style_t::copy_out(osmium::OSMObject const &o, // osm_id buffer->add_column(o.id()); // osm_type - char const osm_type[2] = { + std::array const osm_type = { (char)toupper(osmium::item_type_to_char(o.type())), '\0'}; - buffer->add_column(osm_type); + buffer->add_column(osm_type.data()); // class buffer->add_column(std::get<0>(tag)); // type diff --git a/src/gazetteer-style.hpp b/src/gazetteer-style.hpp index 6a5937063..7dded6088 100644 --- a/src/gazetteer-style.hpp +++ b/src/gazetteer-style.hpp @@ -105,22 +105,22 @@ class gazetteer_style_t using ptag_t = std::pair; using pmaintag_t = std::tuple; - enum style_flags + enum style_flags : uint16_t { - SF_MAIN = 1 << 0, - SF_MAIN_NAMED = 1 << 1, - SF_MAIN_NAMED_KEY = 1 << 2, - SF_MAIN_FALLBACK = 1 << 3, - SF_MAIN_OPERATOR = 1 << 4, - SF_NAME = 1 << 5, - SF_REF = 1 << 6, - SF_ADDRESS = 1 << 7, - SF_ADDRESS_POINT = 1 << 8, - SF_POSTCODE = 1 << 9, - SF_COUNTRY = 1 << 10, - SF_EXTRA = 1 << 11, - SF_INTERPOLATION = 1 << 12, - SF_BOUNDARY = 1 << 13, // internal flag for boundaries + SF_MAIN = 1U << 0U, + SF_MAIN_NAMED = 1U << 1U, + SF_MAIN_NAMED_KEY = 1U << 2U, + SF_MAIN_FALLBACK = 1U << 3U, + SF_MAIN_OPERATOR = 1U << 4U, + SF_NAME = 1U << 5U, + SF_REF = 1U << 6U, + SF_ADDRESS = 1U << 7U, + SF_ADDRESS_POINT = 1U << 8U, + SF_POSTCODE = 1U << 9U, + SF_COUNTRY = 1U << 10U, + SF_EXTRA = 1U << 11U, + SF_INTERPOLATION = 1U << 12U, + SF_BOUNDARY = 1U << 13U, // internal flag for boundaries }; enum class matcher_t @@ -138,8 +138,8 @@ class gazetteer_style_t flag_t flag; matcher_t type; - string_with_flag_t(std::string const &n, flag_t f, matcher_t t) - : name(n), flag(f), type(t) + string_with_flag_t(std::string n, flag_t f, matcher_t t) + : name(std::move(n)), flag(f), type(t) {} }; diff --git a/src/output-flex.cpp b/src/output-flex.cpp index 3bd6db3ce..5086b86d3 100644 --- a/src/output-flex.cpp +++ b/src/output-flex.cpp @@ -79,8 +79,9 @@ TRAMPOLINE(table_add_row, add_row) TRAMPOLINE(table_columns, columns) TRAMPOLINE(table_tostring, __tostring) -static char const osm2pgsql_table_name[] = "osm2pgsql.table"; -static char const osm2pgsql_object_metatable[] = "osm2pgsql.object_metatable"; +static char const *const osm2pgsql_table_name = "osm2pgsql.table"; +static char const *const osm2pgsql_object_metatable = + "osm2pgsql.object_metatable"; prepared_lua_function_t::prepared_lua_function_t(lua_State *lua_state, calling_context context, diff --git a/src/pgsql-helper.cpp b/src/pgsql-helper.cpp index 4c7fdce0e..20fd0b846 100644 --- a/src/pgsql-helper.cpp +++ b/src/pgsql-helper.cpp @@ -65,7 +65,7 @@ void drop_geom_check_trigger(pg_conn_t *db_connection, { std::string func_name = qualified_name(schema, table + "_osm2pgsql_valid"); - db_connection->exec("DROP TRIGGER \"{}\" ON {};"_format( + db_connection->exec(R"(DROP TRIGGER "{}" ON {};)"_format( table + "_osm2pgsql_valid", qualified_name(schema, table))); db_connection->exec("DROP FUNCTION IF EXISTS {} ();"_format(func_name)); diff --git a/src/table.cpp b/src/table.cpp index 021072497..cf077abc1 100644 --- a/src/table.cpp +++ b/src/table.cpp @@ -107,12 +107,12 @@ void table_t::start(std::string const &conninfo, std::string const &table_space) //first with the regular columns for (auto const &column : m_columns) { - sql += "\"{}\" {},"_format(column.name, column.type_name); + sql += R"("{}" {},)"_format(column.name, column.type_name); } //then with the hstore columns for (auto const &hcolumn : m_hstore_columns) { - sql += "\"{}\" hstore,"_format(hcolumn); + sql += R"("{}" hstore,)"_format(hcolumn); } //add tags column @@ -225,7 +225,7 @@ void table_t::stop(bool updateable, bool enable_hstore_index, m_sql_conn->exec(sql); m_sql_conn->exec("DROP TABLE {}"_format(qual_name)); - m_sql_conn->exec("ALTER TABLE {} RENAME TO \"{}\""_format( + m_sql_conn->exec(R"(ALTER TABLE {} RENAME TO "{}")"_format( qual_tmp_name, m_target->name)); log_info("Creating geometry index on table '{}'...", m_target->name); @@ -258,7 +258,7 @@ void table_t::stop(bool updateable, bool enable_hstore_index, } for (auto const &hcolumn : m_hstore_columns) { m_sql_conn->exec( - "CREATE INDEX ON {} USING GIN (\"{}\") {}"_format( + R"(CREATE INDEX ON {} USING GIN ("{}") {})"_format( qual_name, hcolumn, tablespace_clause(table_space_index))); } diff --git a/tests/test-middle.cpp b/tests/test-middle.cpp index 2886de0af..e973357d7 100644 --- a/tests/test-middle.cpp +++ b/tests/test-middle.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -184,7 +185,8 @@ TEMPLATE_TEST_CASE("middle import", "", options_slim_default, SECTION("Set and retrieve a single relation with supporting ways") { - idlist_t const nds[] = {{4, 5, 13, 14, 342}, {45, 90}, {30, 3, 45}}; + std::array const nds = { + {{4, 5, 13, 14, 342}, {45, 90}, {30, 3, 45}}}; // set the node mid->node(buffer.add_node("n1 x4.1 y12.8")); diff --git a/tests/test-output-flex-types.cpp b/tests/test-output-flex-types.cpp index 0f97721a0..02a369fc9 100644 --- a/tests/test-output-flex-types.cpp +++ b/tests/test-output-flex-types.cpp @@ -12,6 +12,8 @@ #include "common-import.hpp" #include "common-options.hpp" +#include + static testing::db::import_t db; static char const *const conf_file = "test_output_flex_types.lua"; @@ -205,8 +207,9 @@ TEST_CASE("Adding a function should always fail") { testing::opt_t const options = testing::opt_t().flex(conf_file); - std::string const types[] = {"ttext", "tbool", "tint2", "tint4", "tint8", - "treal", "thstr", "tdirn", "tsqlt"}; + std::array const types = {"ttext", "tbool", "tint2", + "tint4", "tint8", "treal", + "thstr", "tdirn", "tsqlt"}; for (auto const &type : types) { auto const line = @@ -252,8 +255,8 @@ TEST_CASE("Adding a table should fail except for hstore and json/jsonb") { testing::opt_t const options = testing::opt_t().flex(conf_file); - std::string const types[] = {"ttext", "tbool", "tint2", "tint4", - "tint8", "treal", "tdirn", "tsqlt"}; + std::array const types = { + "ttext", "tbool", "tint2", "tint4", "tint8", "treal", "tdirn", "tsqlt"}; for (auto const &type : types) { auto const line = diff --git a/tests/test-output-flex-way-add.cpp b/tests/test-output-flex-way-add.cpp index cf6f3ce1a..ed3e2cbc5 100644 --- a/tests/test-output-flex-way-add.cpp +++ b/tests/test-output-flex-way-add.cpp @@ -12,11 +12,13 @@ #include "common-import.hpp" #include "common-options.hpp" +#include + static testing::db::import_t db; static char const *const conf_file = "test_output_flex_way.lua"; -static const char *const tdata[] = { +static std::array const tdata = { "n10 v1 dV x10.0 y10.0", "n11 v1 dV x10.0 y10.1", "n12 v1 dV x10.1 y10.0", diff --git a/tests/test-output-flex-way-change.cpp b/tests/test-output-flex-way-change.cpp index e650cea46..26cf7f2e2 100644 --- a/tests/test-output-flex-way-change.cpp +++ b/tests/test-output-flex-way-change.cpp @@ -12,11 +12,13 @@ #include "common-import.hpp" #include "common-options.hpp" +#include + static testing::db::import_t db; static char const *const conf_file = "test_output_flex_way.lua"; -static const char *const tdata[] = { +static std::array const tdata = { "n10 v1 dV x10.0 y10.0", "n11 v1 dV x10.0 y10.1", "n12 v1 dV x10.1 y10.0", "n13 v1 dV x10.1 y10.1", "n14 v1 dV x10.2 y10.0", "n15 v1 dV x10.2 y10.1", diff --git a/tests/test-output-flex-way-del.cpp b/tests/test-output-flex-way-del.cpp index 0d06e6df3..594bac708 100644 --- a/tests/test-output-flex-way-del.cpp +++ b/tests/test-output-flex-way-del.cpp @@ -12,11 +12,13 @@ #include "common-import.hpp" #include "common-options.hpp" +#include + static testing::db::import_t db; static char const *const conf_file = "test_output_flex_way.lua"; -static const char *const tdata[] = { +static std::array const tdata = { "n10 v1 dV x10.0 y10.0", "n11 v1 dV x10.0 y10.1", "n12 v1 dV x10.1 y10.0", "n13 v1 dV x10.1 y10.1", "n14 v1 dV x10.2 y10.0", "n15 v1 dV x10.2 y10.1", diff --git a/tests/test-output-flex-way-relation-add.cpp b/tests/test-output-flex-way-relation-add.cpp index 9ee6c6910..392901fb6 100644 --- a/tests/test-output-flex-way-relation-add.cpp +++ b/tests/test-output-flex-way-relation-add.cpp @@ -12,11 +12,13 @@ #include "common-import.hpp" #include "common-options.hpp" +#include + static testing::db::import_t db; static char const *const conf_file = "test_output_flex_way.lua"; -static char const *const tdata[] = { +static std::array const tdata = { "n10 v1 dV x10.0 y10.0", "n11 v1 dV x10.0 y10.1", "n12 v1 dV x10.1 y10.0", diff --git a/tests/test-output-flex-way-relation-del.cpp b/tests/test-output-flex-way-relation-del.cpp index 1d757e715..c7cc38c9f 100644 --- a/tests/test-output-flex-way-relation-del.cpp +++ b/tests/test-output-flex-way-relation-del.cpp @@ -12,11 +12,13 @@ #include "common-import.hpp" #include "common-options.hpp" +#include + static testing::db::import_t db; static char const *const conf_file = "test_output_flex_way.lua"; -static const char *const tdata[] = { +static std::array const tdata = { "n10 v1 dV x10.0 y10.0", "n11 v1 dV x10.0 y10.1", "n12 v1 dV x10.1 y10.0", diff --git a/tests/test-output-pgsql-z_order.cpp b/tests/test-output-pgsql-z_order.cpp index 3e155fdc4..f373c24f5 100644 --- a/tests/test-output-pgsql-z_order.cpp +++ b/tests/test-output-pgsql-z_order.cpp @@ -12,6 +12,8 @@ #include "common-import.hpp" #include "common-options.hpp" +#include + static testing::db::import_t db; TEST_CASE("compute Z order") @@ -21,8 +23,8 @@ TEST_CASE("compute Z order") auto conn = db.db().connect(); - char const *expected[] = {"motorway", "trunk", "primary", "secondary", - "tertiary"}; + std::array const expected = { + "motorway", "trunk", "primary", "secondary", "tertiary"}; for (unsigned i = 0; i < 5; ++i) { auto const sql = "SELECT highway FROM osm2pgsql_test_line" diff --git a/tests/test-persistent-cache.cpp b/tests/test-persistent-cache.cpp index 40bdbd640..1bdda1906 100644 --- a/tests/test-persistent-cache.cpp +++ b/tests/test-persistent-cache.cpp @@ -26,10 +26,10 @@ static void read_location(node_persistent_cache const &cache, osmid_t id, REQUIRE(osmium::Location(x, y) == cache.get(id)); } -static void delete_location(node_persistent_cache &cache, osmid_t id) +static void delete_location(node_persistent_cache *cache, osmid_t id) { - cache.set(id, osmium::Location{}); - REQUIRE(osmium::Location{} == cache.get(id)); + cache->set(id, osmium::Location{}); + REQUIRE(osmium::Location{} == cache->get(id)); } TEST_CASE("Persistent cache", "[NoDB]") @@ -91,10 +91,10 @@ TEST_CASE("Persistent cache", "[NoDB]") write_and_read_location(&cache, 510000, 44, 0.0); // delete existing - delete_location(cache, 11); + delete_location(&cache, 11); // delete non-existing - delete_location(cache, 21); + delete_location(&cache, 21); // non-deleted should still be there read_location(cache, 10, 10.01, -45.3);