[pulse] Model std::__optional_storage_base::has_value

Summary: Model ` std::__optional_storage_base::has_value` as this is what we see in clang AST when translating  `std::optional::has_value` for libc++. For libstdc++, we get `std::optional::has_value` as expected.

Reviewed By: skcho, jvillard

Differential Revision: D25585543

fbshipit-source-id: b8d9d2902
master
Daiva Naudziuniene 4 years ago committed by Facebook GitHub Bot
parent b4b75c4ffb
commit 0c6eedc835

@ -1075,14 +1075,14 @@ module ProcNameDispatcher = struct
~desc:"std::optional::optional(std::optional<Value> arg)" ~desc:"std::optional::optional(std::optional<Value> arg)"
; -"std" &:: "optional" &:: "optional" $ capt_arg_payload $+ capt_arg_payload ; -"std" &:: "optional" &:: "optional" $ capt_arg_payload $+ capt_arg_payload
$+...$--> Optional.assign_value ~desc:"std::optional::optional(Value arg)" $+...$--> Optional.assign_value ~desc:"std::optional::optional(Value arg)"
; -"std" &:: "optional" &:: "operator=" <>$ capt_arg_payload ; -"std" &:: "optional" &:: "operator=" $ capt_arg_payload
$+ any_arg_of_typ (-"std" &:: "nullopt_t") $+ any_arg_of_typ (-"std" &:: "nullopt_t")
$--> Optional.assign_none ~desc:"std::optional::operator=(None)" $--> Optional.assign_none ~desc:"std::optional::operator=(None)"
; -"std" &:: "optional" &:: "operator=" <>$ capt_arg_payload ; -"std" &:: "optional" &:: "operator=" $ capt_arg_payload
$+ capt_arg_payload_of_typ (-"std" &:: "optional") $+ capt_arg_payload_of_typ (-"std" &:: "optional")
$--> Optional.assign_optional_value $--> Optional.assign_optional_value
~desc:"std::optional::operator=(std::optional<Value> arg)" ~desc:"std::optional::operator=(std::optional<Value> arg)"
; -"std" &:: "optional" &:: "operator=" <>$ capt_arg_payload $+ capt_arg_payload ; -"std" &:: "optional" &:: "operator=" $ capt_arg_payload $+ capt_arg_payload
$+...$--> Optional.assign_value ~desc:"std::optional::operator=(Value arg)" $+...$--> Optional.assign_value ~desc:"std::optional::operator=(Value arg)"
; -"std" &:: "optional" &:: "emplace<>" $ capt_arg_payload ; -"std" &:: "optional" &:: "emplace<>" $ capt_arg_payload
$+...$--> Optional.emplace ~desc:"std::optional::emplace()" $+...$--> Optional.emplace ~desc:"std::optional::emplace()"
@ -1090,6 +1090,8 @@ module ProcNameDispatcher = struct
$+...$--> Optional.emplace ~desc:"std::optional::emplace()" $+...$--> Optional.emplace ~desc:"std::optional::emplace()"
; -"std" &:: "optional" &:: "has_value" <>$ capt_arg_payload ; -"std" &:: "optional" &:: "has_value" <>$ capt_arg_payload
$+...$--> Optional.has_value ~desc:"std::optional::has_value()" $+...$--> Optional.has_value ~desc:"std::optional::has_value()"
; -"std" &:: "__optional_storage_base" &:: "has_value" $ capt_arg_payload
$+...$--> Optional.has_value ~desc:"std::optional::has_value()"
; -"std" &:: "optional" &:: "operator_bool" <>$ capt_arg_payload ; -"std" &:: "optional" &:: "operator_bool" <>$ capt_arg_payload
$+...$--> Optional.has_value ~desc:"std::optional::operator_bool()" $+...$--> Optional.has_value ~desc:"std::optional::operator_bool()"
; -"std" &:: "optional" &:: "reset" <>$ capt_arg_payload ; -"std" &:: "optional" &:: "reset" <>$ capt_arg_payload

@ -238,6 +238,14 @@ int std_none_check_ok() {
return -1; return -1;
} }
int std_none_check_has_value_ok() {
std::optional<int> foo{std::nullopt};
if (foo.has_value()) {
return foo.value();
}
return -1;
}
int std_none_no_check_bad() { int std_none_no_check_bad() {
std::optional<int> foo{std::nullopt}; std::optional<int> foo{std::nullopt};
return foo.value(); return foo.value();
@ -305,6 +313,7 @@ int std_value_or_check_value_ok_FP() {
} }
return -1; return -1;
} }
struct Container final { struct Container final {
std::vector<int> _vec; std::vector<int> _vec;
@ -324,3 +333,19 @@ struct Container final {
return -1; return -1;
} }
}; };
std::optional<std::string> might_return_none(bool b, std::string x) {
if (b) {
return std::nullopt;
}
return x;
}
std::string reassing_non_empty_ok(const std::string& x) {
std::optional<std::string> foo = might_return_none(true, x);
if (!foo.has_value()) {
foo = x;
}
return foo.value();
}

Loading…
Cancel
Save