diff --git a/cmake/soci_utils.cmake b/cmake/soci_utils.cmake index 5095829d..40e35341 100644 --- a/cmake/soci_utils.cmake +++ b/cmake/soci_utils.cmake @@ -137,50 +137,4 @@ function(soci_public_dependency) endforeach() endfunction() -# This function can be used to check whether two C++ types actually refer to the same -# type (e.g. if one is aliased to the other). -# -# Use as -# soci_are_types_same( -# TYPES [... ] -# OUTPUT_VARIABLE -# ) -# where -# - , , are the types to test -# - is the name of the variable that will hold the result of the check -function(soci_are_types_same) - set(FLAGS "") - set(ONE_VAL_OPTIONS "OUTPUT_VARIABLE") - set(MULTI_VAL_OPTIONS "TYPES") - - cmake_parse_arguments(TYPES_SAME "${FLAGS}" "${ONE_VAL_OPTIONS}" "${MULTI_VAL_OPTIONS}" ${ARGV}) - soci_verify_parsed_arguments( - PREFIX "TYPES_SAME" - FUNCTION_NAME "soci_are_types_same" - REQUIRED "TYPES" "OUTPUT_VARIABLE" - ) - - set(TEST_CODE "#include \nstruct Foo { ") - set(TEST_NAME "") - foreach(CURRENT_TYPE IN LISTS TYPES_SAME_TYPES) - string(APPEND TEST_CODE "void foo(${CURRENT_TYPE} x); ") - string(TOUPPER "${CURRENT_TYPE}" UPPER_TYPE) - string(APPEND TEST_NAME "${UPPER_TYPE}_") - endforeach() - string(APPEND TEST_CODE "};\nint main() {}") - string(APPEND TEST_NAME "ARE_DISTINGUISHABLE") - - include(CheckCXXSourceCompiles) - - # If some of the provided types are actually the same, compilation - # will fail due to duplication of function declarations. - check_cxx_source_compiles("${TEST_CODE}" ${TEST_NAME}) - - if (${TEST_NAME}) - set("${TYPES_SAME_OUTPUT_VARIABLE}" FALSE PARENT_SCOPE) - else() - set("${TYPES_SAME_OUTPUT_VARIABLE}" TRUE PARENT_SCOPE) - endif() -endfunction() - set(SOCI_UTILS_ALREADY_INCLUDED TRUE) diff --git a/include/soci/exchange-traits.h b/include/soci/exchange-traits.h index bc4359ea..d5d1c965 100644 --- a/include/soci/exchange-traits.h +++ b/include/soci/exchange-traits.h @@ -45,7 +45,7 @@ struct exchange_traits }; template <> -struct exchange_traits +struct exchange_traits { typedef basic_type_tag type_family; enum { x_type = x_int8 }; @@ -117,14 +117,12 @@ struct exchange_traits enum { x_type = x_double }; }; -#ifndef SOCI_INT8_T_IS_CHAR template <> struct exchange_traits { typedef basic_type_tag type_family; enum { x_type = x_char }; }; -#endif // !SOCI_INT8_T_IS_CHAR template <> struct exchange_traits diff --git a/include/soci/soci-types.h b/include/soci/soci-types.h index bdfc367a..8f5bc5f8 100644 --- a/include/soci/soci-types.h +++ b/include/soci/soci-types.h @@ -35,4 +35,17 @@ using soci_ul_or_ull_int_t = std::conditional::type; +// We also specialize some templates for both char and int8_t, but they can be +// the same type, so in this case we define some other type to specialize the +// template for as we just can't do it for int8_t itself if it's the same as +// char, for which we always provide a specialization. +struct soci_int8_t_wrapper +{ + int8_t value = 0; +}; + +using soci_int8_t = + std::conditional::value, + soci_int8_t_wrapper, int8_t>::type; + #endif // SOCI_TYPES_H_INCLUDED diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bcd9de49..7aff9587 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,12 +8,6 @@ add_subdirectory(core) add_subdirectory(backends) -############################################################################### -# platform-dependent settings -############################################################################### - -soci_are_types_same(TYPES "int8_t" "char" OUTPUT_VARIABLE SOCI_INT8_T_IS_CHAR) - # Generate the soci-config.h file set(CONFIG_LINES "#ifndef SOCI_SOCICONFIG_H_INCLUDED" "#define SOCI_SOCICONFIG_H_INCLUDED" "") @@ -27,7 +21,6 @@ set(CONFIG_VARS SOCI_ORACLE SOCI_POSTGRESQL SOCI_SQLITE3 - SOCI_INT8_T_IS_CHAR ) set(CONFIG_MACROS SOCI_HAVE_EMPTY @@ -38,7 +31,6 @@ set(CONFIG_MACROS SOCI_HAVE_ORACLE SOCI_HAVE_POSTGRESQL SOCI_HAVE_SQLITE3 - SOCI_INT8_T_IS_CHAR ) list(LENGTH CONFIG_MACROS N_CONFIGS)