From 7491954f946689bcaea3ce2674a763a89381ed58 Mon Sep 17 00:00:00 2001 From: Michael Tautschnig Date: Wed, 23 Mar 2022 21:53:40 +0000 Subject: [PATCH] Remove unqualified use of nullopt When moving to std::optional we'd have to use std::nullopt. Avoid doing so by using {} instead, which works today and will work with std::optional. --- src/ansi-c/expr2c.cpp | 2 +- .../unreachable_instructions.cpp | 4 +-- src/memory-analyzer/gdb_api.h | 2 +- src/solvers/flattening/boolbv.h | 2 +- src/solvers/flattening/boolbv_quantifier.cpp | 4 +-- src/util/edit_distance.cpp | 2 +- src/util/optional_utils.h | 2 +- src/util/string2int.cpp | 4 +-- unit/util/string2int.cpp | 30 +++++++++---------- 9 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/ansi-c/expr2c.cpp b/src/ansi-c/expr2c.cpp index b776bfe6b16..e1d24ea6d35 100644 --- a/src/ansi-c/expr2c.cpp +++ b/src/ansi-c/expr2c.cpp @@ -4031,7 +4031,7 @@ optionalt expr2ct::convert_function(const exprt &src) const auto function_entry = function_names.find(src.id()); if(function_entry == function_names.end()) - return nullopt; + return {}; return convert_function(src, function_entry->second); } diff --git a/src/goto-analyzer/unreachable_instructions.cpp b/src/goto-analyzer/unreachable_instructions.cpp index 32af3d4ea86..aa2180ae386 100644 --- a/src/goto-analyzer/unreachable_instructions.cpp +++ b/src/goto-analyzer/unreachable_instructions.cpp @@ -104,7 +104,7 @@ static optionalt file_name_string_opt(const source_locationt &source_location) { if(source_location.get_file().empty()) - return nullopt; + return {}; return concat_dir_file( id2string(source_location.get_working_directory()), @@ -255,7 +255,7 @@ line_string_opt(const source_locationt &source_location) const irep_idt &line = source_location.get_line(); if(line.empty()) - return nullopt; + return {}; else return id2string(line); } diff --git a/src/memory-analyzer/gdb_api.h b/src/memory-analyzer/gdb_api.h index 2190731c0d6..a672d644e3e 100644 --- a/src/memory-analyzer/gdb_api.h +++ b/src/memory-analyzer/gdb_api.h @@ -80,7 +80,7 @@ class gdb_apit const std::string &address = "", const std::string &pointee = "", const std::string &character = "", - const optionalt &string = nullopt, + const optionalt &string = {}, const bool valid = false) : address(address), pointee(pointee), diff --git a/src/solvers/flattening/boolbv.h b/src/solvers/flattening/boolbv.h index 3670171fe8b..3575010f3ed 100644 --- a/src/solvers/flattening/boolbv.h +++ b/src/solvers/flattening/boolbv.h @@ -59,7 +59,7 @@ class boolbvt:public arrayst virtual const bvt &convert_bv( // check cache const exprt &expr, - const optionalt expected_width = nullopt); + const optionalt expected_width = {}); virtual bvt convert_bitvector(const exprt &expr); // no cache diff --git a/src/solvers/flattening/boolbv_quantifier.cpp b/src/solvers/flattening/boolbv_quantifier.cpp index fb5e201aa3e..2df5b755990 100644 --- a/src/solvers/flattening/boolbv_quantifier.cpp +++ b/src/solvers/flattening/boolbv_quantifier.cpp @@ -193,13 +193,13 @@ static optionalt eager_quantifier_instantiation( get_quantifier_var_max(var_expr, where_simplified); if(!min_i.has_value() || !max_i.has_value()) - return nullopt; + return {}; mp_integer lb = numeric_cast_v(min_i.value()); mp_integer ub = numeric_cast_v(max_i.value()); if(lb > ub) - return nullopt; + return {}; auto expr_simplified = quantifier_exprt(expr.id(), expr.variables(), where_simplified); diff --git a/src/util/edit_distance.cpp b/src/util/edit_distance.cpp index 5c634b7873f..b2361ed6ba8 100644 --- a/src/util/edit_distance.cpp +++ b/src/util/edit_distance.cpp @@ -69,5 +69,5 @@ levenshtein_automatont::get_edit_distance(const std::string &string) const return distance; } } - return nullopt; + return {}; } diff --git a/src/util/optional_utils.h b/src/util/optional_utils.h index beb20d7dc0d..6ddbd1cba51 100644 --- a/src/util/optional_utils.h +++ b/src/util/optional_utils.h @@ -22,7 +22,7 @@ auto optional_lookup(const map_like_collectiont &map, const keyt &key) { return it->second; } - return nullopt; + return {}; } #endif // CPROVER_UTIL_OPTIONAL_UTILS_H diff --git a/src/util/string2int.cpp b/src/util/string2int.cpp index 583f38eaa69..6cf4bf75b12 100644 --- a/src/util/string2int.cpp +++ b/src/util/string2int.cpp @@ -16,14 +16,14 @@ Author: Michael Tautschnig, michael.tautschnig@cs.ox.ac.uk unsigned safe_string2unsigned(const std::string &str, int base) { auto converted = string2optional(str, base); - CHECK_RETURN(converted != nullopt); + CHECK_RETURN(converted.has_value()); return *converted; } std::size_t safe_string2size_t(const std::string &str, int base) { auto converted = string2optional(str, base); - CHECK_RETURN(converted != nullopt); + CHECK_RETURN(converted.has_value()); return *converted; } diff --git a/unit/util/string2int.cpp b/unit/util/string2int.cpp index a7c8d846bcb..fd8ee3853f9 100644 --- a/unit/util/string2int.cpp +++ b/unit/util/string2int.cpp @@ -22,8 +22,8 @@ TEST_CASE( "optionally converting invalid string to integer should return nullopt", "[core][util][string2int]") { - REQUIRE(string2optional_int("thirteen") == nullopt); - REQUIRE(string2optional_int("c0fefe") == nullopt); + REQUIRE(!string2optional_int("thirteen").has_value()); + REQUIRE(!string2optional_int("c0fefe").has_value()); } TEST_CASE( @@ -31,8 +31,8 @@ TEST_CASE( "[core][util][string2int]") { REQUIRE( - string2optional_int("0xfffffffffffffffffffffffffffffffffffffffffff", 16) == - nullopt); + !string2optional_int("0xfffffffffffffffffffffffffffffffffffffffffff", 16) + .has_value()); } TEST_CASE( @@ -47,18 +47,18 @@ TEST_CASE( "optionally converting invalid string to unsigned should return nullopt", "[core][util][string2int]") { - REQUIRE(string2optional_unsigned("thirteen") == nullopt); - REQUIRE(string2optional_unsigned("c0fefe") == nullopt); + REQUIRE(!string2optional_unsigned("thirteen").has_value()); + REQUIRE(!string2optional_unsigned("c0fefe").has_value()); } TEST_CASE( "optionally converting string out of range to unsigned should return nullopt", "[core][util][string2int]") { - REQUIRE( - string2optional_unsigned( - "0xfffffffffffffffffffffffffffffffffffffffffff", 16) == nullopt); - REQUIRE(string2optional_unsigned("-5") == nullopt); + REQUIRE(!string2optional_unsigned( + "0xfffffffffffffffffffffffffffffffffffffffffff", 16) + .has_value()); + REQUIRE(!string2optional_unsigned("-5").has_value()); } TEST_CASE( @@ -73,8 +73,8 @@ TEST_CASE( "optionally converting invalid string to size_t should return nullopt", "[core][util][string2int]") { - REQUIRE(string2optional_size_t("thirteen") == nullopt); - REQUIRE(string2optional_size_t("c0fefe") == nullopt); + REQUIRE(!string2optional_size_t("thirteen").has_value()); + REQUIRE(!string2optional_size_t("c0fefe").has_value()); } TEST_CASE( @@ -82,7 +82,7 @@ TEST_CASE( "[core][util][string2int]") { REQUIRE( - string2optional_size_t( - "0xfffffffffffffffffffffffffffffffffffffffffff", 16) == nullopt); - REQUIRE(string2optional_size_t("-5") == nullopt); + !string2optional_size_t("0xfffffffffffffffffffffffffffffffffffffffffff", 16) + .has_value()); + REQUIRE(!string2optional_size_t("-5").has_value()); }