From fcd1eec2792d77bf7d5201263fef55ec8dfac705 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 20 May 2018 16:04:22 +0200 Subject: [PATCH] Avoid g++-8 -Wcatch-value warnings in the tests Catch soci_error (and std::bad_cast in one place) by reference rather than by value to avoid slicing -- even if it doesn't matter in the test code, it still provokes the new g++-8 warning about it. See #640. --- tests/common-tests.h | 26 +++++++++++++------------- tests/firebird/test-firebird.cpp | 4 ++-- tests/odbc/test-odbc-mssql.cpp | 2 +- tests/postgresql/test-postgresql.cpp | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/common-tests.h b/tests/common-tests.h index 414fdb70..37d55426 100644 --- a/tests/common-tests.h +++ b/tests/common-tests.h @@ -528,18 +528,18 @@ TEST_CASE_METHOD(common_tests, "Exception on not connected", "[core][exception]" soci::session sql; // no connection // ensure connection is checked, no crash occurs - CHECK_THROWS_AS(sql.begin(), soci_error); - CHECK_THROWS_AS(sql.commit(), soci_error); - CHECK_THROWS_AS(sql.rollback(), soci_error); - CHECK_THROWS_AS(sql.get_backend_name(), soci_error); - CHECK_THROWS_AS(sql.make_statement_backend(), soci_error); - CHECK_THROWS_AS(sql.make_rowid_backend(), soci_error); - CHECK_THROWS_AS(sql.make_blob_backend(), soci_error); + CHECK_THROWS_AS(sql.begin(), soci_error&); + CHECK_THROWS_AS(sql.commit(), soci_error&); + CHECK_THROWS_AS(sql.rollback(), soci_error&); + CHECK_THROWS_AS(sql.get_backend_name(), soci_error&); + CHECK_THROWS_AS(sql.make_statement_backend(), soci_error&); + CHECK_THROWS_AS(sql.make_rowid_backend(), soci_error&); + CHECK_THROWS_AS(sql.make_blob_backend(), soci_error&); std::string s; long l; - CHECK_THROWS_AS(sql.get_next_sequence_value(s, l), soci_error); - CHECK_THROWS_AS(sql.get_last_insert_id(s, l), soci_error); + CHECK_THROWS_AS(sql.get_next_sequence_value(s, l), soci_error&); + CHECK_THROWS_AS(sql.get_last_insert_id(s, l), soci_error&); } TEST_CASE_METHOD(common_tests, "Basic functionality", "[core][basics]") @@ -548,7 +548,7 @@ TEST_CASE_METHOD(common_tests, "Basic functionality", "[core][basics]") auto_table_creator tableCreator(tc_.table_creator_1(sql)); - CHECK_THROWS_AS(sql << "drop table soci_test_nosuchtable", soci_error); + CHECK_THROWS_AS(sql << "drop table soci_test_nosuchtable", soci_error&); sql << "insert into soci_test (id) values (" << 123 << ")"; int id; @@ -2845,7 +2845,7 @@ TEST_CASE_METHOD(common_tests, "Rowset expected exception", "[core][exception][r std::string troublemaker; CHECK_THROWS_AS( rowset((sql.prepare << "select str from soci_test", into(troublemaker))), - soci_error + soci_error& ); } @@ -2878,7 +2878,7 @@ TEST_CASE_METHOD(common_tests, "NULL expected exception", "[core][exception][nul rowset rs = (sql.prepare << "select val from soci_test order by val asc"); - CHECK_THROWS_AS( std::for_each(rs.begin(), rs.end(), THelper()), soci_error ); + CHECK_THROWS_AS( std::for_each(rs.begin(), rs.end(), THelper()), soci_error& ); } // This is like the first dynamic binding test but with rowset and iterators use @@ -4402,7 +4402,7 @@ TEST_CASE_METHOD(common_tests, "XML", "[core][xml]") (sql << "insert into soci_test(id, x) values (2, " + tc_.to_xml(":1") + ")", use(xml) - ), soci_error + ), soci_error& ); } } diff --git a/tests/firebird/test-firebird.cpp b/tests/firebird/test-firebird.cpp index 3a39869a..d4e19835 100644 --- a/tests/firebird/test-firebird.cpp +++ b/tests/firebird/test-firebird.cpp @@ -803,10 +803,10 @@ TEST_CASE("Firebird dynamic binding", "[firebird][dynamic]") // verify default values CHECK(tests::are_doubles_exactly_equal(r.get("NTEST", 2), 2)); - CHECK_THROWS_AS(r.get("NTEST"), soci_error); + CHECK_THROWS_AS(r.get("NTEST"), soci_error&); // verify exception thrown on invalid get<> - CHECK_THROWS_AS(r.get(0), std::bad_cast); + CHECK_THROWS_AS(r.get(0), std::bad_cast&); sql << "drop table test9"; } diff --git a/tests/odbc/test-odbc-mssql.cpp b/tests/odbc/test-odbc-mssql.cpp index 61926058..a2b96a5e 100644 --- a/tests/odbc/test-odbc-mssql.cpp +++ b/tests/odbc/test-odbc-mssql.cpp @@ -69,7 +69,7 @@ TEST_CASE("MS SQL long string", "[odbc][mssql][long]") // column. CHECK_THROWS_AS( (sql << "insert into soci_test(fixed_text) values(:str)", use(str_in)), - soci_error + soci_error& ); } diff --git a/tests/postgresql/test-postgresql.cpp b/tests/postgresql/test-postgresql.cpp index 26e7a1e7..e9472391 100644 --- a/tests/postgresql/test-postgresql.cpp +++ b/tests/postgresql/test-postgresql.cpp @@ -626,7 +626,7 @@ TEST_CASE("PostgreSQL JSON", "[postgresql][json]") CHECK_THROWS_AS(( sql << "insert into soci_json_test (data) values(:data)",use(invalid_input)), - soci_error + soci_error& ); } else