diff --git a/mssql_python/pybind/CMakeLists.txt b/mssql_python/pybind/CMakeLists.txt index 5d1e28f4..45893318 100644 --- a/mssql_python/pybind/CMakeLists.txt +++ b/mssql_python/pybind/CMakeLists.txt @@ -8,6 +8,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) # Enable verbose output to see actual compiler/linker commands set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "Verbose output" FORCE) +# Treat CMake warnings as errors +set(CMAKE_ERROR_DEPRECATED TRUE) +set(CMAKE_WARN_DEPRECATED TRUE) + if (MSVC) # Security compiler options for OneBranch compliance message(STATUS "Applying MSVC security compiler options for OneBranch compliance") @@ -302,6 +306,21 @@ if(MSVC) target_compile_options(ddbc_bindings PRIVATE /W4 /WX) endif() +# Add warning flags for GCC/Clang on Linux and macOS +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + target_compile_options(ddbc_bindings PRIVATE + -Werror # Treat warnings as errors + -Wattributes # Enable attribute warnings (cross-compiler) + ) + + # GCC-specific warning flags + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_compile_options(ddbc_bindings PRIVATE + -Wint-to-pointer-cast # GCC-specific warning for integer-to-pointer casts + ) + endif() +endif() + # Add macOS-specific string conversion fix if(APPLE) message(STATUS "Enabling macOS string conversion fix") diff --git a/mssql_python/pybind/ddbc_bindings.cpp b/mssql_python/pybind/ddbc_bindings.cpp index 9a828011..31cdc514 100644 --- a/mssql_python/pybind/ddbc_bindings.cpp +++ b/mssql_python/pybind/ddbc_bindings.cpp @@ -114,6 +114,13 @@ py::object get_uuid_class() { // Struct to hold parameter information for binding. Used by SQLBindParameter. // This struct is shared between C++ & Python code. +// Suppress -Wattributes warning for ParamInfo struct +// The warning is triggered because pybind11 handles visibility attributes automatically, +// and having additional attributes on the struct can cause conflicts on Linux with GCC +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wattributes" +#endif struct ParamInfo { SQLSMALLINT inputOutputType; SQLSMALLINT paramCType; @@ -124,6 +131,9 @@ struct ParamInfo { bool isDAE = false; // Indicates if we need to stream py::object dataPtr; }; +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif // Mirrors the SQL_NUMERIC_STRUCT. But redefined to replace val char array // with std::string, because pybind doesn't allow binding char array. @@ -713,7 +723,7 @@ SQLRETURN BindParameters(SQLHANDLE hStmt, const py::list& params, } SQL_NUMERIC_STRUCT* numericPtr = reinterpret_cast(dataPtr); rc = SQLSetDescField_ptr(hDesc, 1, SQL_DESC_PRECISION, - (SQLPOINTER)numericPtr->precision, 0); + reinterpret_cast(static_cast(numericPtr->precision)), 0); if (!SQL_SUCCEEDED(rc)) { LOG("BindParameters: SQLSetDescField(SQL_DESC_PRECISION) " "failed for param[%d] - SQLRETURN=%d", @@ -721,7 +731,7 @@ SQLRETURN BindParameters(SQLHANDLE hStmt, const py::list& params, return rc; } - rc = SQLSetDescField_ptr(hDesc, 1, SQL_DESC_SCALE, (SQLPOINTER)numericPtr->scale, 0); + rc = SQLSetDescField_ptr(hDesc, 1, SQL_DESC_SCALE, reinterpret_cast(static_cast(numericPtr->scale)), 0); if (!SQL_SUCCEEDED(rc)) { LOG("BindParameters: SQLSetDescField(SQL_DESC_SCALE) failed " "for param[%d] - SQLRETURN=%d", @@ -729,7 +739,7 @@ SQLRETURN BindParameters(SQLHANDLE hStmt, const py::list& params, return rc; } - rc = SQLSetDescField_ptr(hDesc, 1, SQL_DESC_DATA_PTR, (SQLPOINTER)numericPtr, 0); + rc = SQLSetDescField_ptr(hDesc, 1, SQL_DESC_DATA_PTR, reinterpret_cast(numericPtr), 0); if (!SQL_SUCCEEDED(rc)) { LOG("BindParameters: SQLSetDescField(SQL_DESC_DATA_PTR) failed " "for param[%d] - SQLRETURN=%d",