Skip to content

Implement LWG-3746 optional's spaceship with U with a type derived from optional causes infinite constraint meta-recursion - #3265

Merged
Stephan T. Lavavej (StephanTLavavej) merged 5 commits into
microsoft:mainfrom
frederick-vs-ja:lwg-3746
Dec 6, 2022

Conversation

@frederick-vs-ja

Copy link
Copy Markdown
Contributor

Fixes #3225.

I found that MSVC's behavior is strange during testing (Godbolt link), so currently I haven't add the original example yet.

#include <optional>

struct derived_optional : std::optional<int> {
    friend bool operator==(const derived_optional&, const derived_optional&) = default;
    friend auto operator<=>(const derived_optional&, const derived_optional&) = default;
};

int main()
{
    derived_optional a;
    std::optional<derived_optional> b;
#ifdef LESS // If b < a is not skipped, then MSVC accepts b <=> a.
    (void) (b < a);
#endif
    (void) (b <=> a);
}

@frederick-vs-ja
A. Jiang (frederick-vs-ja) requested a review from a team as a code owner December 5, 2022 06:46
@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) added the LWG Library Working Group issue label Dec 5, 2022
Comment on lines +318 to +319
constexpr derived_optional<decltype(SmallVal)> derived1{std::optional(SmallVal)};
constexpr derived_optional<decltype(SmallVal)> derived2{std::optional(LargeVal)};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change requested: I observe that these temporaries could be constructed with braces, following our preferred modern convention. Although this test uses braces to construct temporaries elsewhere, I can't quite bring myself to reset testing for such a small issue in test code (which certainly doesn't affect correctness or test coverage).

@StephanTLavavej

Copy link
Copy Markdown
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej
Stephan T. Lavavej (StephanTLavavej) merged commit 7164d1c into microsoft:main Dec 6, 2022
@StephanTLavavej

Copy link
Copy Markdown
Member

🛸 ♾️ 🔁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LWG Library Working Group issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LWG-3746 optional's spaceship with U with a type derived from optional causes infinite constraint meta-recursion

3 participants