diff --git a/src/analyses/goto_check.cpp b/src/analyses/goto_check.cpp index 8fe596d9262..be4edbf288f 100644 --- a/src/analyses/goto_check.cpp +++ b/src/analyses/goto_check.cpp @@ -37,7 +37,7 @@ class goto_checkt const namespacet &_ns, const optionst &_options): ns(_ns), - local_bitvector_analysis(0) + local_bitvector_analysis(nullptr) { enable_bounds_check=_options.get_bool_option("bounds-check"); enable_pointer_check=_options.get_bool_option("pointer-check"); diff --git a/src/analyses/goto_rw.cpp b/src/analyses/goto_rw.cpp index be3ef3e0a8d..49827bd2bd3 100644 --- a/src/analyses/goto_rw.cpp +++ b/src/analyses/goto_rw.cpp @@ -463,9 +463,10 @@ void rw_range_sett::add( { objectst::iterator entry=(mode==get_modet::LHS_W ? w_range_set : r_range_set). insert( - std::pair(identifier, 0)).first; + std::pair( + identifier, nullptr)).first; - if(entry->second==0) + if(entry->second==nullptr) entry->second=new range_domaint(); static_cast(entry->second)->push_back( @@ -663,9 +664,10 @@ void rw_guarded_range_set_value_sett::add( { objectst::iterator entry=(mode==get_modet::LHS_W ? w_range_set : r_range_set). insert( - std::pair(identifier, 0)).first; + std::pair( + identifier, nullptr)).first; - if(entry->second==0) + if(entry->second==nullptr) entry->second=new guarded_range_domaint(); static_cast(entry->second)->insert( diff --git a/src/analyses/goto_rw.h b/src/analyses/goto_rw.h index 06b7a7ab411..1f92c3e0e14 100644 --- a/src/analyses/goto_rw.h +++ b/src/analyses/goto_rw.h @@ -108,7 +108,7 @@ class rw_range_sett const range_domaint &get_ranges(objectst::const_iterator it) const { - assert(dynamic_cast(it->second)!=0); + PRECONDITION(dynamic_cast(it->second)!=nullptr); return *static_cast(it->second); } @@ -277,7 +277,7 @@ class rw_guarded_range_set_value_sett:public rw_range_set_value_sett const guarded_range_domaint &get_ranges(objectst::const_iterator it) const { - assert(dynamic_cast(it->second)!=0); + PRECONDITION(dynamic_cast(it->second)!=nullptr); return *static_cast(it->second); } diff --git a/src/analyses/invariant_set.cpp b/src/analyses/invariant_set.cpp index 6127abdd57f..a91c0349bbb 100644 --- a/src/analyses/invariant_set.cpp +++ b/src/analyses/invariant_set.cpp @@ -13,6 +13,7 @@ Author: Daniel Kroening, kroening@kroening.com #include +#include #include #include #include @@ -144,7 +145,7 @@ bool invariant_sett::get_object( const exprt &expr, unsigned &n) const { - assert(object_store!=NULL); + PRECONDITION(object_store!=nullptr); return object_store->get(expr, n); } @@ -315,7 +316,8 @@ void invariant_sett::output( return; } - assert(object_store!=NULL); + INVARIANT_STRUCTURED( + object_store!=nullptr, nullptr_exceptiont, "Object store is null"); for(unsigned i=0; ito_string(a, identifier); } diff --git a/src/analyses/invariant_set.h b/src/analyses/invariant_set.h index 6bb40bd3e94..b65ce7897f3 100644 --- a/src/analyses/invariant_set.h +++ b/src/analyses/invariant_set.h @@ -98,9 +98,9 @@ class invariant_sett invariant_sett(): threaded(false), is_false(false), - value_sets(NULL), - object_store(NULL), - ns(NULL) + value_sets(nullptr), + object_store(nullptr), + ns(nullptr) { } diff --git a/src/analyses/local_may_alias.h b/src/analyses/local_may_alias.h index b54cf4e9e88..5e04ff01a75 100644 --- a/src/analyses/local_may_alias.h +++ b/src/analyses/local_may_alias.h @@ -94,7 +94,7 @@ class local_may_aliast class local_may_alias_factoryt { public: - local_may_alias_factoryt():goto_functions(NULL) + local_may_alias_factoryt():goto_functions(nullptr) { } @@ -109,7 +109,7 @@ class local_may_alias_factoryt local_may_aliast &operator()(const irep_idt &fkt) { - assert(goto_functions!=NULL); + PRECONDITION(goto_functions!=nullptr); fkt_mapt::iterator f_it=fkt_map.find(fkt); if(f_it!=fkt_map.end()) return *f_it->second; diff --git a/src/analyses/reaching_definitions.cpp b/src/analyses/reaching_definitions.cpp index 0e0462c3c8a..89b31da543b 100644 --- a/src/analyses/reaching_definitions.cpp +++ b/src/analyses/reaching_definitions.cpp @@ -51,7 +51,10 @@ void rd_range_domaint::transform( { reaching_definitions_analysist *rd= dynamic_cast(&ai); - assert(rd!=0); + INVARIANT_STRUCTURED( + rd!=nullptr, + bad_cast_exceptiont, + "ai has type reaching_definitions_analysist"); assert(bv_container); @@ -298,7 +301,10 @@ void rd_range_domaint::transform_assign( const symbolt *symbol_ptr; if(ns.lookup(identifier, symbol_ptr)) continue; - assert(symbol_ptr!=0); + INVARIANT_STRUCTURED( + symbol_ptr!=nullptr, + nullptr_exceptiont, + "Symbol is in symbol table"); const range_domaint &ranges=rw_set.get_ranges(it); diff --git a/src/analyses/reaching_definitions.h b/src/analyses/reaching_definitions.h index e5f0d5f12b5..21cbd1ed377 100644 --- a/src/analyses/reaching_definitions.h +++ b/src/analyses/reaching_definitions.h @@ -16,6 +16,7 @@ Date: February 2013 #ifndef CPROVER_ANALYSES_REACHING_DEFINITIONS_H #define CPROVER_ANALYSES_REACHING_DEFINITIONS_H +#include #include #include "ai.h" @@ -102,7 +103,7 @@ class rd_range_domaint:public ai_domain_baset rd_range_domaint(): ai_domain_baset(), has_values(false), - bv_container(0) + bv_container(nullptr) { } @@ -243,9 +244,9 @@ class reaching_definitions_analysist: explicit reaching_definitions_analysist(const namespacet &_ns): concurrency_aware_ait(), ns(_ns), - value_sets(0), - is_threaded(0), - is_dirty(0) + value_sets(nullptr), + is_threaded(nullptr), + is_dirty(nullptr) { } @@ -259,7 +260,10 @@ class reaching_definitions_analysist: statet &s=concurrency_aware_ait::get_state(l); rd_range_domaint *rd_state=dynamic_cast(&s); - assert(rd_state!=0); + INVARIANT_STRUCTURED( + rd_state!=nullptr, + bad_cast_exceptiont, + "rd_state has type rd_range_domaint"); rd_state->set_bitvector_container(*this); diff --git a/src/ansi-c/c_preprocess.cpp b/src/ansi-c/c_preprocess.cpp index 6ba8e6f359b..927a928b187 100644 --- a/src/ansi-c/c_preprocess.cpp +++ b/src/ansi-c/c_preprocess.cpp @@ -344,7 +344,7 @@ bool c_preprocess( static bool is_dot_i_file(const std::string &path) { const char *ext=strrchr(path.c_str(), '.'); - if(ext==NULL) + if(ext==nullptr) return false; if(std::string(ext)==".i" || std::string(ext)==".ii") @@ -889,7 +889,7 @@ bool c_preprocess_gcc_clang( FILE *stream=popen(command.c_str(), "r"); - if(stream!=NULL) + if(stream!=nullptr) { int ch; while((ch=fgetc(stream))!=EOF) @@ -1011,7 +1011,7 @@ bool c_preprocess_arm( FILE *stream=popen(command.c_str(), "r"); - if(stream!=NULL) + if(stream!=nullptr) { int ch; while((ch=fgetc(stream))!=EOF) diff --git a/src/ansi-c/cprover_library.cpp b/src/ansi-c/cprover_library.cpp index 8f99f987bf3..f13e321d752 100644 --- a/src/ansi-c/cprover_library.cpp +++ b/src/ansi-c/cprover_library.cpp @@ -38,7 +38,7 @@ std::string get_cprover_library_text( std::size_t count=0; for(cprover_library_entryt *e=cprover_library; - e->function!=NULL; + e->function!=nullptr; e++) { irep_idt id=e->function; diff --git a/src/ansi-c/expr2c.cpp b/src/ansi-c/expr2c.cpp index 9c980cc842a..d1dbf3bb6b5 100644 --- a/src/ansi-c/expr2c.cpp +++ b/src/ansi-c/expr2c.cpp @@ -2664,7 +2664,7 @@ std::string expr2ct::convert_code_decl( std::string dest=indent_str(indent); - const symbolt *symbol=0; + const symbolt *symbol=nullptr; if(!ns.lookup(to_symbol_expr(src.op0()).get_identifier(), symbol)) { if(symbol->is_file_local && diff --git a/src/cbmc/cbmc_parse_options.cpp b/src/cbmc/cbmc_parse_options.cpp index 2943d9a18d7..2e21dae825b 100644 --- a/src/cbmc/cbmc_parse_options.cpp +++ b/src/cbmc/cbmc_parse_options.cpp @@ -569,7 +569,7 @@ int cbmc_parse_optionst::get_goto_program( languaget *language=get_language_from_filename(filename); - if(language==NULL) + if(language==nullptr) { error() << "failed to figure out type of file `" << filename << "'" << eom; @@ -718,7 +718,7 @@ void cbmc_parse_optionst::preprocessing() languaget *ptr=get_language_from_filename(filename); - if(ptr==NULL) + if(ptr==nullptr) { error() << "failed to figure out type of file" << eom; return; diff --git a/src/clobber/clobber_parse_options.cpp b/src/clobber/clobber_parse_options.cpp index 36cc3e49abc..8c2b2dc1f50 100644 --- a/src/clobber/clobber_parse_options.cpp +++ b/src/clobber/clobber_parse_options.cpp @@ -250,7 +250,7 @@ bool clobber_parse_optionst::get_goto_program( languaget *language=get_language_from_filename(filename); - if(language==NULL) + if(language==nullptr) { error() << "failed to figure out type of file `" << filename << "'" << eom; diff --git a/src/cpp/cpp_id.cpp b/src/cpp/cpp_id.cpp index e6c13ca4cfb..edcc139ce4f 100644 --- a/src/cpp/cpp_id.cpp +++ b/src/cpp/cpp_id.cpp @@ -24,7 +24,7 @@ cpp_idt::cpp_idt(): id_class(id_classt::UNKNOWN), this_expr(static_cast(get_nil_irep())), compound_counter(0), - parent(NULL) + parent(nullptr) { } diff --git a/src/cpp/cpp_id.h b/src/cpp/cpp_id.h index f7fe339cc1a..b2efbc27188 100644 --- a/src/cpp/cpp_id.h +++ b/src/cpp/cpp_id.h @@ -20,6 +20,7 @@ Author: Daniel Kroening, kroening@cs.cmu.edu #include #include +#include #include class cpp_scopet; @@ -81,7 +82,7 @@ class cpp_idt cpp_idt &get_parent() const { - assert(parent!=NULL); + PRECONDITION(parent!=nullptr); return *parent; } diff --git a/src/cpp/cpp_instantiate_template.cpp b/src/cpp/cpp_instantiate_template.cpp index c28fe5ca546..fe0b3e28ac2 100644 --- a/src/cpp/cpp_instantiate_template.cpp +++ b/src/cpp/cpp_instantiate_template.cpp @@ -12,6 +12,7 @@ Author: Daniel Kroening, kroening@cs.cmu.edu #include "cpp_typecheck.h" #include +#include #include #include @@ -130,7 +131,8 @@ const symbolt &cpp_typecheckt::class_template_symbol( cpp_scopet *template_scope= static_cast(cpp_scopes.id_map[template_symbol.name]); - assert(template_scope!=NULL); + INVARIANT_STRUCTURED( + template_scope!=nullptr, nullptr_exceptiont, "template_scope is null"); irep_idt identifier= id2string(template_scope->prefix)+ @@ -276,7 +278,7 @@ const symbolt &cpp_typecheckt::instantiate_template( cpp_scopet *template_scope= static_cast(cpp_scopes.id_map[template_symbol.name]); - if(template_scope==NULL) + if(template_scope==nullptr) { error().source_location=source_location; error() << "identifier: " << template_symbol.name << '\n' @@ -284,7 +286,8 @@ const symbolt &cpp_typecheckt::instantiate_template( throw 0; } - assert(template_scope!=NULL); + INVARIANT_STRUCTURED( + template_scope!=nullptr, nullptr_exceptiont, "template_scope is null"); // produce new declaration cpp_declarationt new_decl=to_cpp_declaration(template_symbol.type); diff --git a/src/cpp/cpp_language.cpp b/src/cpp/cpp_language.cpp index 59e538265cb..c8b7f999653 100644 --- a/src/cpp/cpp_language.cpp +++ b/src/cpp/cpp_language.cpp @@ -65,7 +65,7 @@ bool cpp_languaget::preprocess( // check extension const char *ext=strrchr(path.c_str(), '.'); - if(ext!=NULL && std::string(ext)==".ipp") + if(ext!=nullptr && std::string(ext)==".ipp") { std::ifstream infile(path); diff --git a/src/cpp/cpp_typecheck_compound_type.cpp b/src/cpp/cpp_typecheck_compound_type.cpp index 36d2a2e70b6..39f229bfbea 100644 --- a/src/cpp/cpp_typecheck_compound_type.cpp +++ b/src/cpp/cpp_typecheck_compound_type.cpp @@ -110,7 +110,7 @@ void cpp_typecheckt::typecheck_compound_type( // get the tag name bool has_tag=type.find(ID_tag).is_not_nil(); irep_idt base_name; - cpp_scopet *dest_scope=NULL; + cpp_scopet *dest_scope=nullptr; bool has_body=type.find(ID_body).is_not_nil(); bool tag_only_declaration=type.get_bool(ID_C_tag_only_declaration); diff --git a/src/cpp/cpp_typecheck_expr.cpp b/src/cpp/cpp_typecheck_expr.cpp index 87f15a16a3b..88b26461482 100644 --- a/src/cpp/cpp_typecheck_expr.cpp +++ b/src/cpp/cpp_typecheck_expr.cpp @@ -471,7 +471,7 @@ struct operator_entryt { ID_notequal, "!=" }, { ID_dereference, "*" }, { ID_ptrmember, "->" }, - { irep_idt(), NULL } + { irep_idt(), nullptr } }; bool cpp_typecheckt::operator_is_overloaded(exprt &expr) diff --git a/src/cpp/cpp_typecheck_resolve.cpp b/src/cpp/cpp_typecheck_resolve.cpp index 28d42e6af62..d8e0e8c3d90 100644 --- a/src/cpp/cpp_typecheck_resolve.cpp +++ b/src/cpp/cpp_typecheck_resolve.cpp @@ -1117,7 +1117,7 @@ symbol_typet cpp_typecheck_resolvet::disambiguate_template_classes( static_cast( cpp_typecheck.cpp_scopes.id_map[id]); - if(template_scope==NULL) + if(template_scope==nullptr) { cpp_typecheck.error().source_location=source_location; cpp_typecheck.error() << "template identifier: " << id << '\n' @@ -1959,7 +1959,7 @@ exprt cpp_typecheck_resolvet::guess_function_template_args( static_cast( cpp_typecheck.cpp_scopes.id_map[template_identifier]); - if(template_scope==NULL) + if(template_scope==nullptr) { cpp_typecheck.error().source_location=source_location; cpp_typecheck.error() << "template identifier: " diff --git a/src/cpp/cpp_typecheck_template.cpp b/src/cpp/cpp_typecheck_template.cpp index 47ebd7f006e..7c464208265 100644 --- a/src/cpp/cpp_typecheck_template.cpp +++ b/src/cpp/cpp_typecheck_template.cpp @@ -11,6 +11,7 @@ Author: Daniel Kroening, kroening@cs.cmu.edu #include "cpp_typecheck.h" +#include #include #include "cpp_type2name.h" @@ -910,7 +911,8 @@ cpp_template_args_tct cpp_typecheckt::typecheck_template_args( // these need to be typechecked in the scope of the template, // not in the current scope! cpp_idt *template_scope=cpp_scopes.id_map[template_symbol.name]; - assert(template_scope!=NULL); + INVARIANT_STRUCTURED( + template_scope!=nullptr, nullptr_exceptiont, "template_scope is null"); cpp_scopes.go_to(*template_scope); } @@ -960,7 +962,10 @@ cpp_template_args_tct cpp_typecheckt::typecheck_template_args( { cpp_save_scopet cpp_saved_scope(cpp_scopes); cpp_idt *template_scope=cpp_scopes.id_map[template_symbol.name]; - assert(template_scope!=NULL); + INVARIANT_STRUCTURED( + template_scope!=nullptr, + nullptr_exceptiont, + "template_scope is null"); cpp_scopes.go_to(*template_scope); typecheck_type(type); } diff --git a/src/cpp/parse.cpp b/src/cpp/parse.cpp index 87e9ad099d7..d0c2e01ecf2 100644 --- a/src/cpp/parse.cpp +++ b/src/cpp/parse.cpp @@ -48,7 +48,7 @@ struct indenter // NOLINT(readability/identifiers) class new_scopet { public: - new_scopet():kind(kindt::NONE), anon_count(0), parent(NULL) + new_scopet():kind(kindt::NONE), anon_count(0), parent(nullptr) { } @@ -155,7 +155,7 @@ class new_scopet std::string full_name() const { - return (parent==NULL?"":(parent->full_name()+"::"))+ + return (parent==nullptr?"":(parent->full_name()+"::"))+ id2string(id); } diff --git a/src/goto-cc/armcc_cmdline.cpp b/src/goto-cc/armcc_cmdline.cpp index 9cb3fccfd03..d0a16ac95a0 100644 --- a/src/goto-cc/armcc_cmdline.cpp +++ b/src/goto-cc/armcc_cmdline.cpp @@ -192,7 +192,7 @@ static const char *options_no_arg[]= "--translate_gcc", "--translate_gld", "-W", - NULL + nullptr }; static const char *options_with_prefix[]= @@ -242,7 +242,7 @@ static const char *options_with_prefix[]= "--configure_cpp_headers=", "--configure_extra_includes=", "--configure_extra_libraries=", - NULL + nullptr }; static const char *options_with_arg[]= @@ -262,7 +262,7 @@ static const char *options_with_arg[]= "-o", "--cpu", "--apcs", - NULL + nullptr }; bool armcc_cmdlinet::parse(int argc, const char **argv) diff --git a/src/goto-cc/as86_cmdline.cpp b/src/goto-cc/as86_cmdline.cpp index e60f0152bc0..dce3deecf2c 100644 --- a/src/goto-cc/as86_cmdline.cpp +++ b/src/goto-cc/as86_cmdline.cpp @@ -23,7 +23,7 @@ const char *goto_as86_options_with_argument[]= "--function", "--native-assembler", "--print-rejected-preprocessed-source", - NULL + nullptr }; const char *as86_options_without_argument[]= @@ -40,7 +40,7 @@ const char *as86_options_without_argument[]= "-u-", // both -u and -u- seem to be accepted "-v", "-w-", - NULL + nullptr }; const char *as86_options_with_argument[]= @@ -52,7 +52,7 @@ const char *as86_options_with_argument[]= "-b", "-s", "-t", - NULL + nullptr }; bool as86_cmdlinet::parse(int argc, const char **argv) @@ -75,7 +75,7 @@ bool as86_cmdlinet::parse(int argc, const char **argv) // separated only, and also allow concatenation with "=" for(const char **o=goto_as86_options_with_argument; - *o!=NULL && !found; + *o!=nullptr && !found; ++o) { std::string os(*o); @@ -113,7 +113,7 @@ bool as86_cmdlinet::parse(int argc, const char **argv) } for(const char **o=as86_options_with_argument; - *o!=NULL && !found; + *o!=nullptr && !found; ++o) { std::string os(*o); diff --git a/src/goto-cc/as_cmdline.cpp b/src/goto-cc/as_cmdline.cpp index 172b281458f..2c22cfc70df 100644 --- a/src/goto-cc/as_cmdline.cpp +++ b/src/goto-cc/as_cmdline.cpp @@ -23,7 +23,7 @@ const char *goto_as_options_with_argument[]= "--function", "--native-assembler", "--print-rejected-preprocessed-source", - NULL + nullptr }; const char *as_options_without_argument[]= @@ -59,7 +59,7 @@ const char *as_options_without_argument[]= "--32", // i386 "--64", // i386 "-n", // i386 - NULL + nullptr }; const char *as_options_with_argument[]= @@ -74,7 +74,7 @@ const char *as_options_with_argument[]= "-o", "-march", // i386 "-mtune", // i386 - NULL + nullptr }; bool as_cmdlinet::parse(int argc, const char **argv) @@ -104,7 +104,7 @@ bool as_cmdlinet::parse(int argc, const char **argv) // separated only, and also allow concatenation with "=" for(const char **o=goto_as_options_with_argument; - *o!=NULL && !found; + *o!=nullptr && !found; ++o) { std::string os(*o); @@ -170,7 +170,7 @@ bool as_cmdlinet::parse(int argc, const char **argv) } for(const char **o=as_options_with_argument; - *o!=NULL && !found; + *o!=nullptr && !found; ++o) { std::string os(*o); diff --git a/src/goto-cc/bcc_cmdline.cpp b/src/goto-cc/bcc_cmdline.cpp index c4cbbc80b3f..f4c0626b142 100644 --- a/src/goto-cc/bcc_cmdline.cpp +++ b/src/goto-cc/bcc_cmdline.cpp @@ -24,7 +24,7 @@ const char *goto_bcc_options_with_argument[]= "--native-compiler", "--native-linker", "--print-rejected-preprocessed-source", - NULL + nullptr }; const char *bcc_options_without_argument[]= @@ -46,7 +46,7 @@ const char *bcc_options_without_argument[]= "-x", "-W", "-ansi", - NULL + nullptr }; const char *bcc_options_with_argument[]= @@ -64,7 +64,7 @@ const char *bcc_options_with_argument[]= "-T", "-Q", "-t", - NULL + nullptr }; bool bcc_cmdlinet::parse(int argc, const char **argv) @@ -87,7 +87,7 @@ bool bcc_cmdlinet::parse(int argc, const char **argv) // separated only, and also allow concatenation with "=" for(const char **o=goto_bcc_options_with_argument; - *o!=NULL && !found; + *o!=nullptr && !found; ++o) { std::string os(*o); @@ -125,7 +125,7 @@ bool bcc_cmdlinet::parse(int argc, const char **argv) } for(const char **o=bcc_options_with_argument; - *o!=NULL && !found; + *o!=nullptr && !found; ++o) { std::string os(*o); diff --git a/src/goto-cc/compile.cpp b/src/goto-cc/compile.cpp index 96b76260e96..d5dcf8b5704 100644 --- a/src/goto-cc/compile.cpp +++ b/src/goto-cc/compile.cpp @@ -232,7 +232,7 @@ bool compilet::add_input_file(const std::string &file_name) stream=popen(cmd.str().c_str(), "r"); - if(stream!=NULL) + if(stream!=nullptr) { std::string line; int ch; // fgetc returns an int, not char @@ -472,7 +472,7 @@ bool compilet::parse(const std::string &file_name) else languagep=get_language_from_filename(file_name); - if(languagep==NULL) + if(languagep==nullptr) { error() << "failed to figure out type of file `" << file_name << "'" << eom; return true; diff --git a/src/goto-cc/gcc_cmdline.cpp b/src/goto-cc/gcc_cmdline.cpp index c5b4057ed14..e4b2bb1ddb6 100644 --- a/src/goto-cc/gcc_cmdline.cpp +++ b/src/goto-cc/gcc_cmdline.cpp @@ -29,7 +29,7 @@ const char *goto_cc_options_with_separated_argument[]= "--native-compiler", "--native-linker", "--print-rejected-preprocessed-source", - NULL + nullptr }; // non-gcc options @@ -52,7 +52,7 @@ const char *goto_cc_options_without_argument[]= "--no-arch", "--partial-inlining", "-?", - NULL + nullptr }; // separated or concatenated @@ -75,7 +75,7 @@ const char *gcc_options_with_argument[]= "-U", "-u", // goes to linker "-T", // goes to linker - NULL + nullptr }; const char *gcc_options_with_separated_argument[]= @@ -107,7 +107,7 @@ const char *gcc_options_with_separated_argument[]= "-current_version", // on the Mac "-compatibility_version", // on the Mac "-z", - NULL + nullptr }; const char *gcc_options_with_concatenated_argument[]= @@ -115,7 +115,7 @@ const char *gcc_options_with_concatenated_argument[]= "-d", "-g", "-A", - NULL + nullptr }; const char *gcc_options_without_argument[]= @@ -209,7 +209,7 @@ const char *gcc_options_without_argument[]= "-EB", "-EL", "-fast", // Apple only - NULL + nullptr }; bool gcc_cmdlinet::parse(int argc, const char **argv) @@ -282,7 +282,7 @@ bool gcc_cmdlinet::parse_arguments( // separated only, and also allow concatenation with "=" for(const char **o=goto_cc_options_with_separated_argument; - *o!=NULL && !found; + *o!=nullptr && !found; ++o) { if(argv_i==*o) // separated @@ -354,7 +354,7 @@ bool gcc_cmdlinet::parse_arguments( // separated only, and also allow concatenation with "=" for(const char **o=gcc_options_with_separated_argument; - *o!=NULL && !found; + *o!=nullptr && !found; ++o) { if(argv_i==*o) // separated @@ -380,7 +380,7 @@ bool gcc_cmdlinet::parse_arguments( // concatenated _or_ separated, e.g., -I for(const char **o=gcc_options_with_argument; - *o!=NULL && !found; + *o!=nullptr && !found; ++o) { if(argv_i==*o) // separated @@ -405,7 +405,7 @@ bool gcc_cmdlinet::parse_arguments( // concatenated only for(const char **o=gcc_options_with_concatenated_argument; - *o!=NULL && !found; + *o!=nullptr && !found; ++o) { if(has_prefix(argv_i, *o)) // concatenated diff --git a/src/goto-cc/goto_cc_cmdline.cpp b/src/goto-cc/goto_cc_cmdline.cpp index 71bb06f8160..cb030366e3f 100644 --- a/src/goto-cc/goto_cc_cmdline.cpp +++ b/src/goto-cc/goto_cc_cmdline.cpp @@ -29,7 +29,7 @@ goto_cc_cmdlinet::~goto_cc_cmdlinet() bool goto_cc_cmdlinet::in_list(const char *option, const char **list) { - for(std::size_t i=0; list[i]!=NULL; i++) + for(std::size_t i=0; list[i]!=nullptr; i++) { if(strcmp(option, list[i])==0) return true; @@ -43,7 +43,7 @@ bool goto_cc_cmdlinet::prefix_in_list( const char **list, std::string &prefix) { - for(std::size_t i=0; list[i]!=NULL; i++) + for(std::size_t i=0; list[i]!=nullptr; i++) { if(strncmp(option, list[i], strlen(list[i]))==0) { diff --git a/src/goto-cc/goto_cc_main.cpp b/src/goto-cc/goto_cc_main.cpp index ebe885a37a3..8d3e4222194 100644 --- a/src/goto-cc/goto_cc_main.cpp +++ b/src/goto-cc/goto_cc_main.cpp @@ -48,7 +48,7 @@ int main(int argc, const char **argv) const char **argv=narrow_argv(argc, argv_wide); #endif - if(argv==NULL || argc<1) + if(argv==nullptr || argc<1) { std::cerr << "failed to determine base name\n"; return 1; diff --git a/src/goto-cc/ld_cmdline.cpp b/src/goto-cc/ld_cmdline.cpp index 1f17dabd105..c77ee68773b 100644 --- a/src/goto-cc/ld_cmdline.cpp +++ b/src/goto-cc/ld_cmdline.cpp @@ -24,7 +24,7 @@ const char *goto_ld_options_with_argument[]= "--verbosity", "--native-compiler", "--native-linker", - NULL + nullptr }; const char *ld_options_with_argument[]= @@ -99,7 +99,7 @@ const char *ld_options_with_argument[]= "--ios_version_min", // Apple only "--macosx_version_min", // Apple only "--install_name", // Apple only - NULL + nullptr }; const char *ld_options_without_argument[]= @@ -233,7 +233,7 @@ const char *ld_options_without_argument[]= "--dylib", // Apple only "--dylinker", // Apple only "--bundle", // Apple only - NULL + nullptr }; bool ld_cmdlinet::parse(int argc, const char **argv) @@ -262,7 +262,7 @@ bool ld_cmdlinet::parse(int argc, const char **argv) bool found=false; for(const char **o=goto_ld_options_with_argument; - *o!=NULL && !found; + *o!=nullptr && !found; ++o) { std::string os(*o); @@ -299,7 +299,7 @@ bool ld_cmdlinet::parse(int argc, const char **argv) // also store in cmdlinet - for(const char **o=ld_options_without_argument; *o!=NULL && !found; o++) + for(const char **o=ld_options_without_argument; *o!=nullptr && !found; o++) { std::string os(*o); // ld accepts all long options also as short option @@ -316,7 +316,7 @@ bool ld_cmdlinet::parse(int argc, const char **argv) // 2) concatenated with '=' for long options // 3) separate - for(const char **o=ld_options_with_argument; *o!=NULL && !found; o++) + for(const char **o=ld_options_with_argument; *o!=nullptr && !found; o++) { std::string os(*o); diff --git a/src/goto-cc/ms_cl_cmdline.cpp b/src/goto-cc/ms_cl_cmdline.cpp index ea605ef6d82..cdc9458bb0c 100644 --- a/src/goto-cc/ms_cl_cmdline.cpp +++ b/src/goto-cc/ms_cl_cmdline.cpp @@ -44,7 +44,7 @@ const char *non_ms_cl_options[]= "--partial-inlining", "--verbosity", "--function", - NULL + nullptr }; bool ms_cl_cmdlinet::parse(const std::vector &options) @@ -110,7 +110,7 @@ void ms_cl_cmdlinet::parse_env() const char *CL_env=getenv("CL"); - if(CL_env!=NULL) + if(CL_env!=nullptr) process_response_file_line(CL_env); #endif @@ -275,7 +275,7 @@ void ms_cl_cmdlinet::process_non_cl_option( { set(s); - for(unsigned j=0; non_ms_cl_options[j]!=NULL; j++) + for(unsigned j=0; non_ms_cl_options[j]!=nullptr; j++) if(s==non_ms_cl_options[j]) return; @@ -288,7 +288,7 @@ void ms_cl_cmdlinet::process_non_cl_option( const char *ms_cl_flags[]= { "c", // compile only - NULL + nullptr }; const char *ms_cl_prefixes[]= @@ -406,7 +406,7 @@ const char *ms_cl_prefixes[]= "MT", // link with LIBCMT.LIB "MDd", // link with MSVCRTD.LIB debug lib "MTd", // link with LIBCMTD.LIB debug lib - NULL + nullptr }; void ms_cl_cmdlinet::process_cl_option(const std::string &s) @@ -420,7 +420,7 @@ void ms_cl_cmdlinet::process_cl_option(const std::string &s) return; } - for(std::size_t j=0; ms_cl_flags[j]!=NULL; j++) + for(std::size_t j=0; ms_cl_flags[j]!=nullptr; j++) { if(std::string(s, 1, std::string::npos)==ms_cl_flags[j]) { @@ -453,7 +453,7 @@ void ms_cl_cmdlinet::process_cl_option(const std::string &s) } } - for(std::size_t j=0; ms_cl_prefixes[j]!=NULL; j++) + for(std::size_t j=0; ms_cl_prefixes[j]!=nullptr; j++) { std::string ms_cl_prefix=ms_cl_prefixes[j]; diff --git a/src/goto-instrument/dump_c.cpp b/src/goto-instrument/dump_c.cpp index efa0ac4afc2..1020d2021a1 100644 --- a/src/goto-instrument/dump_c.cpp +++ b/src/goto-instrument/dump_c.cpp @@ -1309,7 +1309,7 @@ static bool find_block_position_rec( if(!root.has_operands()) return false; - code_blockt *our_dest=0; + code_blockt *our_dest=nullptr; exprt::operandst &operands=root.operands(); exprt::operandst::iterator first_found=operands.end(); @@ -1400,14 +1400,14 @@ void dump_ct::insert_local_static_decls( std::list redundant; cleanup_decl(d, redundant, type_decls); - code_blockt *dest_ptr=0; + code_blockt *dest_ptr=nullptr; exprt::operandst::iterator before=b.operands().end(); // some use of static variables might be optimised out if it is // within an if(false) { ... } block if(find_block_position_rec(*it, b, dest_ptr, before)) { - CHECK_RETURN(dest_ptr!=0); + CHECK_RETURN(dest_ptr!=nullptr); dest_ptr->operands().insert(before, d); } } @@ -1437,14 +1437,14 @@ void dump_ct::insert_local_type_decls( // another hack to ensure symbols inside types are seen skip.type()=type; - code_blockt *dest_ptr=0; + code_blockt *dest_ptr=nullptr; exprt::operandst::iterator before=b.operands().end(); // we might not find it in case a transparent union type cast // has been removed by cleanup operations if(find_block_position_rec(*it, b, dest_ptr, before)) { - CHECK_RETURN(dest_ptr!=0); + CHECK_RETURN(dest_ptr!=nullptr); dest_ptr->operands().insert(before, skip); } } diff --git a/src/goto-instrument/model_argc_argv.cpp b/src/goto-instrument/model_argc_argv.cpp index bae8010d907..7e01d66e62a 100644 --- a/src/goto-instrument/model_argc_argv.cpp +++ b/src/goto-instrument/model_argc_argv.cpp @@ -38,7 +38,7 @@ bool model_argc_argv( messaget message(message_handler); const namespacet ns(symbol_table); - const symbolt *init_symbol=0; + const symbolt *init_symbol=nullptr; if(ns.lookup(CPROVER_PREFIX "initialize", init_symbol)) { message.error() << "Linking not done, missing " diff --git a/src/goto-instrument/wmm/cycle_collection.cpp b/src/goto-instrument/wmm/cycle_collection.cpp index caef3e7ee77..64b619c4369 100644 --- a/src/goto-instrument/wmm/cycle_collection.cpp +++ b/src/goto-instrument/wmm/cycle_collection.cpp @@ -56,7 +56,7 @@ void event_grapht::graph_explorert::collect_cycles( for(std::size_t i=0; i* order=0; + std::list* order=nullptr; /* on Power, rfe pairs are also potentially unsafe */ switch(model) { diff --git a/src/goto-instrument/wmm/goto2graph.cpp b/src/goto-instrument/wmm/goto2graph.cpp index 7828ac8008a..011ef1a36ac 100644 --- a/src/goto-instrument/wmm/goto2graph.cpp +++ b/src/goto-instrument/wmm/goto2graph.cpp @@ -1198,7 +1198,7 @@ bool instrumentert::is_cfg_spurious(const event_grapht::critical_cyclet &cyc) const source_locationt ¤t_location=current_event.source_location; /* select relevant thread (po) -- or function contained in this thread */ - goto_programt *current_po=0; + goto_programt *current_po=nullptr; bool thread_found=false; Forall_goto_functions(f_it, goto_functions) diff --git a/src/goto-programs/initialize_goto_model.cpp b/src/goto-programs/initialize_goto_model.cpp index d284bc403c9..eb2b6f8490b 100644 --- a/src/goto-programs/initialize_goto_model.cpp +++ b/src/goto-programs/initialize_goto_model.cpp @@ -81,7 +81,7 @@ bool initialize_goto_model( lf.filename=filename; lf.language=get_language_from_filename(filename); - if(lf.language==NULL) + if(lf.language==nullptr) { source_locationt location; location.set_file(filename); diff --git a/src/goto-programs/interpreter.cpp b/src/goto-programs/interpreter.cpp index a79910b7654..817d04c3a59 100644 --- a/src/goto-programs/interpreter.cpp +++ b/src/goto-programs/interpreter.cpp @@ -70,7 +70,7 @@ void interpretert::command() { #define BUFSIZE 100 char command[BUFSIZE]; - if(fgets(command, BUFSIZE-1, stdin)==NULL) + if(fgets(command, BUFSIZE-1, stdin)==nullptr) { done=true; return; diff --git a/src/goto-programs/show_symbol_table.cpp b/src/goto-programs/show_symbol_table.cpp index 1d5ce87f5a6..6a15759f11e 100644 --- a/src/goto-programs/show_symbol_table.cpp +++ b/src/goto-programs/show_symbol_table.cpp @@ -48,7 +48,7 @@ void show_symbol_table_plain( else { ptr=get_language_from_mode(symbol.mode); - if(ptr==NULL) + if(ptr==nullptr) throw "symbol "+id2string(symbol.name)+" has unknown mode"; } diff --git a/src/goto-symex/goto_symex_state.cpp b/src/goto-symex/goto_symex_state.cpp index 6fdf4b54aa8..6402923c4cf 100644 --- a/src/goto-symex/goto_symex_state.cpp +++ b/src/goto-symex/goto_symex_state.cpp @@ -15,6 +15,7 @@ Author: Daniel Kroening, kroening@kroening.com #include #include +#include #include #include @@ -22,10 +23,10 @@ Author: Daniel Kroening, kroening@kroening.com goto_symex_statet::goto_symex_statet(): depth(0), - symex_target(NULL), + symex_target(nullptr), atomic_section_id(0), record_events(true), - dirty(0) + dirty(nullptr) { threads.resize(1); new_frame(); @@ -541,7 +542,7 @@ bool goto_symex_statet::l2_thread_read_encoding( return false; // is it a shared object? - assert(dirty!=0); + INVARIANT_STRUCTURED(dirty!=nullptr, nullptr_exceptiont, "dirty is null"); const irep_idt &obj_identifier=expr.get_object_name(); if(obj_identifier=="goto_symex::\\guard" || (!ns.lookup(obj_identifier).is_shared() && @@ -666,7 +667,8 @@ bool goto_symex_statet::l2_thread_read_encoding( expr=ssa_l1; // and record that - assert(symex_target!=NULL); + INVARIANT_STRUCTURED( + symex_target!=nullptr, nullptr_exceptiont, "symex_target is null"); symex_target->shared_read( guard.as_expr(), expr, @@ -685,7 +687,7 @@ bool goto_symex_statet::l2_thread_write_encoding( return false; // is it a shared object? - assert(dirty!=0); + INVARIANT_STRUCTURED(dirty!=nullptr, nullptr_exceptiont, "dirty is null"); const irep_idt &obj_identifier=expr.get_object_name(); if(obj_identifier=="goto_symex::\\guard" || (!ns.lookup(obj_identifier).is_shared() && diff --git a/src/goto-symex/slice_by_trace.cpp b/src/goto-symex/slice_by_trace.cpp index 80acfa4add8..828b457caa0 100644 --- a/src/goto-symex/slice_by_trace.cpp +++ b/src/goto-symex/slice_by_trace.cpp @@ -187,9 +187,9 @@ void symex_slice_by_tracet::parse_events(std::string read_line) { if(read_line=="") return; - bool parity=strstr(read_line.c_str(), "!")==NULL; - bool universe=strstr(read_line.c_str(), "?")!=NULL; - bool has_values=strstr(read_line.c_str(), " ")!=NULL; + bool parity=strstr(read_line.c_str(), "!")==nullptr; + bool universe=strstr(read_line.c_str(), "?")!=nullptr; + bool has_values=strstr(read_line.c_str(), " ")!=nullptr; std::cout << "Trace: " << read_line << '\n'; std::vector value_v; if(has_values) diff --git a/src/goto-symex/symex_dereference_state.cpp b/src/goto-symex/symex_dereference_state.cpp index f0e36f5d03c..9911ba51e7d 100644 --- a/src/goto-symex/symex_dereference_state.cpp +++ b/src/goto-symex/symex_dereference_state.cpp @@ -43,7 +43,7 @@ bool symex_dereference_statet::has_failed_symbol( !ns.lookup(failed_symbol, symbol)) { symbolt sym=*symbol; - symbolt *sym_ptr=0; + symbolt *sym_ptr=nullptr; symbol_exprt sym_expr=sym.symbol_expr(); state.rename(sym_expr, ns, goto_symex_statet::L1); sym.name=to_ssa_expr(sym_expr).get_identifier(); @@ -64,7 +64,7 @@ bool symex_dereference_statet::has_failed_symbol( !ns.lookup(failed_symbol, symbol)) { symbolt sym=*symbol; - symbolt *sym_ptr=0; + symbolt *sym_ptr=nullptr; symbol_exprt sym_expr=sym.symbol_expr(); state.rename(sym_expr, ns, goto_symex_statet::L1); sym.name=to_ssa_expr(sym_expr).get_identifier(); diff --git a/src/goto-symex/symex_function_call.cpp b/src/goto-symex/symex_function_call.cpp index a71a142b89b..06d519e4941 100644 --- a/src/goto-symex/symex_function_call.cpp +++ b/src/goto-symex/symex_function_call.cpp @@ -139,7 +139,7 @@ void goto_symext::parameter_assignments( { // These are va_arg arguments; their types may differ from call to call unsigned va_count=0; - const symbolt *va_sym=0; + const symbolt *va_sym=nullptr; while(!ns.lookup( id2string(function_identifier)+"::va_arg"+std::to_string(va_count), va_sym)) diff --git a/src/goto-symex/symex_main.cpp b/src/goto-symex/symex_main.cpp index b8a1e294f10..4fce789ad3a 100644 --- a/src/goto-symex/symex_main.cpp +++ b/src/goto-symex/symex_main.cpp @@ -158,7 +158,7 @@ void goto_symext::operator()( } delete state.dirty; - state.dirty=0; + state.dirty=nullptr; } /// symex starting from given program diff --git a/src/java_bytecode/java_bytecode_convert_method.cpp b/src/java_bytecode/java_bytecode_convert_method.cpp index 8a02f4f8855..5c2135e8afe 100644 --- a/src/java_bytecode/java_bytecode_convert_method.cpp +++ b/src/java_bytecode/java_bytecode_convert_method.cpp @@ -406,7 +406,7 @@ void java_bytecode_convert_methodt::convert( const bytecode_infot &java_bytecode_convert_methodt::get_bytecode_info( const irep_idt &statement) { - for(const bytecode_infot *p=bytecode_info; p->mnemonic!=0; p++) + for(const bytecode_infot *p=bytecode_info; p->mnemonic!=nullptr; p++) if(statement==p->mnemonic) return *p; diff --git a/src/java_bytecode/java_bytecode_parser.cpp b/src/java_bytecode/java_bytecode_parser.cpp index 77874da4944..d24141b76da 100644 --- a/src/java_bytecode/java_bytecode_parser.cpp +++ b/src/java_bytecode/java_bytecode_parser.cpp @@ -99,7 +99,7 @@ class java_bytecode_parsert:public parsert { // pre-hash the mnemonics, so we do this only once bytecodes.resize(256); - for(const bytecode_infot *p=bytecode_info; p->mnemonic!=0; p++) + for(const bytecode_infot *p=bytecode_info; p->mnemonic!=nullptr; p++) { assert(p->opcodeopcode].mnemonic=p->mnemonic; diff --git a/src/java_bytecode/java_local_variable_table.cpp b/src/java_bytecode/java_local_variable_table.cpp index 052b958d058..94d5062fb24 100644 --- a/src/java_bytecode/java_local_variable_table.cpp +++ b/src/java_bytecode/java_local_variable_table.cpp @@ -288,7 +288,7 @@ static void populate_predecessor_map( auto pred_var= (predmode); - if(ptr==NULL) + if(ptr==nullptr) throw "symbol `"+id2string(symbol->name)+ "' has unknown mode '"+id2string(symbol->mode)+"'"; diff --git a/src/langapi/mode.cpp b/src/langapi/mode.cpp index 55c533f9495..2c3a852b73a 100644 --- a/src/langapi/mode.cpp +++ b/src/langapi/mode.cpp @@ -45,7 +45,7 @@ languaget *get_language_from_mode(const irep_idt &mode) if(mode==it->mode) return it->factory(); - return NULL; + return nullptr; } languaget *get_language_from_filename(const std::string &filename) @@ -53,13 +53,13 @@ languaget *get_language_from_filename(const std::string &filename) std::size_t ext_pos=filename.rfind('.'); if(ext_pos==std::string::npos) - return NULL; + return nullptr; std::string extension= std::string(filename, ext_pos+1, std::string::npos); if(extension=="") - return NULL; + return nullptr; for(languagest::const_iterator l_it=languages.begin(); @@ -79,7 +79,7 @@ languaget *get_language_from_filename(const std::string &filename) #endif } - return NULL; + return nullptr; } languaget *get_default_language() diff --git a/src/path-symex/path_symex_history.h b/src/path-symex/path_symex_history.h index 4371e5e26d3..0783281c703 100644 --- a/src/path-symex/path_symex_history.h +++ b/src/path-symex/path_symex_history.h @@ -15,6 +15,7 @@ Author: Daniel Kroening, kroening@kroening.com #include #include +#include #include #include "loc_ref.h" @@ -35,7 +36,7 @@ class path_symex_step_reft } path_symex_step_reft(): - index(std::numeric_limits::max()), history(0) + index(std::numeric_limits::max()), history(nullptr) { } @@ -46,7 +47,8 @@ class path_symex_step_reft path_symex_historyt &get_history() const { - assert(history!=0); + INVARIANT_STRUCTURED( + history!=nullptr, nullptr_exceptiont, "history is null"); return *history; } @@ -154,7 +156,8 @@ class path_symex_historyt inline void path_symex_step_reft::generate_successor() { - assert(history!=0); + INVARIANT_STRUCTURED( + history!=nullptr, nullptr_exceptiont, "history is null"); path_symex_step_reft old=*this; index=history->step_container.size(); history->step_container.push_back(path_symex_stept()); @@ -169,7 +172,8 @@ inline path_symex_step_reft &path_symex_step_reft::operator--() inline path_symex_stept &path_symex_step_reft::get() const { - assert(history!=0); + INVARIANT_STRUCTURED( + history!=nullptr, nullptr_exceptiont, "history is null"); assert(!is_nil()); return history->step_container[index]; } diff --git a/src/path-symex/path_symex_state_read.cpp b/src/path-symex/path_symex_state_read.cpp index a6993c19b05..87dea21be4a 100644 --- a/src/path-symex/path_symex_state_read.cpp +++ b/src/path-symex/path_symex_state_read.cpp @@ -430,7 +430,7 @@ bool path_symex_statet::is_symbol_member_index(const exprt &src) const // the loop avoids recursion while(true) { - const exprt *next=0; + const exprt *next=nullptr; if(current->id()==ID_symbol) { @@ -465,7 +465,7 @@ bool path_symex_statet::is_symbol_member_index(const exprt &src) const return false; // next round - assert(next!=0); + INVARIANT_STRUCTURED(next!=nullptr, nullptr_exceptiont, "next is null"); current=next; } } diff --git a/src/path-symex/var_map.cpp b/src/path-symex/var_map.cpp index f5dea20a96d..96d079c48ff 100644 --- a/src/path-symex/var_map.cpp +++ b/src/path-symex/var_map.cpp @@ -84,7 +84,7 @@ void var_mapt::init(var_infot &var_info) } else { - const symbolt *symbol=0; + const symbolt *symbol=nullptr; if(ns.lookup(var_info.symbol, symbol)) throw "var_mapt::init identifier \"" +id2string(var_info.full_identifier) diff --git a/src/pointer-analysis/value_set_fi.cpp b/src/pointer-analysis/value_set_fi.cpp index 77962a3b3b2..d08694b82da 100644 --- a/src/pointer-analysis/value_set_fi.cpp +++ b/src/pointer-analysis/value_set_fi.cpp @@ -550,18 +550,18 @@ void value_set_fit::get_value_set_rec( if(expr.type().id()==ID_pointer) { // find the pointer operand - const exprt *ptr_operand=NULL; + const exprt *ptr_operand=nullptr; forall_operands(it, expr) if(it->type().id()==ID_pointer) { - if(ptr_operand==NULL) + if(ptr_operand==nullptr) ptr_operand=&(*it); else throw "more than one pointer operand in pointer arithmetic"; } - if(ptr_operand==NULL) + if(ptr_operand==nullptr) throw "pointer type sum expected to have pointer operand"; object_mapt pointer_expr_set; diff --git a/src/pointer-analysis/value_set_fivr.cpp b/src/pointer-analysis/value_set_fivr.cpp index 6bd7e1321e9..3ea5ef1aa8e 100644 --- a/src/pointer-analysis/value_set_fivr.cpp +++ b/src/pointer-analysis/value_set_fivr.cpp @@ -668,18 +668,18 @@ void value_set_fivrt::get_value_set_rec( if(expr.type().id()==ID_pointer) { // find the pointer operand - const exprt *ptr_operand=NULL; + const exprt *ptr_operand=nullptr; forall_operands(it, expr) if(it->type().id()==ID_pointer) { - if(ptr_operand==NULL) + if(ptr_operand==nullptr) ptr_operand=&(*it); else throw "more than one pointer operand in pointer arithmetic"; } - if(ptr_operand==NULL) + if(ptr_operand==nullptr) throw "pointer type sum expected to have pointer operand"; object_mapt pointer_expr_set; diff --git a/src/pointer-analysis/value_set_fivrns.cpp b/src/pointer-analysis/value_set_fivrns.cpp index 0eaf08b201b..3b5ce55a3aa 100644 --- a/src/pointer-analysis/value_set_fivrns.cpp +++ b/src/pointer-analysis/value_set_fivrns.cpp @@ -454,18 +454,18 @@ void value_set_fivrnst::get_value_set_rec( if(expr.type().id()==ID_pointer) { // find the pointer operand - const exprt *ptr_operand=NULL; + const exprt *ptr_operand=nullptr; forall_operands(it, expr) if(it->type().id()==ID_pointer) { - if(ptr_operand==NULL) + if(ptr_operand==nullptr) ptr_operand=&(*it); else throw "more than one pointer operand in pointer arithmetic"; } - if(ptr_operand==NULL) + if(ptr_operand==nullptr) throw "pointer type sum expected to have pointer operand"; object_mapt pointer_expr_set; diff --git a/src/solvers/miniBDD/miniBDD.h b/src/solvers/miniBDD/miniBDD.h index f7dde020fe6..9b994b88ff6 100644 --- a/src/solvers/miniBDD/miniBDD.h +++ b/src/solvers/miniBDD/miniBDD.h @@ -55,7 +55,7 @@ class mini_bddt unsigned node_number() const; void clear(); - bool is_initialized() const { return node!=0; } + bool is_initialized() const { return node!=nullptr; } // internal explicit mini_bddt(class mini_bdd_nodet *_node); diff --git a/src/solvers/miniBDD/miniBDD.inc b/src/solvers/miniBDD/miniBDD.inc index 091725ed333..a2077ab95f1 100644 --- a/src/solvers/miniBDD/miniBDD.inc +++ b/src/solvers/miniBDD/miniBDD.inc @@ -2,7 +2,7 @@ // inline functions -inline mini_bddt::mini_bddt():node(0) +inline mini_bddt::mini_bddt():node(nullptr) { } @@ -82,7 +82,7 @@ inline void mini_bddt::clear() if(is_initialized()) { node->remove_reference(); - node=NULL; + node=nullptr; } } diff --git a/src/solvers/sat/pbs_dimacs_cnf.cpp b/src/solvers/sat/pbs_dimacs_cnf.cpp index 731c6ac7ae6..69e4c78a290 100644 --- a/src/solvers/sat/pbs_dimacs_cnf.cpp +++ b/src/solvers/sat/pbs_dimacs_cnf.cpp @@ -125,7 +125,7 @@ bool pbs_dimacs_cnft::pbs_solve() { std::getline(file, line); if(strstr(line.c_str(), - "Variable Assignments Satisfying CNF Formula:")!=NULL) + "Variable Assignments Satisfying CNF Formula:")!=nullptr) { // print ("Reading assignments...\n"); // std::cout << "No literals: " << no_variables() << "\n"; @@ -143,12 +143,12 @@ bool pbs_dimacs_cnft::pbs_solve() // std::cout << "\n"; // print ("Finished reading assignments.\n"); } - else if(strstr(line.c_str(), "SAT... SUM")!=NULL) + else if(strstr(line.c_str(), "SAT... SUM")!=nullptr) { // print (line); sscanf(line.c_str(), "%*s %*s %*s %d", &opt_sum); } - else if(strstr(line.c_str(), "SAT - All implied")!=NULL) + else if(strstr(line.c_str(), "SAT - All implied")!=nullptr) { // print (line); sscanf( @@ -156,15 +156,15 @@ bool pbs_dimacs_cnft::pbs_solve() "%*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %d", &opt_sum); } - else if(strstr(line.c_str(), "SAT... Solution")!=NULL) + else if(strstr(line.c_str(), "SAT... Solution")!=nullptr) { // print(line); sscanf(line.c_str(), "%*s %*s %*s %d", &opt_sum); } - else if(strstr(line.c_str(), "Optimal Soln")!=NULL) + else if(strstr(line.c_str(), "Optimal Soln")!=nullptr) { // print(line); - if(strstr(line.c_str(), "time out")!=NULL) + if(strstr(line.c_str(), "time out")!=nullptr) { status() << "WARNING: TIMED OUT. SOLUTION MAY BE INCORRECT." << eom; diff --git a/src/util/base_exceptions.h b/src/util/base_exceptions.h new file mode 100644 index 00000000000..6d1218a9e7c --- /dev/null +++ b/src/util/base_exceptions.h @@ -0,0 +1,37 @@ +/*******************************************************************\ + +Module: Util base exceptions + +Author: Diffblue Ltd. + +\*******************************************************************/ + +/// \file +/// Generic exception types primarily designed for use with invariants. + +#ifndef CPROVER_UTIL_BASE_EXCEPTIONS_H +#define CPROVER_UTIL_BASE_EXCEPTIONS_H + +#include "util/invariant.h" + +class bad_cast_exceptiont:public invariant_failedt +{ +public: + // Normally we'd prefer + // using invariant_failedt::invariant_failedt; + // However, this isn't supported on VS2013. + + template + explicit bad_cast_exceptiont(Ts &&...ts): + invariant_failedt(std::forward(ts)...) {} +}; + +class nullptr_exceptiont:public invariant_failedt +{ +public: + template + explicit nullptr_exceptiont(Ts &&...ts): + invariant_failedt(std::forward(ts)...) {} +}; + +#endif diff --git a/src/util/config.cpp b/src/util/config.cpp index ee24ab7b0f7..a256ff6b17e 100644 --- a/src/util/config.cpp +++ b/src/util/config.cpp @@ -739,7 +739,7 @@ bool configt::set(const cmdlinet &cmdline) ansi_c.arch="none"; ansi_c.lib=configt::ansi_ct::libt::LIB_NONE; // NOLINTNEXTLINE(readability/casting) - ansi_c.NULL_is_zero=reinterpret_cast((void*)0)==0; + ansi_c.NULL_is_zero=reinterpret_cast(nullptr)==0; // Default is ROUND_TO_EVEN, justified by C99: // 1 At program startup the floating-point environment is initialized as @@ -773,7 +773,7 @@ bool configt::set(const cmdlinet &cmdline) { // environment variable set? const char *CLASSPATH=getenv("CLASSPATH"); - if(CLASSPATH!=NULL) + if(CLASSPATH!=nullptr) set_classpath(CLASSPATH); else set_classpath("."); // default diff --git a/src/util/file_util.cpp b/src/util/file_util.cpp index 3753fa5aab8..37dfd595876 100644 --- a/src/util/file_util.cpp +++ b/src/util/file_util.cpp @@ -51,7 +51,7 @@ std::string get_current_working_directory() errno=0; - while(buf && getcwd(buf, bsize-1)==NULL && errno==ERANGE) + while(buf && getcwd(buf, bsize-1)==nullptr && errno==ERANGE) { bsize*=2; buf=reinterpret_cast(realloc(buf, sizeof(char)*bsize)); @@ -98,10 +98,10 @@ void delete_directory(const std::string &path) delete_directory_utf16(utf8_to_utf16_little_endian(path)); #else DIR *dir=opendir(path.c_str()); - if(dir!=NULL) + if(dir!=nullptr) { struct dirent *ent; - while((ent=readdir(dir))!=NULL) + while((ent=readdir(dir))!=nullptr) { // Needed for Alpine Linux if(strcmp(ent->d_name, ".")==0 || strcmp(ent->d_name, "..")==0) diff --git a/src/util/invariant.cpp b/src/util/invariant.cpp index eb63382ef76..d3f750041a3 100644 --- a/src/util/invariant.cpp +++ b/src/util/invariant.cpp @@ -54,7 +54,7 @@ static bool output_demangled_name( int demangle_success=1; char *demangled= - abi::__cxa_demangle(mangled.c_str(), NULL, 0, &demangle_success); + abi::__cxa_demangle(mangled.c_str(), nullptr, nullptr, &demangle_success); if(demangle_success==0) { diff --git a/src/util/irep_ids.cpp b/src/util/irep_ids.cpp index 8aff81777ae..50e0f537fa5 100644 --- a/src/util/irep_ids.cpp +++ b/src/util/irep_ids.cpp @@ -22,7 +22,7 @@ const char *irep_ids_table[]= #include "irep_ids.def" - NULL, + nullptr, }; #ifdef USE_DSTRING @@ -47,7 +47,7 @@ void initialize_string_container() { // this is called by the constructor of string_containert - for(unsigned i=0; irep_ids_table[i]!=NULL; i++) + for(unsigned i=0; irep_ids_table[i]!=nullptr; i++) { unsigned x; x=string_container[irep_ids_table[i]]; diff --git a/src/util/language_file.cpp b/src/util/language_file.cpp index 2aa57a85c6a..7ca179f68fe 100644 --- a/src/util/language_file.cpp +++ b/src/util/language_file.cpp @@ -14,14 +14,14 @@ Author: Daniel Kroening, kroening@kroening.com language_filet::language_filet(const language_filet &rhs): modules(rhs.modules), - language(rhs.language==NULL?NULL:rhs.language->new_language()), + language(rhs.language==nullptr?nullptr:rhs.language->new_language()), filename(rhs.filename) { } language_filet::~language_filet() { - if(language!=NULL) + if(language!=nullptr) delete language; } diff --git a/src/util/language_file.h b/src/util/language_file.h index e2e8750be5d..a18d4685a39 100644 --- a/src/util/language_file.h +++ b/src/util/language_file.h @@ -49,7 +49,7 @@ class language_filet language_filet(const language_filet &rhs); - language_filet():language(NULL) + language_filet():language(nullptr) { } diff --git a/src/util/message.h b/src/util/message.h index 41c91174001..c3d73d5f4d2 100644 --- a/src/util/message.h +++ b/src/util/message.h @@ -133,7 +133,7 @@ class messaget // constructors, destructor messaget(): - message_handler(NULL), + message_handler(nullptr), mstream(M_DEBUG, *this) { } diff --git a/src/util/namespace.cpp b/src/util/namespace.cpp index 50de95f2961..218e73d2850 100644 --- a/src/util/namespace.cpp +++ b/src/util/namespace.cpp @@ -127,10 +127,10 @@ unsigned namespacet::get_max(const std::string &prefix) const { unsigned m=0; - if(symbol_table1!=NULL) + if(symbol_table1!=nullptr) m=std::max(m, ::get_max(prefix, symbol_table1->symbols)); - if(symbol_table2!=NULL) + if(symbol_table2!=nullptr) m=std::max(m, ::get_max(prefix, symbol_table2->symbols)); return m; @@ -142,7 +142,7 @@ bool namespacet::lookup( { symbol_tablet::symbolst::const_iterator it; - if(symbol_table1!=NULL) + if(symbol_table1!=nullptr) { it=symbol_table1->symbols.find(name); @@ -153,7 +153,7 @@ bool namespacet::lookup( } } - if(symbol_table2!=NULL) + if(symbol_table2!=nullptr) { it=symbol_table2->symbols.find(name); diff --git a/src/util/namespace.h b/src/util/namespace.h index ea6b33cfdbd..a3b9f3827c6 100644 --- a/src/util/namespace.h +++ b/src/util/namespace.h @@ -64,7 +64,7 @@ class namespacet:public namespace_baset public: // constructors explicit namespacet(const symbol_tablet &_symbol_table) - { symbol_table1=&_symbol_table; symbol_table2=NULL; } + { symbol_table1=&_symbol_table; symbol_table2=nullptr; } namespacet( const symbol_tablet &_symbol_table1, @@ -101,12 +101,12 @@ class multi_namespacet:public namespacet { public: // constructors - multi_namespacet():namespacet(NULL, NULL) + multi_namespacet():namespacet(nullptr, nullptr) { } explicit multi_namespacet( - const symbol_tablet &symbol_table):namespacet(NULL, NULL) + const symbol_tablet &symbol_table):namespacet(nullptr, nullptr) { add(symbol_table); } diff --git a/src/util/parser.h b/src/util/parser.h index b450de7f614..bf572e6004d 100644 --- a/src/util/parser.h +++ b/src/util/parser.h @@ -39,7 +39,7 @@ class parsert:public messaget last_line.clear(); } - parsert():in(NULL) { clear(); } + parsert():in(nullptr) { clear(); } virtual ~parsert() { } // The following are for the benefit of the scanner diff --git a/src/util/pipe_stream.cpp b/src/util/pipe_stream.cpp index 4306bce8e00..44ac29b3eb4 100644 --- a/src/util/pipe_stream.cpp +++ b/src/util/pipe_stream.cpp @@ -159,12 +159,12 @@ int pipe_streamt::run() a_it++, i++) _argv[i]=strdup(a_it->c_str()); - _argv[args.size()+1]=NULL; + _argv[args.size()+1]=nullptr; int result=execvp(executable.c_str(), _argv); if(result==-1) - perror(0); + perror(nullptr); return result; } @@ -289,7 +289,7 @@ std::streamsize filedescriptor_streambuft::xsputn( /// read a character from the piped process std::streambuf::int_type filedescriptor_streambuft::underflow() { - if(gptr()==0) + if(gptr()==nullptr) return traits_type::eof(); if(gptr() bool empty() const { - if(d==NULL) + if(d==nullptr) return true; return d->expr_set.empty(); } @@ -52,13 +52,13 @@ class ref_expr_sett:public reference_counting bool make_union(const ref_expr_sett &s2) { - if(s2.d==NULL) + if(s2.d==nullptr) return false; if(s2.d==d) return false; - if(d==NULL) + if(d==nullptr) { copy_from(s2); return true; diff --git a/src/util/reference_counting.h b/src/util/reference_counting.h index ffdc8eed754..4d5accb5ece 100644 --- a/src/util/reference_counting.h +++ b/src/util/reference_counting.h @@ -19,7 +19,7 @@ template class reference_counting { public: - reference_counting():d(NULL) + reference_counting():d(nullptr) { } @@ -31,7 +31,7 @@ class reference_counting // copy constructor reference_counting(const reference_counting &other):d(other.d) { - if(d!=NULL) + if(d!=nullptr) { assert(d->ref_count!=0); d->ref_count++; @@ -50,7 +50,7 @@ class reference_counting ~reference_counting() { remove_ref(d); - d=NULL; + d=nullptr; } void swap(reference_counting &other) @@ -61,12 +61,12 @@ class reference_counting void clear() { remove_ref(d); - d=NULL; + d=nullptr; } const T &read() const { - if(d==NULL) + if(d==nullptr) return T::blank; return *d; } @@ -104,7 +104,7 @@ class reference_counting remove_ref(d); d=other.d; - if(d!=NULL) + if(d!=nullptr) d->ref_count++; } @@ -118,7 +118,7 @@ class reference_counting template void reference_counting::remove_ref(dt *old_d) { - if(old_d==NULL) + if(old_d==nullptr) return; assert(old_d->ref_count!=0); @@ -151,7 +151,7 @@ void reference_counting::detatch() std::cout << "DETATCH1: " << d << '\n'; #endif - if(d==NULL) + if(d==nullptr) { d=new dt; diff --git a/src/util/run.cpp b/src/util/run.cpp index 164cac834d3..c01aff35bd6 100644 --- a/src/util/run.cpp +++ b/src/util/run.cpp @@ -117,13 +117,13 @@ int run( { // resume signals remove_signal_catcher(); - sigprocmask(SIG_SETMASK, &old_mask, NULL); + sigprocmask(SIG_SETMASK, &old_mask, nullptr); char **_argv=new char * [argv.size()+1]; for(std::size_t i=0; i &s) const char **narrow_argv(int argc, const wchar_t **argv_wide) { - if(argv_wide==NULL) - return NULL; + if(argv_wide==nullptr) + return nullptr; // the following never gets deleted const char **argv_narrow=new const char *[argc+1]; - argv_narrow[argc]=0; + argv_narrow[argc]=nullptr; for(int i=0; i