Avoid C-style const casts (#659)

* Avoid C-style const casts

Replace C-style casts that discard `const` with `const_cast` (and, where
necessary, `reinterpret_cast` as well).

* Warn about C-style const-discarding casts

Change pybind11_enable_warnings to also enable `-Wcast-qual` (warn if a
C-style cast discards `const`) by default. The previous commit should
have gotten rid of all of these (at least, all the ones that tripped in
my build, which included the tests), and this should discourage more
from newly appearing.
This commit is contained in:
Matthew Woehlke
2017-02-08 17:43:08 -05:00
committed by Wenzel Jakob
parent d534bd670e
commit e15fa9f99a
4 changed files with 18 additions and 15 deletions

View File

@@ -40,7 +40,7 @@ function(pybind11_enable_warnings target_name)
if(MSVC)
target_compile_options(${target_name} PRIVATE /W4)
else()
target_compile_options(${target_name} PRIVATE -Wall -Wextra -Wconversion)
target_compile_options(${target_name} PRIVATE -Wall -Wextra -Wconversion -Wcast-qual)
endif()
if(PYBIND11_WERROR)