Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ class NullableValue : public bsl::optional<T> {
const T &value() const &;
T &value() &;

constexpr T &makeValue();

template <typename U>
constexpr T &makeValue(U&& v);

template <typename... ARGS>
constexpr T &makeValueInplace(ARGS &&... args);

// 'operator bool' is inherited from bsl::optional

constexpr bool isNull() const noexcept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,20 @@ void nullable_value_after_swap(BloombergLP::bdlb::NullableValue<int> &opt1, Bloo
}
}

void nullable_value_make_value(BloombergLP::bdlb::NullableValue<int> &opt1, BloombergLP::bdlb::NullableValue<int> &opt2) {
if (opt1.isNull()) {
opt1.makeValue(42);
}

opt1.value();

if (opt2.isNull()) {
opt2.makeValueInplace(42);
}

opt2.value();
}

template <typename T>
void function_template_without_user(const absl::optional<T> &opt) {
opt.value(); // no-warning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,20 @@ auto buildTransferMatchSwitch() {
isOptionalMemberCallWithNameMatcher(hasName("isNull")),
transferOptionalIsNullCall)

// NullableValue::makeValue, NullableValue::makeValueInplace
// Only NullableValue has these methods, but this
// will also pass for other types
.CaseOfCFGStmt<CXXMemberCallExpr>(
isOptionalMemberCallWithNameMatcher(
hasAnyName("makeValue", "makeValueInplace")),
[](const CXXMemberCallExpr *E, const MatchFinder::MatchResult &,
LatticeTransferState &State) {
if (RecordStorageLocation *Loc =
getImplicitObjectLocation(*E, State.Env)) {
setHasValue(*Loc, State.Env.getBoolLiteralValue(true), State.Env);
}
})

// optional::emplace
.CaseOfCFGStmt<CXXMemberCallExpr>(
isOptionalMemberCallWithNameMatcher(hasName("emplace")),
Expand Down
Loading