This is an archive of the discontinued LLVM Phabricator instance.

Don't use Optional::getPointer (NFC)
ClosedPublic

Authored by kazu on Nov 21 2022, 6:03 PM.

Details

Summary

Since std::optional does not offer getPointer(), this patch replaces
X.getPointer() with &*X to make the migration from llvm::Optional to
std::optional easier.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Diff Detail

Event Timeline

kazu created this revision.Nov 21 2022, 6:03 PM
kazu requested review of this revision.Nov 21 2022, 6:03 PM
Herald added projects: Restricted Project, Restricted Project, Restricted Project. · View Herald TranscriptNov 21 2022, 6:03 PM
MaskRay accepted this revision.Nov 21 2022, 6:42 PM

getPointer asserts hasValue, so &* is safe,

This revision is now accepted and ready to land.Nov 21 2022, 6:42 PM
kazu added a comment.Nov 21 2022, 7:02 PM

Thanks for the review!

getPointer asserts hasValue, so &* is safe,

Yes. operator* also asserts hasVal via value(), so we maintain the same level of safety.

This revision was landed with ongoing or failed builds.Nov 21 2022, 7:03 PM
This revision was automatically updated to reflect the committed changes.