This is an archive of the discontinued LLVM Phabricator instance.

[ADT, Support] Move operator<< to raw_ostream.h (NFC)
ClosedPublic

Authored by kazu on Dec 4 2022, 10:05 PM.

Details

Summary

Without this patch, operator<< for Optional<T> and std::optional<T>
are in Optional.h. This means that a C++ source file must include
Optional.h even if it just needs to stream std::optional<T> and has
nothing to do with Optional<T>, which is counter-intuitive.

This patch moves the operator<< to raw_ostream.h.

As a bonus, we get to resolve a circular dependency. Optional.h no
longer needs to forward-declare raw_ostream. That is, raw_ostream.h
depends on Optional.h, not vice versa.

As a preparation for this patch, I've checked in
77609717410372e8c43aca49a268511378f58297 to forward-declare
raw_ostream in those header files that were relying on the forward
declaration of raw_ostream in Optional.h.

Diff Detail

Event Timeline

kazu created this revision.Dec 4 2022, 10:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 4 2022, 10:05 PM
kazu requested review of this revision.Dec 4 2022, 10:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 4 2022, 10:05 PM
dblaikie accepted this revision.Dec 5 2022, 2:10 PM

looks good

This revision is now accepted and ready to land.Dec 5 2022, 2:10 PM

operator<< for Optional has very few users (<3) and some seem inadvertent. It's possibly that the overload can just be deleted.

This revision was automatically updated to reflect the committed changes.