From 6b6078ab3f6e665d07a78fc3a8360b22a0afe953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Guzm=C3=A1n?= Date: Tue, 19 Apr 2022 21:12:46 -0600 Subject: [PATCH 1/4] use int64_t instead of long long(unit tests) using long long may be ambigous for the compiler in the call of bind() using a fixed type(int64_t) solves this issue this issue was replicated on both Arch Linux&Windows with clang 13.0.1/14.0.1 --- tests/Statement_test.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/Statement_test.cpp b/tests/Statement_test.cpp index 8a79a18f..ca0497ec 100644 --- a/tests/Statement_test.cpp +++ b/tests/Statement_test.cpp @@ -12,6 +12,7 @@ #include #include +#include // for int64_t #include // for SQLITE_DONE #include @@ -327,7 +328,7 @@ TEST(Statement, bindings) // Fourth row with string/int64/float { const std::string fourth("fourth"); - const long long int64 = 12345678900000LL; + const int64_t int64 = 12345678900000LL; const float float32 = 0.234f; insert.bind(1, fourth); insert.bind(2, int64); @@ -491,7 +492,7 @@ TEST(Statement, bindByName) // Second row with string/int64/float { const std::string second("second"); - const long long int64 = 12345678900000LL; + const int64_t int64 = 12345678900000LL; const long integer = -123; const float float32 = 0.234f; insert.bind("@msg", second); @@ -604,7 +605,7 @@ TEST(Statement, bindByNameString) // Second row with string/int64/float { const std::string second("second"); - const long long int64 = 12345678900000LL; + const int64_t int64 = 12345678900000LL; const long integer = -123; const float float32 = 0.234f; insert.bind(amsg, second); From 179ef091c618c5e177dcd1ccad9fadd705e9b860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Guzm=C3=A1n?= Date: Tue, 19 Apr 2022 21:58:04 -0600 Subject: [PATCH 2/4] define preprocesor definition define NON_AMBIGOUS_OVERLOAD to prevent ambiguous overload and use int instead of long to prevent ambiguous overload errors --- meson.build | 21 ++++++++++++++++----- tests/Statement_test.cpp | 13 +++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index e064971a..5447d8b8 100644 --- a/meson.build +++ b/meson.build @@ -46,6 +46,8 @@ sqlitecpp_deps = [ sqlite3_dep, thread_dep, ] +## used to override the default sqlitecpp options like cpp standard +sqlitecpp_opts = [] ## tests @@ -59,6 +61,10 @@ sqlitecpp_test_srcs = [ 'tests/Exception_test.cpp', 'tests/ExecuteMany_test.cpp', ] +sqlitecpp_test_args = [ + # do not use ambiguous overloads by default + '-DNON_AMBIGOUS_OVERLOAD' +] ## samples @@ -131,10 +137,11 @@ libsqlitecpp = library( include_directories: sqlitecpp_incl, cpp_args: sqlitecpp_args, dependencies: sqlitecpp_deps, + # override the default options + override_options: sqlitecpp_opts, # install: true, # API version for SQLiteCpp shared library. - version: '0', -) + version: '0',) install_headers( 'include/SQLiteCpp/SQLiteCpp.h', @@ -164,10 +171,12 @@ if get_option('SQLITECPP_BUILD_TESTS') sqlitecpp_dep, sqlite3_dep, ] - sqlitecpp_test_args = [] testexe = executable('testexe', sqlitecpp_test_srcs, - dependencies: sqlitecpp_test_dependencies) + dependencies: sqlitecpp_test_dependencies, + cpp_args: sqlitecpp_test_args, + # override the default options + override_options: sqlitecpp_opts,) test_args = [] @@ -177,7 +186,9 @@ if get_option('SQLITECPP_BUILD_EXAMPLES') ## demo executable sqlitecpp_demo_exe = executable('SQLITECPP_sample_demo', sqlitecpp_sample_srcs, - dependencies: sqlitecpp_dep) + dependencies: sqlitecpp_dep, + # override the default options + override_options: sqlitecpp_opts,) endif pkgconfig = import('pkgconfig') diff --git a/tests/Statement_test.cpp b/tests/Statement_test.cpp index ca0497ec..87ad244d 100644 --- a/tests/Statement_test.cpp +++ b/tests/Statement_test.cpp @@ -374,7 +374,12 @@ TEST(Statement, bindings) // Sixth row with uint32_t unsigned value and a long value (which is either a 32b int or a 64b long long) { const uint32_t uint32 = 4294967295U; + // preprocessor define to force not use long and use instead uint + #if NON_AMBIGOUS_OVERLOAD + const int integer = -123; + #else const long integer = -123; + #endif insert.bind(2, uint32); insert.bind(3, integer); EXPECT_EQ(1, insert.exec()); @@ -493,7 +498,11 @@ TEST(Statement, bindByName) { const std::string second("second"); const int64_t int64 = 12345678900000LL; + #if NON_AMBIGOUS_OVERLOAD + const int integer = -123; + #else const long integer = -123; + #endif const float float32 = 0.234f; insert.bind("@msg", second); insert.bind("@int", int64); @@ -606,7 +615,11 @@ TEST(Statement, bindByNameString) { const std::string second("second"); const int64_t int64 = 12345678900000LL; + #if NON_AMBIGOUS_OVERLOAD + const int integer = -123; + #else const long integer = -123; + #endif const float float32 = 0.234f; insert.bind(amsg, second); insert.bind(aint, int64); From 9f5d446e36c37824a7321c16e1b4603d80b67a58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Guzm=C3=A1n?= Date: Tue, 19 Apr 2022 21:59:52 -0600 Subject: [PATCH 3/4] use c++14 on windows on windows may show an error in xstddef if c++11 is used this is a workarround for that issue "deduced return types are a C++14 extension" --- meson.build | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 5447d8b8..81058e19 100644 --- a/meson.build +++ b/meson.build @@ -84,7 +84,14 @@ if not (host_machine.system() == 'windows' and cxx.get_id() == 'msvc') '-Wno-long-long', ] endif - +## using MSVC headers requires c++14, if not will show an error on xstddef as: +## 'auto' return without trailing return type; deduced return types are a C++14 extension +if host_machine.system() == 'windows' + message('[WINDOWS] using c++14 standard') + sqlitecpp_opts += [ + 'cpp_std=c++14', + ] +endif # Options relative to SQLite and SQLiteC++ functions if get_option('SQLITE_ENABLE_COLUMN_METADATA') From e32daec169af42fcf401e636c1653dcf590d88e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Guzm=C3=A1n?= Date: Tue, 19 Apr 2022 22:03:40 -0600 Subject: [PATCH 4/4] link library statically when building unit tests make the meson file link statically the library when building the unit tests executable so it does not fail on windows as the symbols are not exported by default --- meson.build | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 81058e19..fb6f6588 100644 --- a/meson.build +++ b/meson.build @@ -149,6 +149,18 @@ libsqlitecpp = library( # install: true, # API version for SQLiteCpp shared library. version: '0',) +if get_option('SQLITECPP_BUILD_TESTS') + # for the unit tests we need to link against a static version of SQLiteCpp + libsqlitecpp_static = static_library( + 'sqlitecpp_static', + sqlitecpp_srcs, + include_directories: sqlitecpp_incl, + cpp_args: sqlitecpp_args, + dependencies: sqlitecpp_deps, + # override the default options + override_options: sqlitecpp_opts,) + # static libraries do not have a version +endif install_headers( 'include/SQLiteCpp/SQLiteCpp.h', @@ -167,6 +179,14 @@ sqlitecpp_dep = declare_dependency( include_directories: sqlitecpp_incl, link_with: libsqlitecpp, ) +if get_option('SQLITECPP_BUILD_TESTS') + ## make the dependency static so the unit tests can link against it + ## (mainly for windows as the symbols are not exported by default) + sqlitecpp_static_dep = declare_dependency( + include_directories: sqlitecpp_incl, + link_with: libsqlitecpp_static, + ) +endif if get_option('SQLITECPP_BUILD_TESTS') gtest_dep = dependency( @@ -175,7 +195,7 @@ if get_option('SQLITECPP_BUILD_TESTS') fallback: ['gtest', 'gtest_dep']) sqlitecpp_test_dependencies = [ gtest_dep, - sqlitecpp_dep, + sqlitecpp_static_dep, sqlite3_dep, ]