diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000000..e02b1c4556 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1 @@ +Checks: '-*,modernize-use-nullptr,modernize-use-override,bugprone,modernize-redundant-void-arg' diff --git a/libnestutil/config.h.in b/libnestutil/config.h.in index 8b4d78e471..6ffe368c0d 100644 --- a/libnestutil/config.h.in +++ b/libnestutil/config.h.in @@ -129,7 +129,7 @@ /* "Define if NAN is available" */ #cmakedefine HAVE_NAN 1 -/* "Define if std::nan(NULL) is available" */ +/* "Define if std::nan(nullptr) is available" */ #cmakedefine HAVE_STD_NAN 1 /* define for ostream */ diff --git a/libnestutil/lockptr.h b/libnestutil/lockptr.h index 21096cf20a..88c7618864 100644 --- a/libnestutil/lockptr.h +++ b/libnestutil/lockptr.h @@ -97,7 +97,7 @@ class lockPTR PointerObject( PointerObject const& ); public: - explicit PointerObject( D* p = NULL ) + explicit PointerObject( D* p = nullptr ) : pointee( p ) , deletable( true ) , locked( false ) @@ -114,7 +114,7 @@ class lockPTR ~PointerObject() { assert( not locked ); - if ( ( pointee != NULL ) and deletable and not locked ) + if ( pointee and deletable and not locked ) { delete pointee; } @@ -164,34 +164,34 @@ class lockPTR // object which must then be initialised, for example // by assignement. - explicit lockPTR( D* p = NULL ) + explicit lockPTR( D* p = nullptr ) { obj = std::make_shared< PointerObject >( p ); - assert( obj != NULL ); + assert( obj ); } explicit lockPTR( D& p_o ) { obj = std::make_shared< PointerObject >( p_o ); - assert( obj != NULL ); + assert( obj ); } lockPTR( const lockPTR< D >& spd ) : obj( spd.obj ) { - assert( obj != NULL ); + assert( obj ); } virtual ~lockPTR() { - assert( obj != NULL ); + assert( obj ); } lockPTR< D > operator=( const lockPTR< D >& spd ) { - assert( obj != NULL ); - assert( spd.obj != NULL ); + assert( obj ); + assert( spd.obj ); obj = spd.obj; @@ -234,7 +234,7 @@ class lockPTR D* operator->() const { - assert( obj->get() != NULL ); + assert( obj->get() ); return obj->get(); } @@ -242,7 +242,7 @@ class lockPTR D* operator->() { - assert( obj->get() != NULL ); + assert( obj->get() ); return obj->get(); } @@ -250,7 +250,7 @@ class lockPTR D& operator*() { - assert( obj->get() != NULL ); + assert( obj->get() ); return *( obj->get() ); } @@ -258,17 +258,15 @@ class lockPTR const D& operator*() const { - assert( obj->get() != NULL ); + assert( obj->get() ); return *( obj->get() ); } bool - operator not() const //!< returns true if and only if obj->pointee == NULL + operator not() const //!< returns true if and only if not obj->pointee { - // assert(obj != NULL); - - return ( obj->get() == NULL ); + return not obj->get(); } @@ -296,51 +294,51 @@ class lockPTR bool - valid() const //!< returns true if and only if obj->pointee != NULL + valid() const //!< returns true if and only if obj->pointee { - assert( obj != NULL ); - return ( obj->get() != NULL ); + assert( obj ); + return ( obj->get() ); } bool islocked() const { - assert( obj != NULL ); + assert( obj ); return ( obj->islocked() ); } bool deletable() const { - assert( obj != NULL ); + assert( obj ); return ( obj->isdeletable() ); } void lock() const { - assert( obj != NULL ); + assert( obj ); obj->lock(); } void unlock() const { - assert( obj != NULL ); + assert( obj ); obj->unlock(); } void unlock() { - assert( obj != NULL ); + assert( obj ); obj->unlock(); } size_t references() const { - return ( obj == NULL ) ? 0 : obj.use_count(); + return not obj ? 0 : obj.use_count(); } }; diff --git a/nest/neststartup.cpp b/nest/neststartup.cpp index 973da183ff..15d4d992e2 100644 --- a/nest/neststartup.cpp +++ b/nest/neststartup.cpp @@ -141,7 +141,7 @@ neststartup( int* argc, char*** argv, SLIInterpreter& engine, std::string module #ifdef _IS_PYNEST // add the init-script to the list of module initializers ArrayDatum* ad = dynamic_cast< ArrayDatum* >( engine.baselookup( engine.commandstring_name ).datum() ); - assert( ad != NULL ); + assert( ad ); ad->push_back( new StringDatum( "(" + modulepath + "/pynest-init.sli) run" ) ); #endif @@ -160,11 +160,11 @@ nestshutdown( int exitcode ) Datum* CYTHON_unpackConnectionGeneratorDatum( PyObject* obj ) { - Datum* ret = NULL; - ConnectionGenerator* cg = NULL; + Datum* ret = nullptr; + ConnectionGenerator* cg = nullptr; cg = PNS::unpackConnectionGenerator( obj ); - if ( cg != NULL ) + if ( cg ) { ret = static_cast< Datum* >( new ConnectionGeneratorDatum( cg ) ); } diff --git a/nest/neststartup.h b/nest/neststartup.h index 5974e68414..72b790ecd1 100644 --- a/nest/neststartup.h +++ b/nest/neststartup.h @@ -33,7 +33,7 @@ Datum* CYTHON_unpackConnectionGeneratorDatum( PyObject* ); #else #define CYTHON_isConnectionGenerator( x ) 0 -#define CYTHON_unpackConnectionGeneratorDatum( x ) NULL +#define CYTHON_unpackConnectionGeneratorDatum( x ) nullptr #endif class SLIInterpreter; diff --git a/nestkernel/conn_builder_conngen.cpp b/nestkernel/conn_builder_conngen.cpp index b835ebeab9..0f4ccea662 100644 --- a/nestkernel/conn_builder_conngen.cpp +++ b/nestkernel/conn_builder_conngen.cpp @@ -82,7 +82,7 @@ ConnectionGeneratorBuilder::connect_() if ( num_parameters == 0 ) { // connect source to target - while ( cg_->next( source, target, NULL ) ) + while ( cg_->next( source, target, nullptr ) ) { // No need to check for locality of the target, as the mask // created by cg_set_masks() only contains local nodes. diff --git a/nestkernel/connection_manager.cpp b/nestkernel/connection_manager.cpp index 0381c80cf4..dd8922dc2e 100644 --- a/nestkernel/connection_manager.cpp +++ b/nestkernel/connection_manager.cpp @@ -890,7 +890,7 @@ nest::ConnectionManager::trigger_update_weight( const long vt_id, for ( std::vector< ConnectorBase* >::iterator it = connections_[ tid ].begin(); it != connections_[ tid ].end(); ++it ) { - if ( *it != NULL ) + if ( *it ) { ( *it )->trigger_update_weight( vt_id, tid, dopa_spikes, t_trig, kernel().model_manager.get_connection_models( tid ) ); diff --git a/nestkernel/event.h b/nestkernel/event.h index f26a6acf17..9d0ae616c6 100644 --- a/nestkernel/event.h +++ b/nestkernel/event.h @@ -299,10 +299,10 @@ class Event * members, however, in order to avoid the reference of reference * problem, we store sender and receiver as pointers and use * references in the interface. - * Thus, we can still ensure that the pointers are never NULL. + * Thus, we can still ensure that the pointers are never nullptr. */ - Node* sender_; //!< Pointer to sender or NULL. - Node* receiver_; //!< Pointer to receiver or NULL. + Node* sender_; //!< Pointer to sender or nullptr. + Node* receiver_; //!< Pointer to receiver or nullptr. /** @@ -620,7 +620,7 @@ class DataLoggingRequest : public Event Time recording_offset_; /** * Names of properties to record from. - * @note This pointer shall be NULL unless the event is sent by a connection + * @note This pointer shall be nullptr unless the event is sent by a connection * routine. */ std::vector< Name > const* const record_from_; diff --git a/nestkernel/recording_backend_sionlib.cpp b/nestkernel/recording_backend_sionlib.cpp index 2af52133b7..eb5c7f6d18 100644 --- a/nestkernel/recording_backend_sionlib.cpp +++ b/nestkernel/recording_backend_sionlib.cpp @@ -167,7 +167,7 @@ nest::RecordingBackendSIONlib::open_files_() // we need to delay the throwing of exceptions to the end of the parallel // section - WrappedThreadException* we = NULL; + WrappedThreadException* we = nullptr; // This code is executed in a parallel region (opened above)! const thread t = kernel().vp_manager.get_thread_id(); @@ -228,8 +228,8 @@ nest::RecordingBackendSIONlib::open_files_() &sion_chunksize, &fs_block_size, &rank, - NULL, - NULL ); + nullptr, + nullptr ); file.buffer.reserve( P_.buffer_size_ ); file.buffer.clear(); @@ -316,7 +316,7 @@ nest::RecordingBackendSIONlib::close_files_() if ( task == 0 ) { int mc; - sion_int64* cs = NULL; + sion_int64* cs = nullptr; int info_blk; // here int, other place sion_int64 due to sion api sion_int64 info_pos; @@ -536,14 +536,14 @@ nest::RecordingBackendSIONlib::build_filename_() const * ---------------------------------------------------------------- */ nest::RecordingBackendSIONlib::SIONBuffer::SIONBuffer() - : buffer_( NULL ) + : buffer_( nullptr ) , ptr_( 0 ) , max_size_( 0 ) { } nest::RecordingBackendSIONlib::SIONBuffer::SIONBuffer( size_t size ) - : buffer_( NULL ) + : buffer_( nullptr ) , ptr_( 0 ) , max_size_( 0 ) { @@ -552,7 +552,7 @@ nest::RecordingBackendSIONlib::SIONBuffer::SIONBuffer( size_t size ) nest::RecordingBackendSIONlib::SIONBuffer::~SIONBuffer() { - if ( buffer_ != NULL ) + if ( buffer_ ) { delete[] buffer_; } @@ -563,7 +563,7 @@ nest::RecordingBackendSIONlib::SIONBuffer::reserve( size_t size ) { char* new_buffer = new char[ size ]; - if ( buffer_ != NULL ) + if ( buffer_ ) { ptr_ = std::min( ptr_, size ); memcpy( new_buffer, buffer_, ptr_ ); diff --git a/nestkernel/target_table_devices.h b/nestkernel/target_table_devices.h index f80d360a35..32855ed47b 100644 --- a/nestkernel/target_table_devices.h +++ b/nestkernel/target_table_devices.h @@ -239,7 +239,7 @@ TargetTableDevices::send_from_device( const thread tid, it != target_from_devices_[ tid ][ ldid ].end(); ++it ) { - if ( *it != NULL ) + if ( *it ) { ( *it )->send_to_all( tid, cm, e ); } diff --git a/nestkernel/target_table_devices_impl.h b/nestkernel/target_table_devices_impl.h index cf29786c9e..095d82c11b 100644 --- a/nestkernel/target_table_devices_impl.h +++ b/nestkernel/target_table_devices_impl.h @@ -83,7 +83,7 @@ nest::TargetTableDevices::send_to_device( const thread tid, it != target_to_devices_[ tid ][ lid ].end(); ++it ) { - if ( *it != NULL ) + if ( *it ) { ( *it )->send_to_all( tid, cm, e ); } diff --git a/sli/aggregatedatum.h b/sli/aggregatedatum.h index c284633f60..517c803061 100644 --- a/sli/aggregatedatum.h +++ b/sli/aggregatedatum.h @@ -96,7 +96,7 @@ class AggregateDatum : public TypedDatum< slt >, public C // to work. const AggregateDatum< C, slt >* ddc = dynamic_cast< AggregateDatum< C, slt >* >( const_cast< Datum* >( dat ) ); - if ( ddc == NULL ) + if ( not ddc ) { return false; } diff --git a/sli/genericdatum.h b/sli/genericdatum.h index ea8be03c7e..dc6847d5f3 100644 --- a/sli/genericdatum.h +++ b/sli/genericdatum.h @@ -114,7 +114,7 @@ class GenericDatum : public TypedDatum< slt > // std::cerr << "d = " << d << " ddc = " << ddc << " dat = " << dat << // std::endl; - if ( ddc == NULL ) + if ( not ddc ) { return false; } diff --git a/sli/sli_io.cc b/sli/sli_io.cc index c7bd2c9d70..bc823523b8 100644 --- a/sli/sli_io.cc +++ b/sli/sli_io.cc @@ -463,7 +463,7 @@ OstrstreamFunction::execute( SLIInterpreter* i ) const #else std::ostrstream* out = new std::ostrstream(); #endif - assert( out != NULL ); + assert( out ); if ( out->good() ) { @@ -492,7 +492,7 @@ StrFunction::execute( SLIInterpreter* i ) const OstreamDatum* ostreamdatum = dynamic_cast< OstreamDatum* >( i->OStack.top().datum() ); - if ( ostreamdatum == NULL ) + if ( not ostreamdatum ) { OstreamDatum const d; Token t = i->OStack.top(); @@ -504,10 +504,10 @@ StrFunction::execute( SLIInterpreter* i ) const #else std::ostrstream* out = dynamic_cast< std::ostrstream* >( ostreamdatum->get() ); #endif - assert( out != NULL ); + assert( out ); ostreamdatum->unlock(); - if ( out != NULL ) + if ( out ) { if ( out->good() ) { diff --git a/sli/sliactions.cc b/sli/sliactions.cc index 756ea1506e..3e32e572e4 100644 --- a/sli/sliactions.cc +++ b/sli/sliactions.cc @@ -106,7 +106,6 @@ FunctiontypeFunction::execute( SLIInterpreter* i ) const void TrietypeFunction::execute( SLIInterpreter* i ) const { - TrieDatum* tried = static_cast< TrieDatum* >( i->EStack.top().datum() ); i->EStack.top().assign_by_ref( tried->lookup( i->OStack ) ); } @@ -114,17 +113,14 @@ TrietypeFunction::execute( SLIInterpreter* i ) const void CallbacktypeFunction::execute( SLIInterpreter* i ) const { - // assert(i->ct.datum() != NULL); // we wouldn't be here otherwise - CallbackDatum* cb = static_cast< CallbackDatum* >( i->ct.datum() ); // Note, although cb is a pointer to a class derived from Datum, // it also has the properties of a token, since it is derived from both. - i->EStack.push_move( i->ct ); // This moves the complete callback datum to the EStack. - // Now, the pointer in ct is set to NULL !! + // Now, the pointer in ct is set to nullptr !! // Now push command to restore the callback, once the action has // been finished diff --git a/sli/sliarray.cc b/sli/sliarray.cc index 64cf2dd332..6561321c52 100644 --- a/sli/sliarray.cc +++ b/sli/sliarray.cc @@ -1610,26 +1610,21 @@ void SLIArrayModule::IMapThreadFunction::execute( SLIInterpreter* i ) const { ProcedureDatum* procd = static_cast< ProcedureDatum* >( i->EStack.pick( 1 ).datum() ); - // assert(procd != NULL); size_t proclimit = procd->size(); IntegerDatum* argcountd = static_cast< IntegerDatum* >( i->EStack.pick( 2 ).datum() ); - // assert(argcountd != NULL); size_t argcount = argcountd->get(); IntegerDatum* proccountd = static_cast< IntegerDatum* >( i->EStack.pick( 3 ).datum() ); - // assert(proccountd != NULL); + size_t proccount = proccountd->get(); ArrayDatum* sarray = static_cast< ArrayDatum* >( i->EStack.pick( 4 ).datum() ); - // assert(sarray != NULL); ArrayDatum* tarray = static_cast< ArrayDatum* >( i->EStack.pick( 5 ).datum() ); - // assert(tarray != NULL); IntegerDatum* limitd = static_cast< IntegerDatum* >( i->EStack.pick( 6 ).datum() ); - // assert(limitd != NULL); size_t args = sarray->size(); // number of argument arrays size_t limit = limitd->get(); // number of arguments per array @@ -2070,7 +2065,7 @@ SLIArrayModule::AreaFunction::execute( SLIInterpreter* i ) const IntegerDatum* a_y_d = dynamic_cast< IntegerDatum* >( i->OStack.pick( 1 ).datum() ); IntegerDatum* a_x_d = dynamic_cast< IntegerDatum* >( i->OStack.pick( 0 ).datum() ); - // if(s_h_d == NULL) + // if(not s_h_d) // { // i->raiseerror(i->ArgumentTypeError); // return; @@ -2334,12 +2329,12 @@ SLIArrayModule::Area2Function::execute( SLIInterpreter* i ) const IntegerDatum* a_y_d = dynamic_cast< IntegerDatum* >( i->OStack.pick( 1 ).datum() ); IntegerDatum* a_x_d = dynamic_cast< IntegerDatum* >( i->OStack.pick( 0 ).datum() ); - // if(s_h_d == NULL) + // if(not s_h_d) // { // i->raiseerror(i->ArgumentTypeError); // return; // } - // if(s_w_d == NULL) + // if(not s_w_d) // { // i->raiseerror(i->ArgumentTypeError); // return; diff --git a/sli/slitype.h b/sli/slitype.h index b9a3523543..4b38e74199 100644 --- a/sli/slitype.h +++ b/sli/slitype.h @@ -86,8 +86,6 @@ class SLIType SLIFunction* getaction() const { - // assert(defaultaction != NULL); - // If this fails, we have created a datum before the types were initialised. return defaultaction; } }; diff --git a/sli/specialfunctionsmodule.cc b/sli/specialfunctionsmodule.cc index b3a850629b..e3c495bc5f 100644 --- a/sli/specialfunctionsmodule.cc +++ b/sli/specialfunctionsmodule.cc @@ -444,11 +444,11 @@ SpecialFunctionsModule::ErfcFunction::execute( SLIInterpreter* i ) const // --------------------------------------------------------------- -SpecialFunctionsModule::GaussDiskConvFunction::GaussDiskConvFunction( void ) +SpecialFunctionsModule::GaussDiskConvFunction::GaussDiskConvFunction() { } -SpecialFunctionsModule::GaussDiskConvFunction::~GaussDiskConvFunction( void ) +SpecialFunctionsModule::GaussDiskConvFunction::~GaussDiskConvFunction() { } diff --git a/sli/tarrayobj.cc b/sli/tarrayobj.cc index ded44e05cf..2a8e978386 100644 --- a/sli/tarrayobj.cc +++ b/sli/tarrayobj.cc @@ -89,7 +89,7 @@ TokenArrayObj::allocate( size_t new_s, size_t new_c, size_t new_a, const Token& assert( new_a != 0 ); Token* h = new Token[ new_c ]; - assert( h != NULL ); + assert( h ); if ( t != Token() ) { @@ -123,7 +123,7 @@ TokenArrayObj::allocate( size_t new_s, size_t new_c, size_t new_a, const Token& delete[] p; } p = h; - assert( p != NULL ); + assert( p ); ++allocations; } @@ -278,7 +278,7 @@ TokenArrayObj::erase( Token* first, Token* last ) { if ( to->p ) { - // deleting NULL pointer is safe in ISO C++ + // deleting nullptr pointer is safe in ISO C++ to->p->removeReference(); } to->p = from->p; // move @@ -399,7 +399,7 @@ TokenArrayObj::insert( size_t i, size_t n, const Token& t ) to->p = from->p; // move from->p = nullptr; // knowing that to->p is --from; - --to; // NULL before + --to; // nullptr before } for ( size_t i = 0; i < n; ++i ) // insert n copies of Token t; @@ -426,7 +426,7 @@ TokenArrayObj::insert_move( size_t i, TokenArrayObj& a ) to->p = from->p; // move from->p = nullptr; // knowing that to->p is --from; - --to; // NULL before + --to; // nullptr before } from = a.p; @@ -498,7 +498,7 @@ TokenArrayObj::insert_move( size_t i, Token& t ) to->p = from->p; // move from->p = nullptr; // knowing that to->p is --from; - --to; // NULL before + --to; // nullptr before } ( p + i )->p = t.p; // move contens of t @@ -549,7 +549,7 @@ TokenArrayObj::replace_move( size_t i, size_t n, TokenArrayObj& a ) { if ( to->p ) { - // deleting NULL pointer is safe in ISO C++ + // deleting nullptr pointer is safe in ISO C++ to->p->removeReference(); } to->p = from->p; // move @@ -586,7 +586,7 @@ TokenArrayObj::replace_move( size_t i, size_t n, TokenArrayObj& a ) to->p->removeReference(); } to->p = from->p; // movement, it is typically - from->p = nullptr; // not the NULL pointer + from->p = nullptr; // not the nullptr pointer ++from; ++to; } @@ -603,7 +603,7 @@ TokenArrayObj::append_move( TokenArrayObj& a ) while ( from < a.end() ) // move { // knowing that to->p is - to->p = from->p; // NULL before + to->p = from->p; // nullptr before from->p = nullptr; ++from; ++to; diff --git a/sli/token.h b/sli/token.h index acb07077d8..e5a7be51e2 100644 --- a/sli/token.h +++ b/sli/token.h @@ -373,7 +373,6 @@ class Token Datum* operator->() const { - // assert(p!= NULL); return p; } @@ -381,7 +380,6 @@ class Token Datum& operator*() const { - // assert(p != NULL); return *p; } diff --git a/sli/tokenutils.h b/sli/tokenutils.h index 2523feaae3..64c92195d5 100644 --- a/sli/tokenutils.h +++ b/sli/tokenutils.h @@ -152,7 +152,7 @@ FT getValue( const Token& t ) { FT* value = dynamic_cast< FT* >( t.datum() ); - if ( value == NULL ) + if ( not value ) { throw TypeMismatch(); } @@ -177,7 +177,7 @@ void setValue( const Token& t, FT const& value ) { FT* old = dynamic_cast< FT* >( t.datum() ); - if ( old == NULL ) + if ( not old ) { throw TypeMismatch(); } diff --git a/sli/typechk.cc b/sli/typechk.cc index 50e9e8c400..92e055dfab 100644 --- a/sli/typechk.cc +++ b/sli/typechk.cc @@ -167,7 +167,6 @@ TypeTrie::getalternative( TypeTrie::TypeNode* pos, const Name& type ) if ( pos->type == empty ) { pos->type = type; - // assert(pos->next == NULL); return pos; } @@ -180,10 +179,8 @@ TypeTrie::getalternative( TypeTrie::TypeNode* pos, const Name& type ) if ( pos->type == sli::any ) { - // any must have been the tail and the previous - // if must have added an extra Node, thus the following - // assertion must hold: - // assert(pos->alt->alt == NULL); + // When entering this if, the previous if added an extra Node, + // thus pos->alt->alt will not be defined yet (nullptr) TypeNode* new_tail = pos->alt; @@ -253,9 +250,9 @@ TypeTrie::insert_move( const TypeArray& a, Token& f ) } /* Error conditions: - 1. If pos->next!=NULL, the parameter list overlaps with + 1. If pos->next != nullptr, the parameter list overlaps with an existing function definition. - 2. If pos->alt != NULL, something undefined must have happened. + 2. If pos->alt != nullptr, something undefined must have happened. This should be impossible. */ if ( not pos->next )