From bc5533bda8747873ff17d402a2b46517858d8627 Mon Sep 17 00:00:00 2001 From: Mark Pictor Date: Mon, 3 Aug 2015 21:37:28 -0400 Subject: [PATCH] test for, and use, nullptr if we have it --- CMakeLists.txt | 3 +++ cmake/SC_Config_Headers.cmake | 18 ++++++++++++++++-- include/sc_cf_cmake.h.in | 1 + src/base/CMakeLists.txt | 1 + src/base/sc_nullptr.h | 13 +++++++++++++ src/clstepcore/mgrnode.h | 5 +++-- src/clstepcore/sdaiApplication_instance.cc | 4 +++- test/cpp/schema_specific/CMakeLists.txt | 2 +- 8 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 src/base/sc_nullptr.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 97c0be91..bc0ef653 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -114,6 +114,9 @@ elseif(BORLAND) add_definitions(-D__BORLAND__ -D__WIN32__) else() add_definitions(-pedantic -W -Wall -Wundef -Wfloat-equal -Wshadow -Winline -Wno-long-long) + if(HAVE_NULLPTR) + list(APPEND CMAKE_CXX_FLAGS -std=c++11) + endif(HAVE_NULLPTR) endif() include_directories( diff --git a/cmake/SC_Config_Headers.cmake b/cmake/SC_Config_Headers.cmake index 6fe3e7c6..5c985296 100644 --- a/cmake/SC_Config_Headers.cmake +++ b/cmake/SC_Config_Headers.cmake @@ -57,7 +57,7 @@ int main() { " ) cmake_push_check_state() if( UNIX ) - set( CMAKE_REQUIRED_FLAGS "-pthread -std=c++0x" ) + set( CMAKE_REQUIRED_FLAGS "-pthread -std=c++11" ) else( UNIX ) # vars probably need set for embarcadero, etc endif( UNIX ) @@ -74,13 +74,27 @@ int main() { " ) cmake_push_check_state() if( UNIX ) - set( CMAKE_REQUIRED_FLAGS "-std=c++0x" ) + set( CMAKE_REQUIRED_FLAGS "-std=c++11" ) else( UNIX ) # vars probably need set for embarcadero, etc endif( UNIX ) CHECK_CXX_SOURCE_RUNS( "${TEST_STD_CHRONO}" HAVE_STD_CHRONO ) #quotes are *required*! cmake_pop_check_state() +set( TEST_NULLPTR " +#include +std::nullptr_t f() {return nullptr;} +int main() {return !!f();} +" ) +cmake_push_check_state() + if( UNIX ) + set( CMAKE_REQUIRED_FLAGS "-std=c++11" ) + else( UNIX ) + # vars probably need set for embarcadero, etc + endif( UNIX ) + CHECK_CXX_SOURCE_RUNS( "${TEST_NULLPTR}" HAVE_NULLPTR ) #quotes are *required*! +cmake_pop_check_state() + # Now that all the tests are done, configure the sc_cf.h file: get_property(CONFIG_H_FILE_CONTENTS GLOBAL PROPERTY SC_CONFIG_H_CONTENTS) file(WRITE ${CONFIG_H_FILE} "${CONFIG_H_FILE_CONTENTS}") diff --git a/include/sc_cf_cmake.h.in b/include/sc_cf_cmake.h.in index 417e5c57..3d744d15 100644 --- a/include/sc_cf_cmake.h.in +++ b/include/sc_cf_cmake.h.in @@ -25,5 +25,6 @@ #cmakedefine HAVE_STD_THREAD 1 #cmakedefine HAVE_STD_CHRONO 1 +#cmakedefine HAVE_NULLPTR 1 #endif /* SCL_CF_H */ diff --git a/src/base/CMakeLists.txt b/src/base/CMakeLists.txt index 8ce6eb25..cbfd2cbc 100644 --- a/src/base/CMakeLists.txt +++ b/src/base/CMakeLists.txt @@ -14,6 +14,7 @@ set(SC_BASE_HDRS sc_getopt.h sc_trace_fprintf.h sc_mkdir.h + sc_nullptr.h path2str.h ) diff --git a/src/base/sc_nullptr.h b/src/base/sc_nullptr.h new file mode 100644 index 00000000..34239700 --- /dev/null +++ b/src/base/sc_nullptr.h @@ -0,0 +1,13 @@ +#ifndef NULLPTR_H +#define NULLPTR_H + +#include + +#ifdef HAVE_NULLPTR +#include +#else +# define nullptr_t void* +# define nullptr NULL +#endif //HAVE_NULLPTR + +#endif //NULLPTR_H diff --git a/src/clstepcore/mgrnode.h b/src/clstepcore/mgrnode.h index 5d163b45..435b6aa7 100644 --- a/src/clstepcore/mgrnode.h +++ b/src/clstepcore/mgrnode.h @@ -19,20 +19,21 @@ class GenericNode; class DisplayNode; #include -//class SDAI_Application_instance; #include #include -//#include #include +#include + class InstMgr; class SC_CORE_EXPORT MgrNodeBase : public GenericNode { public: virtual inline SDAI_Application_instance * GetSTEPentity() { abort(); + return nullptr; }; virtual ~MgrNodeBase() {}; }; diff --git a/src/clstepcore/sdaiApplication_instance.cc b/src/clstepcore/sdaiApplication_instance.cc index 04e1b922..4f77ba35 100644 --- a/src/clstepcore/sdaiApplication_instance.cc +++ b/src/clstepcore/sdaiApplication_instance.cc @@ -20,6 +20,8 @@ #include "sdaiApplication_instance.h" #include "superInvAttrIter.h" +#include + SDAI_Application_instance NilSTEPentity; /**************************************************************//** @@ -944,7 +946,7 @@ const SDAI_Application_instance::iAMap_t::value_type SDAI_Application_instance:: } iAstruct z; memset( &z, 0, sizeof z ); - iAMap_t::value_type nil( NULL, z ); + iAMap_t::value_type nil( nullptr, z ); return nil; } diff --git a/test/cpp/schema_specific/CMakeLists.txt b/test/cpp/schema_specific/CMakeLists.txt index 59823cb8..51d9c317 100644 --- a/test/cpp/schema_specific/CMakeLists.txt +++ b/test/cpp/schema_specific/CMakeLists.txt @@ -96,7 +96,7 @@ add_schema_dependent_test( "attribute" "inverse_attr" "${SC_SOURCE_DIR}/test/p21 if(HAVE_STD_THREAD) if(UNIX) - set(thread_flags "-pthread -std=c++0x" ) + set(thread_flags "-pthread -std=c++11" ) set(thread_libs "pthread") endif(UNIX) # for best results, use a large file. as1-oc-214.stp is currently the largest file in the repo that sc works with.