Skip to content

Commit

Permalink
check for odr violations and fix odr violation (#985)
Browse files Browse the repository at this point in the history
Closes #976 

This fixes an ODR violation and adds more warnings regarding ODR
violations to the standard build flags (which are treated as errors).
  • Loading branch information
HDembinski committed Apr 15, 2024
1 parent a786736 commit 8b31fda
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
14 changes: 13 additions & 1 deletion CMakeLists.txt
Expand Up @@ -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()
Expand Down
7 changes: 3 additions & 4 deletions src/type_caster.hpp
@@ -1,14 +1,13 @@
#include <algorithm>
#include <pybind11/numpy.h>
#include <pybind11/pybind11.h>
#include <vector>

namespace pybind11 {
namespace detail {

template <typename Value>
struct type_caster<std::vector<Value>> {
using vec_t = std::vector<Value>;
template <typename Value, typename Alloc>
struct type_caster<std::vector<Value, Alloc>> {
using vec_t = std::vector<Value, Alloc>;
using value_conv = make_caster<Value>;
using size_conv = make_caster<std::size_t>;

Expand Down

0 comments on commit 8b31fda

Please sign in to comment.