Skip to content

style: avoid using unintialized variables #2806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()

set(pybind11_system "")
else()
set(PYBIND11_MASTER_PROJECT OFF)
set(pybind11_system SYSTEM)
Expand Down
25 changes: 18 additions & 7 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ include(CMakeParseArguments)
# Usage:
# pybind11_filter_tests(LISTNAME file1.cpp file2.cpp ... MESSAGE "")
#
macro(PYBIND11_FILTER_TESTS LISTNAME)
macro(pybind11_filter_tests LISTNAME)
cmake_parse_arguments(ARG "" "MESSAGE" "" ${ARGN})
set(PYBIND11_FILTER_TESTS_FOUND OFF)
foreach(filename IN LISTS ARG_UNPARSED_ARGUMENTS)
Expand All @@ -39,6 +39,14 @@ macro(PYBIND11_FILTER_TESTS LISTNAME)
endif()
endmacro()

macro(possibly_uninitialized)
foreach(VARNAME ${ARGN})
if(NOT DEFINED "${VARNAME}")
set("${VARNAME}" "")
endif()
endforeach()
endmacro()

# New Python support
if(DEFINED Python_EXECUTABLE)
set(PYTHON_EXECUTABLE "${Python_EXECUTABLE}")
Expand Down Expand Up @@ -67,7 +75,7 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
find_package(pybind11 REQUIRED CONFIG)
endif()

if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
if(NOT CMAKE_BUILD_TYPE AND NOT DEFINED CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting tests build type to MinSizeRel as none was specified")
set(CMAKE_BUILD_TYPE
MinSizeRel
Expand Down Expand Up @@ -345,11 +353,14 @@ foreach(target ${test_targets})
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY
"${CMAKE_CURRENT_BINARY_DIR}")
foreach(config ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${config} config)
set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${config}
"${CMAKE_CURRENT_BINARY_DIR}")
endforeach()

if(DEFINED CMAKE_CONFIGURATION_TYPES)
foreach(config ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${config} config)
set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${config}
"${CMAKE_CURRENT_BINARY_DIR}")
endforeach()
endif()
endif()
endforeach()

Expand Down
2 changes: 2 additions & 0 deletions tests/test_cmake_build/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ function(pybind11_add_build_test name)
add_dependencies(test_cmake_build test_build_${name})
endfunction()

possibly_uninitialized(PYTHON_MODULE_EXTENSION Python_INTERPRETER_ID)

pybind11_add_build_test(subdirectory_function)
pybind11_add_build_test(subdirectory_target)
if("${PYTHON_MODULE_EXTENSION}" MATCHES "pypy" OR "${Python_INTERPRETER_ID}" STREQUAL "PyPy")
Expand Down
3 changes: 3 additions & 0 deletions tests/test_embed/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
possibly_uninitialized(PYTHON_MODULE_EXTENSION Python_INTERPRETER_ID)

if("${PYTHON_MODULE_EXTENSION}" MATCHES "pypy" OR "${Python_INTERPRETER_ID}" STREQUAL "PyPy")
message(STATUS "Skipping embed test on PyPy")
add_custom_target(cpptest) # Dummy target on PyPy. Embedding is not supported.
set(_suppress_unused_variable_warning "${DOWNLOAD_CATCH}")
return()
Expand Down
3 changes: 3 additions & 0 deletions tools/FindEigen3.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ if(EIGEN3_INCLUDE_DIR)
set(EIGEN3_FOUND ${EIGEN3_VERSION_OK})

else(EIGEN3_INCLUDE_DIR)
if(NOT DEFINED KDE4_INCLUDE_DIR)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right, we can't use possibly_uninitialized here? Ah, too bad. So the solution is already less useful :-)

set(KDE4_INCLUDE_DIR "")
endif()

find_path(
EIGEN3_INCLUDE_DIR
Expand Down
2 changes: 2 additions & 0 deletions tools/FindPythonLibsNew.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ endif()

if(PythonLibsNew_FIND_QUIETLY)
set(_pythonlibs_quiet QUIET)
else()
set(_pythonlibs_quiet "")
endif()

if(PythonLibsNew_FIND_REQUIRED)
Expand Down
2 changes: 2 additions & 0 deletions tools/pybind11NewTools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ get_property(

if(pybind11_FIND_QUIETLY)
set(_pybind11_quiet QUIET)
else()
set(_pybind11_quiet "")
endif()

if(CMAKE_VERSION VERSION_LESS 3.12)
Expand Down
11 changes: 9 additions & 2 deletions tools/pybind11Tools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ include(CMakeParseArguments)

if(pybind11_FIND_QUIETLY)
set(_pybind11_quiet QUIET)
else()
set(_pybind11_quiet "")
endif()

# If this is the first run, PYTHON_VERSION can stand in for PYBIND11_PYTHON_VERSION
Expand All @@ -22,11 +24,16 @@ if(NOT DEFINED PYBIND11_PYTHON_VERSION AND DEFINED PYTHON_VERSION)
CACHE STRING "Python version to use for compiling modules")
unset(PYTHON_VERSION)
unset(PYTHON_VERSION CACHE)
else()
# If this is set as a normal variable, promote it, otherwise, make an empty cache variable.
elseif(DEFINED PYBIND11_PYTHON_VERSION)
# If this is set as a normal variable, promote it
set(PYBIND11_PYTHON_VERSION
"${PYBIND11_PYTHON_VERSION}"
CACHE STRING "Python version to use for compiling modules")
else()
# Make an empty cache variable.
set(PYBIND11_PYTHON_VERSION
""
CACHE STRING "Python version to use for compiling modules")
endif()

# A user can set versions manually too
Expand Down