Skip to content

Commit bc5533b

Browse files
committed
test for, and use, nullptr if we have it
1 parent 4e88ad6 commit bc5533b

8 files changed

Lines changed: 41 additions & 6 deletions

File tree

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ elseif(BORLAND)
114114
add_definitions(-D__BORLAND__ -D__WIN32__)
115115
else()
116116
add_definitions(-pedantic -W -Wall -Wundef -Wfloat-equal -Wshadow -Winline -Wno-long-long)
117+
if(HAVE_NULLPTR)
118+
list(APPEND CMAKE_CXX_FLAGS -std=c++11)
119+
endif(HAVE_NULLPTR)
117120
endif()
118121

119122
include_directories(

cmake/SC_Config_Headers.cmake

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ int main() {
5757
" )
5858
cmake_push_check_state()
5959
if( UNIX )
60-
set( CMAKE_REQUIRED_FLAGS "-pthread -std=c++0x" )
60+
set( CMAKE_REQUIRED_FLAGS "-pthread -std=c++11" )
6161
else( UNIX )
6262
# vars probably need set for embarcadero, etc
6363
endif( UNIX )
@@ -74,13 +74,27 @@ int main() {
7474
" )
7575
cmake_push_check_state()
7676
if( UNIX )
77-
set( CMAKE_REQUIRED_FLAGS "-std=c++0x" )
77+
set( CMAKE_REQUIRED_FLAGS "-std=c++11" )
7878
else( UNIX )
7979
# vars probably need set for embarcadero, etc
8080
endif( UNIX )
8181
CHECK_CXX_SOURCE_RUNS( "${TEST_STD_CHRONO}" HAVE_STD_CHRONO ) #quotes are *required*!
8282
cmake_pop_check_state()
8383

84+
set( TEST_NULLPTR "
85+
#include <cstddef>
86+
std::nullptr_t f() {return nullptr;}
87+
int main() {return !!f();}
88+
" )
89+
cmake_push_check_state()
90+
if( UNIX )
91+
set( CMAKE_REQUIRED_FLAGS "-std=c++11" )
92+
else( UNIX )
93+
# vars probably need set for embarcadero, etc
94+
endif( UNIX )
95+
CHECK_CXX_SOURCE_RUNS( "${TEST_NULLPTR}" HAVE_NULLPTR ) #quotes are *required*!
96+
cmake_pop_check_state()
97+
8498
# Now that all the tests are done, configure the sc_cf.h file:
8599
get_property(CONFIG_H_FILE_CONTENTS GLOBAL PROPERTY SC_CONFIG_H_CONTENTS)
86100
file(WRITE ${CONFIG_H_FILE} "${CONFIG_H_FILE_CONTENTS}")

include/sc_cf_cmake.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@
2525

2626
#cmakedefine HAVE_STD_THREAD 1
2727
#cmakedefine HAVE_STD_CHRONO 1
28+
#cmakedefine HAVE_NULLPTR 1
2829

2930
#endif /* SCL_CF_H */

src/base/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ set(SC_BASE_HDRS
1414
sc_getopt.h
1515
sc_trace_fprintf.h
1616
sc_mkdir.h
17+
sc_nullptr.h
1718
path2str.h
1819
)
1920

src/base/sc_nullptr.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef NULLPTR_H
2+
#define NULLPTR_H
3+
4+
#include <sc_cf.h>
5+
6+
#ifdef HAVE_NULLPTR
7+
#include <cstddef>
8+
#else
9+
# define nullptr_t void*
10+
# define nullptr NULL
11+
#endif //HAVE_NULLPTR
12+
13+
#endif //NULLPTR_H

src/clstepcore/mgrnode.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,21 @@
1919
class GenericNode;
2020
class DisplayNode;
2121
#include <sdai.h>
22-
//class SDAI_Application_instance;
2322

2423
#include <gennode.h>
2524
#include <gennodelist.h>
26-
//#include <gennode.inline.h>
2725

2826
#include <editordefines.h>
2927

28+
#include <sc_nullptr.h>
29+
3030
class InstMgr;
3131

3232
class SC_CORE_EXPORT MgrNodeBase : public GenericNode {
3333
public:
3434
virtual inline SDAI_Application_instance * GetSTEPentity() {
3535
abort();
36+
return nullptr;
3637
};
3738
virtual ~MgrNodeBase() {};
3839
};

src/clstepcore/sdaiApplication_instance.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "sdaiApplication_instance.h"
2121
#include "superInvAttrIter.h"
2222

23+
#include <sc_nullptr.h>
24+
2325
SDAI_Application_instance NilSTEPentity;
2426

2527
/**************************************************************//**
@@ -944,7 +946,7 @@ const SDAI_Application_instance::iAMap_t::value_type SDAI_Application_instance::
944946
}
945947
iAstruct z;
946948
memset( &z, 0, sizeof z );
947-
iAMap_t::value_type nil( NULL, z );
949+
iAMap_t::value_type nil( nullptr, z );
948950
return nil;
949951
}
950952

test/cpp/schema_specific/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ add_schema_dependent_test( "attribute" "inverse_attr" "${SC_SOURCE_DIR}/test/p21
9696

9797
if(HAVE_STD_THREAD)
9898
if(UNIX)
99-
set(thread_flags "-pthread -std=c++0x" )
99+
set(thread_flags "-pthread -std=c++11" )
100100
set(thread_libs "pthread")
101101
endif(UNIX)
102102
# for best results, use a large file. as1-oc-214.stp is currently the largest file in the repo that sc works with.

0 commit comments

Comments
 (0)