From dacfc5831380cd7821a5c67e302c3473a0c2cb7b Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Mon, 13 Nov 2023 00:25:22 +0100 Subject: [PATCH] Switch to using the new feature macros. --- cmake/config.cmake | 2 +- include/Makefile.am | 1 - include/Makefile.in | 1 - include/pqxx/except.hxx | 92 +++++++++++++------------- include/pqxx/internal/cxx-features.hxx | 43 ------------ include/pqxx/internal/header-pre.hxx | 2 - include/pqxx/result.hxx | 4 +- include/pqxx/util.hxx | 6 +- src/except.cxx | 62 ++++++++--------- src/result.cxx | 4 +- src/transaction.cxx | 2 +- test/runner.cxx | 22 +++--- test/test_helpers.hxx | 68 +++++++++---------- test/unit/test_field.cxx | 4 +- test/unit/test_test_helpers.cxx | 6 +- 15 files changed, 136 insertions(+), 183 deletions(-) delete mode 100644 include/pqxx/internal/cxx-features.hxx diff --git a/cmake/config.cmake b/cmake/config.cmake index 273cc64e0..1ba173b7b 100644 --- a/cmake/config.cmake +++ b/cmake/config.cmake @@ -55,7 +55,7 @@ set(CMAKE_REQUIRED_QUIET ON) # Incorporate feature checks based on C++ feature test mac include(pqxx_cxx_feature_checks) -# This variable is set by one of the config-tests. +# This variable is set by one of the snippets in config-tests. if(!no_need_fslib) # TODO: This may work for gcc 8, but some clang versions may need -lc++fs. link_libraries(stdc++fs) diff --git a/include/Makefile.am b/include/Makefile.am index 20b277219..5ac0d968d 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -40,7 +40,6 @@ nobase_include_HEADERS= pqxx/pqxx \ pqxx/internal/callgate.hxx \ pqxx/internal/concat.hxx \ pqxx/internal/conversions.hxx \ - pqxx/internal/cxx-features.hxx \ pqxx/internal/encoding_group.hxx \ pqxx/internal/encodings.hxx \ pqxx/internal/header-pre.hxx \ diff --git a/include/Makefile.in b/include/Makefile.in index b4fd1bb47..37e02c0ed 100644 --- a/include/Makefile.in +++ b/include/Makefile.in @@ -390,7 +390,6 @@ nobase_include_HEADERS = pqxx/pqxx \ pqxx/internal/callgate.hxx \ pqxx/internal/concat.hxx \ pqxx/internal/conversions.hxx \ - pqxx/internal/cxx-features.hxx \ pqxx/internal/encoding_group.hxx \ pqxx/internal/encodings.hxx \ pqxx/internal/header-pre.hxx \ diff --git a/include/pqxx/except.hxx b/include/pqxx/except.hxx index 1307d1610..4e9f9a7c2 100644 --- a/include/pqxx/except.hxx +++ b/include/pqxx/except.hxx @@ -17,7 +17,7 @@ # error "Include libpqxx headers as , not ." #endif -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) # include #endif @@ -46,7 +46,7 @@ namespace pqxx /// Run-time failure encountered by libpqxx, similar to std::runtime_error. struct PQXX_LIBEXPORT failure : std::runtime_error { -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) explicit failure( std::string const &, std::source_location = std::source_location::current()); @@ -82,7 +82,7 @@ struct PQXX_LIBEXPORT broken_connection : failure broken_connection(); explicit broken_connection( std::string const & -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location = std::source_location::current() #endif @@ -103,7 +103,7 @@ struct PQXX_LIBEXPORT protocol_violation : broken_connection { explicit protocol_violation( std::string const & -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location = std::source_location::current() #endif @@ -116,7 +116,7 @@ struct PQXX_LIBEXPORT variable_set_to_null : failure { explicit variable_set_to_null( std::string const & -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location = std::source_location::current() #endif @@ -139,7 +139,7 @@ public: explicit sql_error( std::string const &whatarg = "", std::string const &Q = "", char const sqlstate[] = nullptr -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location = std::source_location::current() #endif @@ -165,7 +165,7 @@ struct PQXX_LIBEXPORT in_doubt_error : failure { explicit in_doubt_error( std::string const & -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location = std::source_location::current() #endif @@ -179,7 +179,7 @@ struct PQXX_LIBEXPORT transaction_rollback : sql_error explicit transaction_rollback( std::string const &whatarg, std::string const &q = "", char const sqlstate[] = nullptr -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location = std::source_location::current() #endif @@ -201,7 +201,7 @@ struct PQXX_LIBEXPORT serialization_failure : transaction_rollback explicit serialization_failure( std::string const &whatarg, std::string const &q, char const sqlstate[] = nullptr -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location = std::source_location::current() #endif @@ -215,7 +215,7 @@ struct PQXX_LIBEXPORT statement_completion_unknown : transaction_rollback explicit statement_completion_unknown( std::string const &whatarg, std::string const &q, char const sqlstate[] = nullptr -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location = std::source_location::current() #endif @@ -229,7 +229,7 @@ struct PQXX_LIBEXPORT deadlock_detected : transaction_rollback explicit deadlock_detected( std::string const &whatarg, std::string const &q, char const sqlstate[] = nullptr -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location = std::source_location::current() #endif @@ -249,13 +249,13 @@ struct PQXX_LIBEXPORT usage_error : std::logic_error { explicit usage_error( std::string const & -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location = std::source_location::current() #endif ); -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) std::source_location location; #endif }; @@ -266,13 +266,13 @@ struct PQXX_LIBEXPORT argument_error : std::invalid_argument { explicit argument_error( std::string const & -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location = std::source_location::current() #endif ); -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) std::source_location location; #endif }; @@ -283,13 +283,13 @@ struct PQXX_LIBEXPORT conversion_error : std::domain_error { explicit conversion_error( std::string const & -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location = std::source_location::current() #endif ); -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) std::source_location location; #endif }; @@ -300,7 +300,7 @@ struct PQXX_LIBEXPORT unexpected_null : conversion_error { explicit unexpected_null( std::string const & -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location = std::source_location::current() #endif @@ -313,7 +313,7 @@ struct PQXX_LIBEXPORT conversion_overrun : conversion_error { explicit conversion_overrun( std::string const & -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location = std::source_location::current() #endif @@ -326,13 +326,13 @@ struct PQXX_LIBEXPORT range_error : std::out_of_range { explicit range_error( std::string const & -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location = std::source_location::current() #endif ); -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) std::source_location location; #endif }; @@ -341,7 +341,7 @@ struct PQXX_LIBEXPORT range_error : std::out_of_range /// Query returned an unexpected number of rows. struct PQXX_LIBEXPORT unexpected_rows : public range_error { -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) explicit unexpected_rows( std::string const &msg, std::source_location loc = std::source_location::current()) : @@ -356,7 +356,7 @@ struct PQXX_LIBEXPORT unexpected_rows : public range_error /// Database feature not supported in current setup. struct PQXX_LIBEXPORT feature_not_supported : sql_error { -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) explicit feature_not_supported( std::string const &err, std::string const &Q = "", char const sqlstate[] = nullptr, @@ -375,7 +375,7 @@ struct PQXX_LIBEXPORT feature_not_supported : sql_error /// Error in data provided to SQL statement. struct PQXX_LIBEXPORT data_exception : sql_error { -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) explicit data_exception( std::string const &err, std::string const &Q = "", char const sqlstate[] = nullptr, @@ -393,7 +393,7 @@ struct PQXX_LIBEXPORT data_exception : sql_error struct PQXX_LIBEXPORT integrity_constraint_violation : sql_error { -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) explicit integrity_constraint_violation( std::string const &err, std::string const &Q = "", char const sqlstate[] = nullptr, @@ -411,7 +411,7 @@ struct PQXX_LIBEXPORT integrity_constraint_violation : sql_error struct PQXX_LIBEXPORT restrict_violation : integrity_constraint_violation { -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) explicit restrict_violation( std::string const &err, std::string const &Q = "", char const sqlstate[] = nullptr, @@ -429,7 +429,7 @@ struct PQXX_LIBEXPORT restrict_violation : integrity_constraint_violation struct PQXX_LIBEXPORT not_null_violation : integrity_constraint_violation { -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) explicit not_null_violation( std::string const &err, std::string const &Q = "", char const sqlstate[] = nullptr, @@ -447,7 +447,7 @@ struct PQXX_LIBEXPORT not_null_violation : integrity_constraint_violation struct PQXX_LIBEXPORT foreign_key_violation : integrity_constraint_violation { -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) explicit foreign_key_violation( std::string const &err, std::string const &Q = "", char const sqlstate[] = nullptr, @@ -465,7 +465,7 @@ struct PQXX_LIBEXPORT foreign_key_violation : integrity_constraint_violation struct PQXX_LIBEXPORT unique_violation : integrity_constraint_violation { -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) explicit unique_violation( std::string const &err, std::string const &Q = "", char const sqlstate[] = nullptr, @@ -483,7 +483,7 @@ struct PQXX_LIBEXPORT unique_violation : integrity_constraint_violation struct PQXX_LIBEXPORT check_violation : integrity_constraint_violation { -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) explicit check_violation( std::string const &err, std::string const &Q = "", char const sqlstate[] = nullptr, @@ -501,7 +501,7 @@ struct PQXX_LIBEXPORT check_violation : integrity_constraint_violation struct PQXX_LIBEXPORT invalid_cursor_state : sql_error { -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) explicit invalid_cursor_state( std::string const &err, std::string const &Q = "", char const sqlstate[] = nullptr, @@ -519,7 +519,7 @@ struct PQXX_LIBEXPORT invalid_cursor_state : sql_error struct PQXX_LIBEXPORT invalid_sql_statement_name : sql_error { -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) explicit invalid_sql_statement_name( std::string const &err, std::string const &Q = "", char const sqlstate[] = nullptr, @@ -537,7 +537,7 @@ struct PQXX_LIBEXPORT invalid_sql_statement_name : sql_error struct PQXX_LIBEXPORT invalid_cursor_name : sql_error { -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) explicit invalid_cursor_name( std::string const &err, std::string const &Q = "", char const sqlstate[] = nullptr, @@ -558,7 +558,7 @@ struct PQXX_LIBEXPORT syntax_error : sql_error /// Approximate position in string where error occurred, or -1 if unknown. int const error_position; -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) explicit syntax_error( std::string const &err, std::string const &Q = "", char const sqlstate[] = nullptr, int pos = -1, @@ -576,7 +576,7 @@ struct PQXX_LIBEXPORT syntax_error : sql_error struct PQXX_LIBEXPORT undefined_column : syntax_error { -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) explicit undefined_column( std::string const &err, std::string const &Q = "", char const sqlstate[] = nullptr, @@ -595,7 +595,7 @@ struct PQXX_LIBEXPORT undefined_column : syntax_error struct PQXX_LIBEXPORT undefined_function : syntax_error { -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) explicit undefined_function( std::string const &err, std::string const &Q = "", char const sqlstate[] = nullptr, @@ -614,7 +614,7 @@ struct PQXX_LIBEXPORT undefined_function : syntax_error struct PQXX_LIBEXPORT undefined_table : syntax_error { -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) explicit undefined_table( std::string const &err, std::string const &Q = "", char const sqlstate[] = nullptr, @@ -633,7 +633,7 @@ struct PQXX_LIBEXPORT undefined_table : syntax_error struct PQXX_LIBEXPORT insufficient_privilege : sql_error { -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) explicit insufficient_privilege( std::string const &err, std::string const &Q = "", char const sqlstate[] = nullptr, @@ -652,7 +652,7 @@ struct PQXX_LIBEXPORT insufficient_privilege : sql_error /// Resource shortage on the server struct PQXX_LIBEXPORT insufficient_resources : sql_error { -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) explicit insufficient_resources( std::string const &err, std::string const &Q = "", char const sqlstate[] = nullptr, @@ -670,7 +670,7 @@ struct PQXX_LIBEXPORT insufficient_resources : sql_error struct PQXX_LIBEXPORT disk_full : insufficient_resources { -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) explicit disk_full( std::string const &err, std::string const &Q = "", char const sqlstate[] = nullptr, @@ -688,7 +688,7 @@ struct PQXX_LIBEXPORT disk_full : insufficient_resources struct PQXX_LIBEXPORT out_of_memory : insufficient_resources { -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) explicit out_of_memory( std::string const &err, std::string const &Q = "", char const sqlstate[] = nullptr, @@ -706,7 +706,7 @@ struct PQXX_LIBEXPORT out_of_memory : insufficient_resources struct PQXX_LIBEXPORT too_many_connections : broken_connection { -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) explicit too_many_connections( std::string const &err, std::source_location loc = std::source_location::current()) : @@ -724,7 +724,7 @@ struct PQXX_LIBEXPORT too_many_connections : broken_connection */ struct PQXX_LIBEXPORT plpgsql_error : sql_error { -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) explicit plpgsql_error( std::string const &err, std::string const &Q = "", char const sqlstate[] = nullptr, @@ -743,7 +743,7 @@ struct PQXX_LIBEXPORT plpgsql_error : sql_error /// Exception raised in PL/pgSQL procedure struct PQXX_LIBEXPORT plpgsql_raise : plpgsql_error { -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) explicit plpgsql_raise( std::string const &err, std::string const &Q = "", char const sqlstate[] = nullptr, @@ -761,7 +761,7 @@ struct PQXX_LIBEXPORT plpgsql_raise : plpgsql_error struct PQXX_LIBEXPORT plpgsql_no_data_found : plpgsql_error { -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) explicit plpgsql_no_data_found( std::string const &err, std::string const &Q = "", char const sqlstate[] = nullptr, @@ -779,7 +779,7 @@ struct PQXX_LIBEXPORT plpgsql_no_data_found : plpgsql_error struct PQXX_LIBEXPORT plpgsql_too_many_rows : plpgsql_error { -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) explicit plpgsql_too_many_rows( std::string const &err, std::string const &Q = "", char const sqlstate[] = nullptr, diff --git a/include/pqxx/internal/cxx-features.hxx b/include/pqxx/internal/cxx-features.hxx deleted file mode 100644 index 2667baa55..000000000 --- a/include/pqxx/internal/cxx-features.hxx +++ /dev/null @@ -1,43 +0,0 @@ -/** C++ feature test macros. - * - * Flags defining available C++ features. These will progressively replace - * feature tests at the build stage. - * - * Why define these and not use the standard C++ macros directly? To avoid - * annoying warnings. The standard macros rely on te fact that an undefined - * macro, used as a boolean in a preprocessor conditional, evaluates as false. - * This is pretty fundamental to how the standard feature test macros work: - * you just say `#if __cpp_lib_ssize`, for example, to test whether the - * compiler supports `std::ssize_t`. If it doesn't, then the macro will not - * exist, and the `#if` decides that no, you don't have that feature. But - * some users may ask their compilers to report any use of an undefined macro - * as an error. - * - * So, we define alternate macros here that you can safely use in `#if`. - */ -#if defined(__cpp_multidimensional_subscript) -# if __cpp_multidimensional_subscript -# define pqxx_have_multidim 1 -# endif // __cpp_multidimensional_subscript -#endif // __cpp_multidimensional_subscript -#if !defined(pqxx_have_multidim) -# define pqxx_have_multidim 0 -#endif // pqxx_have_multidim - -#if defined(__cpp_lib_source_location) && __cpp_lib_source_location -# define pqxx_have_source_location 1 -#else -# define pqxx_have_source_location 0 -#endif // __cpp_lib_source_location - -#if defined(__cpp_lib_ssize) && __cpp_lib_ssize -# define pqxx_have_ssize 1 -#else -# define pqxx_have_ssize 0 -#endif // __cpp_lib_ssize - -#if defined(__cpp_lib_unreachable) && __cpp_lib_unreachable -# define pqxx_have_unreachable 1 -#else -# define pqxx_have_unreachable 0 -#endif // __cpp_lib_unreachable diff --git a/include/pqxx/internal/header-pre.hxx b/include/pqxx/internal/header-pre.hxx index 441f77a86..aedc84bea 100644 --- a/include/pqxx/internal/header-pre.hxx +++ b/include/pqxx/internal/header-pre.hxx @@ -21,8 +21,6 @@ # include #endif -#include "pqxx/internal/cxx-features.hxx" - // NO GUARD HERE! This part should be included every time this file is. #if defined(_MSC_VER) diff --git a/include/pqxx/result.hxx b/include/pqxx/result.hxx index 70e72b258..e957ce49b 100644 --- a/include/pqxx/result.hxx +++ b/include/pqxx/result.hxx @@ -156,10 +156,10 @@ public: */ [[nodiscard]] row operator[](size_type i) const noexcept; -#if pqxx_have_multidim +#if defined(PQXX_HAVE_MULTIDIM) [[nodiscard]] field operator[](size_type row_num, row_size_type col_num) const noexcept; -#endif // pqxx_have_multidim +#endif // PQXX_HAVE_MULTIDIM /// Index a row by number, but check that the row number is valid. row at(size_type) const; diff --git a/include/pqxx/util.hxx b/include/pqxx/util.hxx index e3d107d5b..1352a4489 100644 --- a/include/pqxx/util.hxx +++ b/include/pqxx/util.hxx @@ -45,7 +45,7 @@ namespace pqxx // C++23: Retire wrapper. -#if pqxx_have_unreachable +#if defined(PQXX_HAVE_UNREACHABLE) /// Equivalent to `std::unreachable()` if available. # define PQXX_UNREACHABLE std::unreachable() #else @@ -452,12 +452,12 @@ std::basic_string /// Transitional: std::ssize(), or custom implementation if not available. template auto ssize(T const &c) { -#if pqxx_have_ssize +#if defined(PQXX_HAVE_SSIZE) return std::ssize(c); #else using signed_t = std::make_signed_t; return static_cast(std::size(c)); -#endif // pqxx_have_ssize +#endif // PQXX_HAVE_SSIZe } diff --git a/src/except.cxx b/src/except.cxx index 6df8910b2..49a88f50b 100644 --- a/src/except.cxx +++ b/src/except.cxx @@ -15,7 +15,7 @@ #include "pqxx/internal/header-post.hxx" -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) pqxx::failure::failure(std::string const &whatarg, std::source_location loc) : std::runtime_error{whatarg}, location{loc} {} @@ -33,7 +33,7 @@ pqxx::broken_connection::broken_connection() : pqxx::broken_connection::broken_connection( std::string const &whatarg -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location loc #endif @@ -41,7 +41,7 @@ pqxx::broken_connection::broken_connection( failure { whatarg -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , loc #endif @@ -51,7 +51,7 @@ pqxx::broken_connection::broken_connection( pqxx::protocol_violation::protocol_violation( std::string const &whatarg -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location loc #endif @@ -59,7 +59,7 @@ pqxx::protocol_violation::protocol_violation( broken_connection { whatarg -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , loc #endif @@ -69,7 +69,7 @@ pqxx::protocol_violation::protocol_violation( pqxx::variable_set_to_null::variable_set_to_null( std::string const &whatarg -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location loc #endif @@ -77,7 +77,7 @@ pqxx::variable_set_to_null::variable_set_to_null( failure { whatarg -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , loc #endif @@ -87,7 +87,7 @@ pqxx::variable_set_to_null::variable_set_to_null( pqxx::sql_error::sql_error( std::string const &whatarg, std::string const &Q, char const sqlstate[] -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location loc #endif @@ -95,7 +95,7 @@ pqxx::sql_error::sql_error( failure { whatarg -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , loc #endif @@ -120,7 +120,7 @@ PQXX_PURE std::string const &pqxx::sql_error::sqlstate() const noexcept pqxx::in_doubt_error::in_doubt_error( std::string const &whatarg -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location loc #endif @@ -128,7 +128,7 @@ pqxx::in_doubt_error::in_doubt_error( failure { whatarg -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , loc #endif @@ -138,7 +138,7 @@ pqxx::in_doubt_error::in_doubt_error( pqxx::transaction_rollback::transaction_rollback( std::string const &whatarg, std::string const &q, char const sqlstate[] -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location loc #endif @@ -146,7 +146,7 @@ pqxx::transaction_rollback::transaction_rollback( sql_error { whatarg, q, sqlstate -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , loc #endif @@ -156,7 +156,7 @@ pqxx::transaction_rollback::transaction_rollback( pqxx::serialization_failure::serialization_failure( std::string const &whatarg, std::string const &q, char const sqlstate[] -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location loc #endif @@ -164,7 +164,7 @@ pqxx::serialization_failure::serialization_failure( transaction_rollback { whatarg, q, sqlstate -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , loc #endif @@ -174,7 +174,7 @@ pqxx::serialization_failure::serialization_failure( pqxx::statement_completion_unknown::statement_completion_unknown( std::string const &whatarg, std::string const &q, char const sqlstate[] -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location loc #endif @@ -182,7 +182,7 @@ pqxx::statement_completion_unknown::statement_completion_unknown( transaction_rollback { whatarg, q, sqlstate -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , loc #endif @@ -192,7 +192,7 @@ pqxx::statement_completion_unknown::statement_completion_unknown( pqxx::deadlock_detected::deadlock_detected( std::string const &whatarg, std::string const &q, char const sqlstate[] -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location loc #endif @@ -200,7 +200,7 @@ pqxx::deadlock_detected::deadlock_detected( transaction_rollback { whatarg, q, sqlstate -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , loc #endif @@ -215,13 +215,13 @@ pqxx::internal_error::internal_error(std::string const &whatarg) : pqxx::usage_error::usage_error( std::string const &whatarg -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location loc #endif ) : std::logic_error{whatarg} -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , location{loc} #endif @@ -230,13 +230,13 @@ pqxx::usage_error::usage_error( pqxx::argument_error::argument_error( std::string const &whatarg -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location loc #endif ) : invalid_argument{whatarg} -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , location{loc} #endif @@ -245,13 +245,13 @@ pqxx::argument_error::argument_error( pqxx::conversion_error::conversion_error( std::string const &whatarg -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location loc #endif ) : domain_error{whatarg} -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , location{loc} #endif @@ -260,7 +260,7 @@ pqxx::conversion_error::conversion_error( pqxx::unexpected_null::unexpected_null( std::string const &whatarg -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location loc #endif @@ -268,7 +268,7 @@ pqxx::unexpected_null::unexpected_null( conversion_error { whatarg -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , loc #endif @@ -278,7 +278,7 @@ pqxx::unexpected_null::unexpected_null( pqxx::conversion_overrun::conversion_overrun( std::string const &whatarg -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location loc #endif @@ -286,7 +286,7 @@ pqxx::conversion_overrun::conversion_overrun( conversion_error { whatarg -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , loc #endif @@ -296,13 +296,13 @@ pqxx::conversion_overrun::conversion_overrun( pqxx::range_error::range_error( std::string const &whatarg -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location loc #endif ) : out_of_range{whatarg} -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , location{loc} #endif diff --git a/src/result.cxx b/src/result.cxx index 060a2f17a..819def1af 100644 --- a/src/result.cxx +++ b/src/result.cxx @@ -141,13 +141,13 @@ pqxx::row pqxx::result::operator[](result_size_type i) const noexcept } -#if pqxx_have_multidim +#if defined(PQXX_HAVE_MULTIDIM) pqxx::field pqxx::result::operator[]( result_size_type row_num, row_size_type col_num) const noexcept { return {*this, row_num, col_num}; } -#endif // pqxx_have_multidim +#endif // PQXX_HAVE_MULTIDIM pqxx::row pqxx::result::at(pqxx::result::size_type i) const diff --git a/src/transaction.cxx b/src/transaction.cxx index 2ee41d046..ba50a36be 100644 --- a/src/transaction.cxx +++ b/src/transaction.cxx @@ -81,7 +81,7 @@ void pqxx::internal::basic_transaction::do_commit() throw in_doubt_error { std::move(msg) -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , e.location #endif diff --git a/test/runner.cxx b/test/runner.cxx index baefe7adb..707b90507 100644 --- a/test/runner.cxx +++ b/test/runner.cxx @@ -23,7 +23,7 @@ inline std::string deref_field(pqxx::field const &f) namespace pqxx::test { -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) test_failure::test_failure(std::string const &desc, std::source_location loc) : std::logic_error{desc}, m_loc{loc} {} @@ -45,11 +45,11 @@ inline void drop_table(transaction_base &t, std::string const &table) [[noreturn]] void check_notreached( -#if !pqxx_have_source_location +#if !defined(PQXX_HAVE_SOURCE_LOCATION) char const file[], int line, #endif std::string desc -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location loc #endif @@ -57,11 +57,11 @@ inline void drop_table(transaction_base &t, std::string const &table) { throw test_failure { -#if !pqxx_have_source_location +#if !defined(PQXX_HAVE_SOURCE_LOCATION) file, line, #endif desc -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , loc #endif @@ -70,11 +70,11 @@ inline void drop_table(transaction_base &t, std::string const &table) void check( -#if !pqxx_have_source_location +#if !defined(PQXX_HAVE_SOURCE_LOCATION) char const file[], int line, #endif bool condition, char const text[], std::string const &desc -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location loc #endif @@ -83,11 +83,11 @@ void check( if (not condition) throw test_failure { -#if !pqxx_have_source_location +#if !defined(PQXX_HAVE_SOURCE_LOCATION) file, line, #endif desc + " (failed expression: " + text + ")" -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , loc #endif @@ -205,7 +205,7 @@ int main(int argc, char const *argv[]) catch (pqxx::feature_not_supported const &e) { std::cerr << "Not testing unsupported feature: " << e.what() << '\n'; -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) std::string func{e.location.function_name()}; std::cerr << "("; std::cerr << e.location.file_name() << ':' << e.location.line(); @@ -219,7 +219,7 @@ int main(int argc, char const *argv[]) catch (pqxx::sql_error const &e) { std::cerr << "SQL error: " << e.what() << '\n'; -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) std::string func{e.location.function_name()}; std::cerr << "("; std::cerr << e.location.file_name() << ':' << e.location.line(); diff --git a/test/test_helpers.hxx b/test/test_helpers.hxx index 0b5a2c119..66b913607 100644 --- a/test/test_helpers.hxx +++ b/test/test_helpers.hxx @@ -11,7 +11,7 @@ namespace test class test_failure : public std::logic_error { public: -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) test_failure( std::string const &desc, std::source_location loc = std::source_location::current()); @@ -21,7 +21,7 @@ public: ~test_failure() noexcept override; -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) constexpr char const *file() const noexcept { return m_loc.file_name(); } constexpr auto line() const noexcept { return m_loc.line(); } #else @@ -30,7 +30,7 @@ public: #endif private: -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) std::source_location m_loc; #else std::string const m_file; @@ -68,25 +68,25 @@ struct registrar // Unconditional test failure. -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) # define PQXX_CHECK_NOTREACHED(desc) pqxx::test::check_notreached((desc)) #else # define PQXX_CHECK_NOTREACHED(desc) \ pqxx::test::check_notreached(__FILE__, __LINE__, (desc)) #endif [[noreturn]] void check_notreached( -#if !pqxx_have_source_location +#if !defined(PQXX_HAVE_SOURCE_LOCATION) char const file[], int line, #endif std::string desc -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location loc = std::source_location::current() #endif ); // Verify that a condition is met, similar to assert() -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) # define PQXX_CHECK(condition, desc) \ pqxx::test::check((condition), #condition, (desc)) #else @@ -94,18 +94,18 @@ struct registrar pqxx::test::check(__FILE__, __LINE__, (condition), #condition, (desc)) #endif void check( -#if !pqxx_have_source_location +#if !defined(PQXX_HAVE_SOURCE_LOCATION) char const file[], int line, #endif bool condition, char const text[], std::string const &desc -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location loc = std::source_location::current() #endif ); // Verify that variable has the expected value. -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) # define PQXX_CHECK_EQUAL(actual, expected, desc) \ pqxx::test::check_equal((actual), #actual, (expected), #expected, (desc)) #else @@ -115,12 +115,12 @@ void check( #endif template inline void check_equal( -#if !pqxx_have_source_location +#if !defined(PQXX_HAVE_SOURCE_LOCATION) char const file[], int line, #endif ACTUAL actual, char const actual_text[], EXPECTED expected, char const expected_text[], std::string const &desc -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location loc = std::source_location::current() #endif @@ -136,7 +136,7 @@ inline void check_equal( ", " "expected=" + to_string(expected) + ")"; -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) throw test_failure{fulldesc, loc}; #else throw test_failure(file, line, fulldesc); @@ -144,7 +144,7 @@ inline void check_equal( } // Verify that two values are not equal. -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) # define PQXX_CHECK_NOT_EQUAL(value1, value2, desc) \ pqxx::test::check_not_equal((value1), #value1, (value2), #value2, (desc)) #else @@ -154,12 +154,12 @@ inline void check_equal( #endif template inline void check_not_equal( -#if !pqxx_have_source_location +#if !defined(PQXX_HAVE_SOURCE_LOCATION) char const file[], int line, #endif VALUE1 value1, char const text1[], VALUE2 value2, char const text2[], std::string const &desc -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location loc = std::source_location::current() #endif @@ -171,7 +171,7 @@ inline void check_not_equal( ": " "both are " + to_string(value2) + ")"; -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) throw test_failure{fulldesc, loc}; #else throw test_failure{file, line, fulldesc}; @@ -179,7 +179,7 @@ inline void check_not_equal( } -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) // Verify that value1 is less than value2. # define PQXX_CHECK_LESS(value1, value2, desc) \ pqxx::test::check_less((value1), #value1, (value2), #value2, (desc)) @@ -198,12 +198,12 @@ inline void check_not_equal( #endif template inline void check_less( -#if !pqxx_have_source_location +#if !defined(PQXX_HAVE_SOURCE_LOCATION) char const file[], int line, #endif VALUE1 value1, char const text1[], VALUE2 value2, char const text2[], std::string const &desc -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location loc = std::source_location::current() #endif @@ -218,7 +218,7 @@ inline void check_less( ", " "\"upper\"=" + to_string(value2) + ")"; -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) throw test_failure{fulldesc, loc}; #else throw test_failure(file, line, fulldesc); @@ -226,7 +226,7 @@ inline void check_less( } -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) // Verify that value1 is less than or equal to value2. # define PQXX_CHECK_LESS_EQUAL(value1, value2, desc) \ pqxx::test::check_less_equal((value1), #value1, (value2), #value2, (desc)) @@ -245,12 +245,12 @@ inline void check_less( #endif template inline void check_less_equal( -#if !pqxx_have_source_location +#if !defined(PQXX_HAVE_SOURCE_LOCATION) char const file[], int line, #endif VALUE1 value1, char const text1[], VALUE2 value2, char const text2[], std::string const &desc -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location loc = std::source_location::current() #endif @@ -265,7 +265,7 @@ inline void check_less_equal( ", " "\"upper\"=" + to_string(value2) + ")"; -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) throw test_failure{fulldesc, loc}; #else throw test_failure(file, line, fulldesc); @@ -361,7 +361,7 @@ inline void end_of_statement() {} } \ pqxx::test::internal::end_of_statement() -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) # define PQXX_CHECK_BOUNDS(value, lower, upper, desc) \ pqxx::test::check_bounds( \ (value), #value, (lower), #lower, (upper), #upper, (desc)) @@ -373,12 +373,12 @@ inline void end_of_statement() {} #endif template inline void check_bounds( -#if !pqxx_have_source_location +#if !defined(PQXX_HAVE_SOURCE_LOCATION) char const file[], int line, #endif VALUE value, char const text[], LOWER lower, char const lower_text[], UPPER upper, char const upper_text[], std::string const &desc -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , std::source_location loc = std::source_location::current() #endif @@ -390,34 +390,34 @@ inline void check_bounds( upper_check = std::string{text} + " < " + upper_text; pqxx::test::check( -#if !pqxx_have_source_location +#if !defined(PQXX_HAVE_SOURCE_LOCATION) file, line, #endif lower < upper, range_check.c_str(), desc + " (acceptable range is empty; value was " + text + ")" -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , loc #endif ); pqxx::test::check( -#if !pqxx_have_source_location +#if !defined(PQXX_HAVE_SOURCE_LOCATION) file, line, #endif not(value < lower), lower_check.c_str(), desc + " (" + text + " is below lower bound " + lower_text + ")" -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , loc #endif ); pqxx::test::check( -#if !pqxx_have_source_location +#if !defined(PQXX_HAVE_SOURCE_LOCATION) file, line, #endif value < upper, upper_check.c_str(), desc + " (" + text + " is not below upper bound " + upper_text + ")" -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) , loc #endif diff --git a/test/unit/test_field.cxx b/test/unit/test_field.cxx index 148818c38..42cfa8859 100644 --- a/test/unit/test_field.cxx +++ b/test/unit/test_field.cxx @@ -47,9 +47,9 @@ void test_field() auto const r3{tx.exec("SELECT generate_series(1, 5)")}; PQXX_CHECK_EQUAL(r3.at(3, 0).as(), 4, "Two-argument at() went wrong."); -#if pqxx_have_multidim +#if defined(PQXX_HAVE_MULTIDIM) PQXX_CHECK_EQUAL((r3[3, 0].as()), 4, "Two-argument [] went wrong."); -#endif // pqxx_have_multidim +#endif // PQXX_HAVE_MULTIDIM } diff --git a/test/unit/test_test_helpers.cxx b/test/unit/test_test_helpers.cxx index 4a197ae1c..2c0375091 100644 --- a/test/unit/test_test_helpers.cxx +++ b/test/unit/test_test_helpers.cxx @@ -21,7 +21,7 @@ void test_check_notreached() if (not failed) throw pqxx::test::test_failure { -#if !pqxx_have_source_location +#if !defined(PQXX_HAVE_SOURCE_LOCATION) __FILE__, __LINE__, #endif "PQXX_CHECK_NOTREACHED is broken." @@ -56,7 +56,7 @@ void test_check_throws_exception() "PQXX_CHECK_THROWS_EXCEPTION did not catch std::exception."); // ...or any exception type derived from it. -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) PQXX_CHECK_THROWS_EXCEPTION( throw pqxx::test::test_failure{"(expected)"}, "PQXX_CHECK_THROWS_EXCEPTION() failed to catch expected exception."); @@ -109,7 +109,7 @@ void test_check_throws_exception() // Test PQXX_CHECK_THROWS. void test_check_throws() { -#if pqxx_have_source_location +#if defined(PQXX_HAVE_SOURCE_LOCATION) PQXX_CHECK_THROWS( throw pqxx::test::test_failure{"(expected)"}, pqxx::test::test_failure, "PQXX_CHECK_THROWS() failed to catch expected exception.");