From 20ee9352038f961b5a9d76c986c9ae088f8ea969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Boris=20Sch=C3=A4ling?= Date: Sat, 28 May 2016 12:26:18 +0200 Subject: [PATCH] Use decltype to deduce return type of PyThread_create_key --- CMakeLists.txt | 2 +- example/example10.cpp | 2 +- example/example4.cpp | 2 +- include/pybind11/common.h | 2 +- include/pybind11/pybind11.h | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 510d4936d..0452d5dab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,7 +81,7 @@ if(MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") endif() elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wconversion") endif() diff --git a/example/example10.cpp b/example/example10.cpp index cbe737e72..06528c2f0 100644 --- a/example/example10.cpp +++ b/example/example10.cpp @@ -13,7 +13,7 @@ double my_func(int x, float y, double z) { std::cout << "my_func(x:int=" << x << ", y:float=" << y << ", z:float=" << z << ")" << std::endl; - return x*y*z; + return (float) x*y*z; } std::complex my_func3(std::complex c) { diff --git a/example/example4.cpp b/example/example4.cpp index 281eafed5..7e17864e0 100644 --- a/example/example4.cpp +++ b/example/example4.cpp @@ -38,7 +38,7 @@ void test_function2(EMyEnumeration k) { float test_function3(int i) { std::cout << "test_function(" << i << ")" << std::endl; - return i / 2.f; + return (float) i / 2.f; } py::bytes return_bytes() { diff --git a/include/pybind11/common.h b/include/pybind11/common.h index 43e41d8d0..272c207e1 100644 --- a/include/pybind11/common.h +++ b/include/pybind11/common.h @@ -262,7 +262,7 @@ struct internals { std::unordered_map registered_instances; // void * -> PyObject* std::unordered_set, overload_hash> inactive_overload_cache; #if defined(WITH_THREAD) - long tstate = 0; + decltype(PyThread_create_key()) tstate = 0; // Usually an int but a long on Cygwin64 with Python 3.x PyInterpreterState *istate = nullptr; #endif }; diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index ee76a6702..46923de4c 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1115,7 +1115,7 @@ public: gil_scoped_release(bool disassoc = false) : disassoc(disassoc) { tstate = PyEval_SaveThread(); if (disassoc) { - int key = detail::get_internals().tstate; + auto key = detail::get_internals().tstate; #if PY_MAJOR_VERSION < 3 PyThread_delete_key_value(key); #else @@ -1128,7 +1128,7 @@ public: return; PyEval_RestoreThread(tstate); if (disassoc) { - int key = detail::get_internals().tstate; + auto key = detail::get_internals().tstate; #if PY_MAJOR_VERSION < 3 PyThread_delete_key_value(key); #endif