From b15940c1e39262dd2b82babd15f9d7af2c2051a1 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Thu, 17 Sep 2015 13:45:35 -0600 Subject: [PATCH] Declare new VTKM_STATIC_ASSERT This is to be used in place of BOOST_STATIC_ASSERT so that we can control its implementation. The implementation is designed to fix the issue where the latest XCode clang compiler gives a warning about a unused typedefs when the boost static assert is used within a function. (This warning also happens when using the C++11 static_assert keyword.) You can suppress this warning with _Pragma commands, but _Pragma commands inside a block is not supported in GCC. The implementation of VTKM_STATIC_ASSERT handles all current cases. --- vtkm/CMakeLists.txt | 1 + vtkm/CellShape.h | 8 ++- vtkm/ListTag.h | 8 ++- vtkm/StaticAssert.h | 54 +++++++++++++++++++ vtkm/cont/ArrayHandleCompositeVector.h | 9 ++-- vtkm/cont/CellSet.h | 7 ++- vtkm/cont/Storage.h | 8 ++- vtkm/cont/arg/ControlSignatureTagBase.h | 8 ++- vtkm/cont/internal/DeviceAdapterTag.h | 11 ++-- vtkm/cont/internal/PointCoordinatesBase.h | 4 +- vtkm/exec/arg/ExecutionSignatureTagBase.h | 8 ++- .../testing/UnitTestWorkletInvokeFunctor.cxx | 9 ++-- vtkm/exec/testing/UnitTestCellDerivative.cxx | 5 +- vtkm/exec/testing/UnitTestCellInterpolate.cxx | 9 +--- .../testing/UnitTestParametricCoordinates.cxx | 6 +-- .../ConnectivityStructuredInternals.h | 9 ++-- vtkm/worklet/internal/DispatcherBase.h | 9 ++-- 17 files changed, 99 insertions(+), 74 deletions(-) create mode 100644 vtkm/StaticAssert.h diff --git a/vtkm/CMakeLists.txt b/vtkm/CMakeLists.txt index 39a352cd1..7004ae7d6 100644 --- a/vtkm/CMakeLists.txt +++ b/vtkm/CMakeLists.txt @@ -30,6 +30,7 @@ set(headers Math.h Matrix.h Pair.h + StaticAssert.h TopologyElementTag.h TypeListTag.h Types.h diff --git a/vtkm/CellShape.h b/vtkm/CellShape.h index ede90bdb8..e89efa4ee 100644 --- a/vtkm/CellShape.h +++ b/vtkm/CellShape.h @@ -20,10 +20,10 @@ #ifndef vtk_m_CellShape_h #define vtk_m_CellShape_h +#include #include VTKM_THIRDPARTY_PRE_INCLUDE -#include #include VTKM_THIRDPARTY_POST_INCLUDE @@ -75,11 +75,9 @@ struct CellShapeTagCheck : boost::false_type { }; /// tag. /// #define VTKM_IS_CELL_SHAPE_TAG(tag) \ - VTKM_THIRDPARTY_PRE_INCLUDE \ - BOOST_STATIC_ASSERT_MSG( \ + VTKM_STATIC_ASSERT_MSG( \ ::vtkm::internal::CellShapeTagCheck::value, \ - "Provided type is not a valid VTK-m cell shape tag.") \ - VTKM_THIRDPARTY_POST_INCLUDE + "Provided type is not a valid VTK-m cell shape tag.") /// A traits-like class to get an CellShapeId known at compile time to a tag. /// diff --git a/vtkm/ListTag.h b/vtkm/ListTag.h index 8cd3060f3..8c41686be 100644 --- a/vtkm/ListTag.h +++ b/vtkm/ListTag.h @@ -22,10 +22,10 @@ #include +#include #include VTKM_THIRDPARTY_PRE_INCLUDE -#include #include VTKM_THIRDPARTY_POST_INCLUDE @@ -48,11 +48,9 @@ struct ListTagCheck /// code when a mistake is made.) /// #define VTKM_IS_LIST_TAG(tag) \ - VTKM_THIRDPARTY_PRE_INCLUDE \ - BOOST_STATIC_ASSERT_MSG( \ + VTKM_STATIC_ASSERT_MSG( \ ::vtkm::internal::ListTagCheck::Valid, \ - "Provided type is not a valid VTK-m list tag.") \ - VTKM_THIRDPARTY_POST_INCLUDE + "Provided type is not a valid VTK-m list tag.") namespace detail { diff --git a/vtkm/StaticAssert.h b/vtkm/StaticAssert.h new file mode 100644 index 000000000..2b73affb3 --- /dev/null +++ b/vtkm/StaticAssert.h @@ -0,0 +1,54 @@ +//============================================================================ +// Copyright (c) Kitware, Inc. +// All rights reserved. +// See LICENSE.txt for details. +// This software is distributed WITHOUT ANY WARRANTY; without even +// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the above copyright notice for more information. +// +// Copyright 2015 Sandia Corporation. +// Copyright 2015 UT-Battelle, LLC. +// Copyright 2015 Los Alamos National Security. +// +// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, +// the U.S. Government retains certain rights in this software. +// +// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National +// Laboratory (LANL), the U.S. Government retains certain rights in +// this software. +//============================================================================ +#ifndef vtk_m_StaticAssert_h +#define vtk_m_StaticAssert_h + +#include + +VTKM_THIRDPARTY_PRE_INCLUDE +#include +VTKM_THIRDPARTY_POST_INCLUDE + +// Newer versions of clang are causing the static assert to issue a warning +// about unused typedefs. In this case, we want to disable the warnings using +// pragmas. However, not all compiler support pragmas in code blocks (although +// fortunately clang does). Thus, only use these pragmas in the instance where +// we need it and know we can use it. +#if defined(VTKM_CLANG) && (__apple_build_version__ >= 7000072) + +#define VTKM_STATIC_ASSERT(condition) \ + VTKM_THIRDPARTY_PRE_INCLUDE \ + BOOST_STATIC_ASSERT(condition) \ + VTKM_THIRDPARTY_POST_INCLUDE +#define VTKM_STATIC_ASSERT_MSG(condition, message) \ + VTKM_THIRDPARTY_PRE_INCLUDE \ + BOOST_STATIC_ASSERT_MSG(condition, message) \ + VTKM_THIRDPARTY_POST_INCLUDE + +#else + +#define VTKM_STATIC_ASSERT(condition) \ + BOOST_STATIC_ASSERT(condition) +#define VTKM_STATIC_ASSERT_MSG(condition, message) \ + BOOST_STATIC_ASSERT_MSG(condition, message) + +#endif + +#endif //vtk_m_StaticAssert_h diff --git a/vtkm/cont/ArrayHandleCompositeVector.h b/vtkm/cont/ArrayHandleCompositeVector.h index 9a43c9667..c7d2303f1 100644 --- a/vtkm/cont/ArrayHandleCompositeVector.h +++ b/vtkm/cont/ArrayHandleCompositeVector.h @@ -24,14 +24,11 @@ #include #include +#include #include #include -VTKM_THIRDPARTY_PRE_INCLUDE -#include -VTKM_THIRDPARTY_POST_INCLUDE - #include namespace vtkm { @@ -181,7 +178,7 @@ public: static const vtkm::IdComponent NUM_COMPONENTS = vtkm::VecTraits::NUM_COMPONENTS; - BOOST_STATIC_ASSERT(NUM_COMPONENTS == PortalTypes::ARITY); + VTKM_STATIC_ASSERT(NUM_COMPONENTS == PortalTypes::ARITY); VTKM_EXEC_CONT_EXPORT ArrayPortalCompositeVector() { } @@ -236,7 +233,7 @@ public: // If you get a compile error here, it means you probably tried to create // an ArrayHandleCompositeVector with a return type of a vector with a // different number of components than the number of arrays given. - BOOST_STATIC_ASSERT(NUM_COMPONENTS == FunctionInterfaceArrays::ARITY); + VTKM_STATIC_ASSERT(NUM_COMPONENTS == FunctionInterfaceArrays::ARITY); VTKM_CONT_EXPORT ArrayPortalCompositeVectorCont() : NumberOfValues(0) { } diff --git a/vtkm/cont/CellSet.h b/vtkm/cont/CellSet.h index 013b3bb68..e491da9b7 100644 --- a/vtkm/cont/CellSet.h +++ b/vtkm/cont/CellSet.h @@ -20,6 +20,8 @@ #ifndef vtk_m_cont_CellSet_h #define vtk_m_cont_CellSet_h +#include + #include #include #include @@ -27,7 +29,6 @@ #include VTKM_THIRDPARTY_PRE_INCLUDE -#include #include VTKM_THIRDPARTY_POST_INCLUDE @@ -95,9 +96,7 @@ struct CellSetCheck }; #define VTKM_IS_CELL_SET(T) \ - VTKM_THIRDPARTY_PRE_INCLUDE \ - BOOST_STATIC_ASSERT(::vtkm::cont::internal::CellSetCheck::type::value) \ - VTKM_THIRDPARTY_POST_INCLUDE + VTKM_STATIC_ASSERT(::vtkm::cont::internal::CellSetCheck::type::value) } // namespace internal diff --git a/vtkm/cont/Storage.h b/vtkm/cont/Storage.h index 4ff0d039e..538871a1d 100644 --- a/vtkm/cont/Storage.h +++ b/vtkm/cont/Storage.h @@ -28,11 +28,9 @@ #define VTKM_STORAGE VTKM_STORAGE_BASIC #endif -#include -VTKM_THIRDPARTY_PRE_INCLUDE -#include -VTKM_THIRDPARTY_POST_INCLUDE +#include +#include namespace vtkm { namespace cont { @@ -76,7 +74,7 @@ namespace detail { // arguments. template struct UndefinedArrayPortal { - BOOST_STATIC_ASSERT(sizeof(T) == static_cast(-1)); + VTKM_STATIC_ASSERT(sizeof(T) == static_cast(-1)); }; } // namespace detail diff --git a/vtkm/cont/arg/ControlSignatureTagBase.h b/vtkm/cont/arg/ControlSignatureTagBase.h index 3061e537c..66906cd25 100644 --- a/vtkm/cont/arg/ControlSignatureTagBase.h +++ b/vtkm/cont/arg/ControlSignatureTagBase.h @@ -20,10 +20,10 @@ #ifndef vtk_m_cont_arg_ControlSignatureTagBase_h #define vtk_m_cont_arg_ControlSignatureTagBase_h +#include #include VTKM_THIRDPARTY_PRE_INCLUDE -#include #include VTKM_THIRDPARTY_POST_INCLUDE @@ -62,11 +62,9 @@ struct ControlSignatureTagCheck /// get weird errors elsewhere in the code when a mistake is made.) /// #define VTKM_IS_CONTROL_SIGNATURE_TAG(tag) \ - VTKM_THIRDPARTY_PRE_INCLUDE \ - BOOST_STATIC_ASSERT_MSG( \ + VTKM_STATIC_ASSERT_MSG( \ ::vtkm::cont::arg::internal::ControlSignatureTagCheck::Valid, \ - "Provided a type that is not a valid ControlSignature tag.") \ - VTKM_THIRDPARTY_POST_INCLUDE + "Provided a type that is not a valid ControlSignature tag.") } } diff --git a/vtkm/cont/internal/DeviceAdapterTag.h b/vtkm/cont/internal/DeviceAdapterTag.h index 98a4980f0..a32fc5148 100644 --- a/vtkm/cont/internal/DeviceAdapterTag.h +++ b/vtkm/cont/internal/DeviceAdapterTag.h @@ -20,15 +20,12 @@ #ifndef vtk_m_cont_internal_DeviceAdapterTag_h #define vtk_m_cont_internal_DeviceAdapterTag_h +#include #include #include #include -VTKM_THIRDPARTY_PRE_INCLUDE -#include -VTKM_THIRDPARTY_POST_INCLUDE - #define VTKM_DEVICE_ADAPTER_ERROR -2 #define VTKM_DEVICE_ADAPTER_UNDEFINED -1 #define VTKM_DEVICE_ADAPTER_SERIAL 1 @@ -86,11 +83,9 @@ struct DeviceAdapterTagCheck /// elsewhere in the code when a mistake is made.) /// #define VTKM_IS_DEVICE_ADAPTER_TAG(tag) \ - VTKM_THIRDPARTY_PRE_INCLUDE \ - BOOST_STATIC_ASSERT_MSG( \ + VTKM_STATIC_ASSERT_MSG( \ ::vtkm::cont::internal::DeviceAdapterTagCheck::Valid, \ - "Provided type is not a valid VTK-m device adapter tag.") \ - VTKM_THIRDPARTY_POST_INCLUDE + "Provided type is not a valid VTK-m device adapter tag.") //----------------------------------------------------------------------------- #if VTKM_DEVICE_ADAPTER == VTKM_DEVICE_ADAPTER_SERIAL diff --git a/vtkm/cont/internal/PointCoordinatesBase.h b/vtkm/cont/internal/PointCoordinatesBase.h index 075166b9c..3c2e72b01 100644 --- a/vtkm/cont/internal/PointCoordinatesBase.h +++ b/vtkm/cont/internal/PointCoordinatesBase.h @@ -20,10 +20,10 @@ #ifndef vtk_m_cont_internal_PointCoordinatesBase_h #define vtk_m_cont_internal_PointCoordinatesBase_h +#include #include VTKM_THIRDPARTY_PRE_INCLUDE -#include #include VTKM_THIRDPARTY_POST_INCLUDE @@ -32,7 +32,7 @@ VTKM_THIRDPARTY_POST_INCLUDE /// argument is actually point coordinates. (You can get weird errors elsewhere /// in the code when a mistake is made.) #define VTKM_IS_POINT_COORDINATES(pctype) \ - BOOST_STATIC_ASSERT_MSG( \ + VTKM_STATIC_ASSERT_MSG( \ ::vtkm::cont::internal::IsValidPointCoordinates::type::value, \ "Provided type is not a valid VTK-m PointCoordinates type.") diff --git a/vtkm/exec/arg/ExecutionSignatureTagBase.h b/vtkm/exec/arg/ExecutionSignatureTagBase.h index 5148db77a..18bb9ade9 100644 --- a/vtkm/exec/arg/ExecutionSignatureTagBase.h +++ b/vtkm/exec/arg/ExecutionSignatureTagBase.h @@ -20,10 +20,10 @@ #ifndef vtk_m_exec_arg_ExecutionSignatureTagBase_h #define vtk_m_exec_arg_ExecutionSignatureTagBase_h +#include #include VTKM_THIRDPARTY_PRE_INCLUDE -#include #include VTKM_THIRDPARTY_POST_INCLUDE @@ -64,11 +64,9 @@ struct ExecutionSignatureTagCheck /// get weird errors elsewhere in the code when a mistake is made.) /// #define VTKM_IS_EXECUTION_SIGNATURE_TAG(tag) \ - VTKM_THIRDPARTY_PRE_INCLUDE \ - BOOST_STATIC_ASSERT_MSG( \ + VTKM_STATIC_ASSERT_MSG( \ ::vtkm::exec::arg::internal::ExecutionSignatureTagCheck::Valid, \ - "Provided a type that is not a valid ExecutionSignature tag.") \ - VTKM_THIRDPARTY_POST_INCLUDE + "Provided a type that is not a valid ExecutionSignature tag.") } } diff --git a/vtkm/exec/internal/testing/UnitTestWorkletInvokeFunctor.cxx b/vtkm/exec/internal/testing/UnitTestWorkletInvokeFunctor.cxx index 7b6f08988..c0347c70b 100644 --- a/vtkm/exec/internal/testing/UnitTestWorkletInvokeFunctor.cxx +++ b/vtkm/exec/internal/testing/UnitTestWorkletInvokeFunctor.cxx @@ -22,12 +22,13 @@ #include +#include + #include #include VTKM_THIRDPARTY_PRE_INCLUDE -#include #include VTKM_THIRDPARTY_POST_INCLUDE @@ -166,15 +167,15 @@ struct TestWorkletErrorProxy : vtkm::exec::FunctorBase // Check behavior of InvocationToFetch helper class. -BOOST_STATIC_ASSERT(( boost::is_same< +VTKM_STATIC_ASSERT(( boost::is_same< vtkm::exec::internal::detail::InvocationToFetch::type, vtkm::exec::arg::Fetch >::type::value )); -BOOST_STATIC_ASSERT(( boost::is_same< +VTKM_STATIC_ASSERT(( boost::is_same< vtkm::exec::internal::detail::InvocationToFetch::type, vtkm::exec::arg::Fetch >::type::value )); -BOOST_STATIC_ASSERT(( boost::is_same< +VTKM_STATIC_ASSERT(( boost::is_same< vtkm::exec::internal::detail::InvocationToFetch::type, vtkm::exec::arg::Fetch >::type::value )); diff --git a/vtkm/exec/testing/UnitTestCellDerivative.cxx b/vtkm/exec/testing/UnitTestCellDerivative.cxx index 228e1bf30..d9fd0d8c6 100644 --- a/vtkm/exec/testing/UnitTestCellDerivative.cxx +++ b/vtkm/exec/testing/UnitTestCellDerivative.cxx @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -76,9 +77,7 @@ void GetMinMaxPoints(CellShapeTag, { // If this line fails, then MAX_POINTS is not large enough to support all // cell shapes. - VTKM_THIRDPARTY_PRE_INCLUDE - BOOST_STATIC_ASSERT((vtkm::CellTraits::NUM_POINTS <= MAX_POINTS)); - VTKM_THIRDPARTY_POST_INCLUDE + VTKM_STATIC_ASSERT((vtkm::CellTraits::NUM_POINTS <= MAX_POINTS)); minPoints = maxPoints = vtkm::CellTraits::NUM_POINTS; } diff --git a/vtkm/exec/testing/UnitTestCellInterpolate.cxx b/vtkm/exec/testing/UnitTestCellInterpolate.cxx index 5090f7a1e..4b4edbcdd 100644 --- a/vtkm/exec/testing/UnitTestCellInterpolate.cxx +++ b/vtkm/exec/testing/UnitTestCellInterpolate.cxx @@ -24,15 +24,12 @@ #include #include +#include #include #include #include -VTKM_THIRDPARTY_PRE_INCLUDE -#include -VTKM_THIRDPARTY_POST_INCLUDE - namespace { static const vtkm::IdComponent MAX_POINTS = 8; @@ -45,9 +42,7 @@ void GetMinMaxPoints(CellShapeTag, { // If this line fails, then MAX_POINTS is not large enough to support all // cell shapes. - VTKM_THIRDPARTY_PRE_INCLUDE - BOOST_STATIC_ASSERT((vtkm::CellTraits::NUM_POINTS <= MAX_POINTS)); - VTKM_THIRDPARTY_POST_INCLUDE + VTKM_STATIC_ASSERT((vtkm::CellTraits::NUM_POINTS <= MAX_POINTS)); minPoints = maxPoints = vtkm::CellTraits::NUM_POINTS; } diff --git a/vtkm/exec/testing/UnitTestParametricCoordinates.cxx b/vtkm/exec/testing/UnitTestParametricCoordinates.cxx index deaf2c0cc..99885a053 100644 --- a/vtkm/exec/testing/UnitTestParametricCoordinates.cxx +++ b/vtkm/exec/testing/UnitTestParametricCoordinates.cxx @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -29,7 +30,6 @@ VTKM_THIRDPARTY_PRE_INCLUDE #include #include -#include VTKM_THIRDPARTY_POST_INCLUDE #include @@ -48,9 +48,7 @@ void GetMinMaxPoints(CellShapeTag, { // If this line fails, then MAX_POINTS is not large enough to support all // cell shapes. - VTKM_THIRDPARTY_PRE_INCLUDE - BOOST_STATIC_ASSERT((vtkm::CellTraits::NUM_POINTS <= MAX_POINTS)); - VTKM_THIRDPARTY_POST_INCLUDE + VTKM_STATIC_ASSERT((vtkm::CellTraits::NUM_POINTS <= MAX_POINTS)); minPoints = maxPoints = vtkm::CellTraits::NUM_POINTS; } diff --git a/vtkm/internal/ConnectivityStructuredInternals.h b/vtkm/internal/ConnectivityStructuredInternals.h index 4929c17b0..c1f34e7e3 100644 --- a/vtkm/internal/ConnectivityStructuredInternals.h +++ b/vtkm/internal/ConnectivityStructuredInternals.h @@ -22,14 +22,11 @@ #define vtk_m_internal_ConnectivityStructuredInternals_h #include +#include #include #include #include -VTKM_THIRDPARTY_PRE_INCLUDE -#include -VTKM_THIRDPARTY_POST_INCLUDE - namespace vtkm { namespace internal { @@ -526,8 +523,8 @@ struct ConnectivityStructuredIndexHelper // instantiated, because it means someone missed a topology mapping type. // We need to create a test which depends on the templated types so // it doesn't get picked up without a concrete instantiation. - BOOST_STATIC_ASSERT_MSG(sizeof(To) == static_cast(-1), - "Missing Specialization for Topologies"); + VTKM_STATIC_ASSERT_MSG(sizeof(To) == static_cast(-1), + "Missing Specialization for Topologies"); }; template diff --git a/vtkm/worklet/internal/DispatcherBase.h b/vtkm/worklet/internal/DispatcherBase.h index 26c4b5ba8..f5097a3c6 100644 --- a/vtkm/worklet/internal/DispatcherBase.h +++ b/vtkm/worklet/internal/DispatcherBase.h @@ -20,6 +20,8 @@ #ifndef vtk_m_worklet_internal_DispatcherBase_h #define vtk_m_worklet_internal_DispatcherBase_h +#include + #include #include @@ -38,7 +40,6 @@ VTKM_THIRDPARTY_PRE_INCLUDE #include -#include #include #include VTKM_THIRDPARTY_POST_INCLUDE @@ -264,12 +265,10 @@ private: const vtkm::internal::FunctionInterface ¶meters) const { typedef vtkm::internal::FunctionInterface ParameterInterface; + VTKM_STATIC_ASSERT_MSG(ParameterInterface::ARITY == NUM_INVOKE_PARAMS, + "Dispatcher Invoke called with wrong number of arguments."); - VTKM_THIRDPARTY_PRE_INCLUDE - BOOST_STATIC_ASSERT_MSG(ParameterInterface::ARITY == NUM_INVOKE_PARAMS, - "Dispatcher Invoke called with wrong number of arguments."); BOOST_MPL_ASSERT(( boost::is_base_of )); - VTKM_THIRDPARTY_POST_INCLUDE // As we do the dynamic transform, we are also going to check the static // type against the TypeCheckTag in the ControlSignature tags. To do this,