This is an archive of the discontinued LLVM Phabricator instance.

[ADT] Factor out in_place_t and expose in Optional ctor
ClosedPublic

Authored by scott.linder on Apr 16 2021, 11:32 AM.

Diff Detail

Event Timeline

scott.linder created this revision.Apr 16 2021, 11:32 AM
scott.linder requested review of this revision.Apr 16 2021, 11:32 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptApr 16 2021, 11:32 AM

This usage doesn't seem to quite match the standard - which provides an existing instance of in_place_t for callers to use:

std::optional<std::string> o4(std::in_place, {'a', 'b', 'c'});

(to quote https://en.cppreference.com/w/cpp/utility/optional/optional )

Probably good to match this sort of behavior.

llvm/unittests/ADT/OptionalTest.cpp
227

Could write this as: return std::tie(LHS.x, LHS.y) == std::tie(RHS.x, RHS.y); which I think is a bit tidier/easier to generalize to other comparisons, etc.

This usage doesn't seem to quite match the standard - which provides an existing instance of in_place_t for callers to use:

std::optional<std::string> o4(std::in_place, {'a', 'b', 'c'});

(to quote https://en.cppreference.com/w/cpp/utility/optional/optional )

Probably good to match this sort of behavior.

My understanding is that the C++17 inline constexpr is what makes that generally "safe" wrt. ODR, but I'm not actually sure that it come up in practice (i.e. I don't suspect we will ever actually cause this thing to have an address).

Maybe I can add the variable with a note about not doing anything with it that could cause it to violate ODR? I.e. don't take its address (and probably other thing I need to refresh my memory on)

llvm/unittests/ADT/OptionalTest.cpp
227

Will do, thank you!

This usage doesn't seem to quite match the standard - which provides an existing instance of in_place_t for callers to use:

std::optional<std::string> o4(std::in_place, {'a', 'b', 'c'});

(to quote https://en.cppreference.com/w/cpp/utility/optional/optional )

Probably good to match this sort of behavior.

My understanding is that the C++17 inline constexpr is what makes that generally "safe" wrt. ODR, but I'm not actually sure that it come up in practice (i.e. I don't suspect we will ever actually cause this thing to have an address).

Maybe I can add the variable with a note about not doing anything with it that could cause it to violate ODR? I.e. don't take its address (and probably other thing I need to refresh my memory on)

I imagine whatever we do for llvm::None would be fine for llvm::inplace too.

Add constexpr convenience variables

dblaikie accepted this revision.May 14 2021, 3:47 PM

Looks good, thanks! Probably skip the other two in_place_* until we have a use for them.

llvm/include/llvm/ADT/STLForwardCompat.h
53–73

I'd probably skip these until we have a use for them?

This revision is now accepted and ready to land.May 14 2021, 3:47 PM
This revision was landed with ongoing or failed builds.May 17 2021, 3:27 PM
This revision was automatically updated to reflect the committed changes.