Skip to content

Commit 11c251a

Browse files
committed
ENH: Add compile definitions to enforce safer casting rules in CMake
Introduce compile-time options to prevent dangerous implicit casting in Qt. Add `PythonQt_NO_IMPLICIT_CASTING` for optional stricter casting rules.
1 parent bc9a2c8 commit 11c251a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,25 @@ enable_testing()
1818
set(CMAKE_CXX_STANDARD 11)
1919
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2020

21+
# Force errors for dangerous operations
22+
add_compile_definitions( -DQT_NO_CAST_TO_ASCII )
23+
24+
option(PythonQt_NO_IMPLICIT_CASTING "Disable implicit casts related to dangerous implicit conversions" OFF)
25+
if(PythonQt_NO_IMPLICIT_CASTING) # Definitions to force
26+
# errors on dangerous implicit operations
27+
# to be addressed at a later time
28+
add_compile_definitions( -DQT_NO_CAST_FROM_ASCII
29+
-DQT_NO_CAST_FROM_ASCII
30+
-DQT_NO_CAST_TO_BYTEARRAY
31+
-DQT_NO_CAST_FROM_BYTEARRAY
32+
-DQT_NO_CAST_TO_QSTRING
33+
-DQT_NO_CAST_FROM_QSTRING
34+
-DQT_NO_CAST_TO_QSTRINGREF
35+
-DQT_NO_CAST_FROM_QSTRINGREF
36+
-DQT_NO_CAST_TO_QVARIANT
37+
-DQT_NO_CAST_FROM_QVARIANT )
38+
endif()
39+
2140
option(FORCE_BUILD_QT5 "Force Qt5 build instead of Qt6" OFF)
2241

2342
if(FORCE_BUILD_QT5)

0 commit comments

Comments
 (0)