Skip to content

Commit 76897ae

Browse files
authored
Merge pull request #6756 from tautschnig/cleanup/nullopt
Remove unqualified use of nullopt [blocks: #6749]
2 parents 8327886 + 7491954 commit 76897ae

File tree

9 files changed

+26
-26
lines changed

9 files changed

+26
-26
lines changed

src/ansi-c/expr2c.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4025,7 +4025,7 @@ optionalt<std::string> expr2ct::convert_function(const exprt &src)
40254025

40264026
const auto function_entry = function_names.find(src.id());
40274027
if(function_entry == function_names.end())
4028-
return nullopt;
4028+
return {};
40294029

40304030
return convert_function(src, function_entry->second);
40314031
}

src/goto-analyzer/unreachable_instructions.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static optionalt<std::string>
104104
file_name_string_opt(const source_locationt &source_location)
105105
{
106106
if(source_location.get_file().empty())
107-
return nullopt;
107+
return {};
108108

109109
return concat_dir_file(
110110
id2string(source_location.get_working_directory()),
@@ -255,7 +255,7 @@ line_string_opt(const source_locationt &source_location)
255255
const irep_idt &line = source_location.get_line();
256256

257257
if(line.empty())
258-
return nullopt;
258+
return {};
259259
else
260260
return id2string(line);
261261
}

src/memory-analyzer/gdb_api.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class gdb_apit
8080
const std::string &address = "",
8181
const std::string &pointee = "",
8282
const std::string &character = "",
83-
const optionalt<std::string> &string = nullopt,
83+
const optionalt<std::string> &string = {},
8484
const bool valid = false)
8585
: address(address),
8686
pointee(pointee),

src/solvers/flattening/boolbv.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class boolbvt:public arrayst
6161

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

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

src/solvers/flattening/boolbv_quantifier.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,13 @@ static optionalt<exprt> eager_quantifier_instantiation(
193193
get_quantifier_var_max(var_expr, where_simplified);
194194

195195
if(!min_i.has_value() || !max_i.has_value())
196-
return nullopt;
196+
return {};
197197

198198
mp_integer lb = numeric_cast_v<mp_integer>(min_i.value());
199199
mp_integer ub = numeric_cast_v<mp_integer>(max_i.value());
200200

201201
if(lb > ub)
202-
return nullopt;
202+
return {};
203203

204204
auto expr_simplified =
205205
quantifier_exprt(expr.id(), expr.variables(), where_simplified);

src/util/edit_distance.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,5 @@ levenshtein_automatont::get_edit_distance(const std::string &string) const
6969
return distance;
7070
}
7171
}
72-
return nullopt;
72+
return {};
7373
}

src/util/optional_utils.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ auto optional_lookup(const map_like_collectiont &map, const keyt &key)
2222
{
2323
return it->second;
2424
}
25-
return nullopt;
25+
return {};
2626
}
2727

2828
#endif // CPROVER_UTIL_OPTIONAL_UTILS_H

src/util/string2int.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ Author: Michael Tautschnig, [email protected]
1616
unsigned safe_string2unsigned(const std::string &str, int base)
1717
{
1818
auto converted = string2optional<unsigned>(str, base);
19-
CHECK_RETURN(converted != nullopt);
19+
CHECK_RETURN(converted.has_value());
2020
return *converted;
2121
}
2222

2323
std::size_t safe_string2size_t(const std::string &str, int base)
2424
{
2525
auto converted = string2optional<std::size_t>(str, base);
26-
CHECK_RETURN(converted != nullopt);
26+
CHECK_RETURN(converted.has_value());
2727
return *converted;
2828
}
2929

unit/util/string2int.cpp

+15-15
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ TEST_CASE(
2222
"optionally converting invalid string to integer should return nullopt",
2323
"[core][util][string2int]")
2424
{
25-
REQUIRE(string2optional_int("thirteen") == nullopt);
26-
REQUIRE(string2optional_int("c0fefe") == nullopt);
25+
REQUIRE(!string2optional_int("thirteen").has_value());
26+
REQUIRE(!string2optional_int("c0fefe").has_value());
2727
}
2828

2929
TEST_CASE(
3030
"optionally converting string out of range to integer should return nullopt",
3131
"[core][util][string2int]")
3232
{
3333
REQUIRE(
34-
string2optional_int("0xfffffffffffffffffffffffffffffffffffffffffff", 16) ==
35-
nullopt);
34+
!string2optional_int("0xfffffffffffffffffffffffffffffffffffffffffff", 16)
35+
.has_value());
3636
}
3737

3838
TEST_CASE(
@@ -47,18 +47,18 @@ TEST_CASE(
4747
"optionally converting invalid string to unsigned should return nullopt",
4848
"[core][util][string2int]")
4949
{
50-
REQUIRE(string2optional_unsigned("thirteen") == nullopt);
51-
REQUIRE(string2optional_unsigned("c0fefe") == nullopt);
50+
REQUIRE(!string2optional_unsigned("thirteen").has_value());
51+
REQUIRE(!string2optional_unsigned("c0fefe").has_value());
5252
}
5353

5454
TEST_CASE(
5555
"optionally converting string out of range to unsigned should return nullopt",
5656
"[core][util][string2int]")
5757
{
58-
REQUIRE(
59-
string2optional_unsigned(
60-
"0xfffffffffffffffffffffffffffffffffffffffffff", 16) == nullopt);
61-
REQUIRE(string2optional_unsigned("-5") == nullopt);
58+
REQUIRE(!string2optional_unsigned(
59+
"0xfffffffffffffffffffffffffffffffffffffffffff", 16)
60+
.has_value());
61+
REQUIRE(!string2optional_unsigned("-5").has_value());
6262
}
6363

6464
TEST_CASE(
@@ -73,16 +73,16 @@ TEST_CASE(
7373
"optionally converting invalid string to size_t should return nullopt",
7474
"[core][util][string2int]")
7575
{
76-
REQUIRE(string2optional_size_t("thirteen") == nullopt);
77-
REQUIRE(string2optional_size_t("c0fefe") == nullopt);
76+
REQUIRE(!string2optional_size_t("thirteen").has_value());
77+
REQUIRE(!string2optional_size_t("c0fefe").has_value());
7878
}
7979

8080
TEST_CASE(
8181
"optionally converting string out of range to size_t should return nullopt",
8282
"[core][util][string2int]")
8383
{
8484
REQUIRE(
85-
string2optional_size_t(
86-
"0xfffffffffffffffffffffffffffffffffffffffffff", 16) == nullopt);
87-
REQUIRE(string2optional_size_t("-5") == nullopt);
85+
!string2optional_size_t("0xfffffffffffffffffffffffffffffffffffffffffff", 16)
86+
.has_value());
87+
REQUIRE(!string2optional_size_t("-5").has_value());
8888
}

0 commit comments

Comments
 (0)