Skip to content

Remove unqualified use of nullopt [blocks: #6749] #6756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ansi-c/expr2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4031,7 +4031,7 @@ optionalt<std::string> 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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/goto-analyzer/unreachable_instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static optionalt<std::string>
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()),
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/memory-analyzer/gdb_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class gdb_apit
const std::string &address = "",
const std::string &pointee = "",
const std::string &character = "",
const optionalt<std::string> &string = nullopt,
const optionalt<std::string> &string = {},
const bool valid = false)
: address(address),
pointee(pointee),
Expand Down
2 changes: 1 addition & 1 deletion src/solvers/flattening/boolbv.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class boolbvt:public arrayst

virtual const bvt &convert_bv( // check cache
const exprt &expr,
const optionalt<std::size_t> expected_width = nullopt);
const optionalt<std::size_t> expected_width = {});

virtual bvt convert_bitvector(const exprt &expr); // no cache

Expand Down
4 changes: 2 additions & 2 deletions src/solvers/flattening/boolbv_quantifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@ static optionalt<exprt> 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<mp_integer>(min_i.value());
mp_integer ub = numeric_cast_v<mp_integer>(max_i.value());

if(lb > ub)
return nullopt;
return {};

auto expr_simplified =
quantifier_exprt(expr.id(), expr.variables(), where_simplified);
Expand Down
2 changes: 1 addition & 1 deletion src/util/edit_distance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ levenshtein_automatont::get_edit_distance(const std::string &string) const
return distance;
}
}
return nullopt;
return {};
}
2 changes: 1 addition & 1 deletion src/util/optional_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/util/string2int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ Author: Michael Tautschnig, [email protected]
unsigned safe_string2unsigned(const std::string &str, int base)
{
auto converted = string2optional<unsigned>(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<std::size_t>(str, base);
CHECK_RETURN(converted != nullopt);
CHECK_RETURN(converted.has_value());
return *converted;
}

Expand Down
30 changes: 15 additions & 15 deletions unit/util/string2int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ 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(
"optionally converting string out of range to integer should return nullopt",
"[core][util][string2int]")
{
REQUIRE(
string2optional_int("0xfffffffffffffffffffffffffffffffffffffffffff", 16) ==
nullopt);
!string2optional_int("0xfffffffffffffffffffffffffffffffffffffffffff", 16)
.has_value());
}

TEST_CASE(
Expand All @@ -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(
Expand All @@ -73,16 +73,16 @@ 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(
"optionally converting string out of range to size_t should return nullopt",
"[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());
}