From 8b31fda810e7494a8eeb17ddb610797cefe29423 Mon Sep 17 00:00:00 2001 From: Hans Dembinski Date: Mon, 15 Apr 2024 09:52:04 +0200 Subject: [PATCH] check for odr violations and fix odr violation (#985) Closes #976 This fixes an ODR violation and adds more warnings regarding ODR violations to the standard build flags (which are treated as errors). --- CMakeLists.txt | 14 +++++++++++++- src/type_caster.hpp | 7 +++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eb69d67f7..b057ebe0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,8 +85,20 @@ set(SOURCES_B pybind11_add_module(_core MODULE ${SOURCES_A} ${SOURCES_B}) if(MSVC) target_compile_options(_core PRIVATE /std:c++14 /Y-) +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + # lots of warnings from gcc, including odr violations + target_compile_options( + _core + PRIVATE -Wall + -Wextra + -pedantic + -Werror + -fstrict-aliasing + -Werror=odr + -Werror=lto-type-mismatch + -Werror=strict-aliasing) else() - # lots of warnings from clang and gcc + # lots of warnings from clang target_compile_options(_core PRIVATE -Wall -Wextra -pedantic -Werror -fstrict-aliasing) endif() diff --git a/src/type_caster.hpp b/src/type_caster.hpp index db8022289..9b0ae5845 100644 --- a/src/type_caster.hpp +++ b/src/type_caster.hpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -6,9 +5,9 @@ namespace pybind11 { namespace detail { -template -struct type_caster> { - using vec_t = std::vector; +template +struct type_caster> { + using vec_t = std::vector; using value_conv = make_caster; using size_conv = make_caster;