This is an archive of the discontinued LLVM Phabricator instance.

[libc][NFC] add arrow operator to optional
ClosedPublic

Authored by michaelrj on Aug 10 2022, 12:00 PM.

Diff Detail

Event Timeline

michaelrj created this revision.Aug 10 2022, 12:00 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptAug 10 2022, 12:00 PM
michaelrj requested review of this revision.Aug 10 2022, 12:00 PM
sivachandra accepted this revision.Aug 10 2022, 12:13 PM

Good to go after adding smoke tests.

libc/src/__support/CPP/optional.h
78

For consistency with operator*, make it const & and add a non-const & flavor also.

This revision is now accepted and ready to land.Aug 10 2022, 12:13 PM
michaelrj updated this revision to Diff 451617.Aug 10 2022, 1:27 PM

add tests and non-const version

libc/src/__support/CPP/optional.h
78

If I change this to be a reference, then to use the -> operator the contained object must also support the -> operator. Here's the error message when I try it:
error: member reference type 'const __llvm_libc::cpp::StringView' is not a pointer

I think it's more useful to leave it as is, so that it works as expected without additional effort.

sivachandra accepted this revision.Aug 10 2022, 1:50 PM
This revision was landed with ongoing or failed builds.Aug 10 2022, 2:47 PM
This revision was automatically updated to reflect the committed changes.