mirror of
https://github.com/allankoechke/soci.git
synced 2026-11-30 10:58:24 +00:00
Get rid of SOCI_INT8_T_IS_CHAR too
As we can't specialize exchange_traits<> for both int8_t and char when they are the same type (which is the case under Solaris, see #1154), specialize exchange_traits<> for some wrapper type in this case to avoid compilation errors. This is an alternative, and simpler, solution than that of #1170, so we can now remove soci_are_types_same CMake function.
This commit is contained in:
@@ -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 <type1> <type2> [... <typeN>]
|
||||
# OUTPUT_VARIABLE <name>
|
||||
# )
|
||||
# where
|
||||
# - <type1>, <type2>, <typeN> are the types to test
|
||||
# - <name> 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 <cstdint>\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)
|
||||
|
||||
@@ -45,7 +45,7 @@ struct exchange_traits
|
||||
};
|
||||
|
||||
template <>
|
||||
struct exchange_traits<int8_t>
|
||||
struct exchange_traits<soci_int8_t>
|
||||
{
|
||||
typedef basic_type_tag type_family;
|
||||
enum { x_type = x_int8 };
|
||||
@@ -117,14 +117,12 @@ struct exchange_traits<double>
|
||||
enum { x_type = x_double };
|
||||
};
|
||||
|
||||
#ifndef SOCI_INT8_T_IS_CHAR
|
||||
template <>
|
||||
struct exchange_traits<char>
|
||||
{
|
||||
typedef basic_type_tag type_family;
|
||||
enum { x_type = x_char };
|
||||
};
|
||||
#endif // !SOCI_INT8_T_IS_CHAR
|
||||
|
||||
template <>
|
||||
struct exchange_traits<std::string>
|
||||
|
||||
@@ -35,4 +35,17 @@ using soci_ul_or_ull_int_t =
|
||||
std::conditional<sizeof(soci_ul_or_ull_t) == 4,
|
||||
uint32_t, uint64_t>::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<std::is_same<int8_t, char>::value,
|
||||
soci_int8_t_wrapper, int8_t>::type;
|
||||
|
||||
#endif // SOCI_TYPES_H_INCLUDED
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user