Skip to content

<variant>: Use a simpler three-way comparator for variant - #6447

Open
A. Jiang (frederick-vs-ja) wants to merge 2 commits into
microsoft:mainfrom
frederick-vs-ja:simpler-cmp-3way-variant
Open

<variant>: Use a simpler three-way comparator for variant#6447
A. Jiang (frederick-vs-ja) wants to merge 2 commits into
microsoft:mainfrom
frederick-vs-ja:simpler-cmp-3way-variant

Conversation

@frederick-vs-ja

@frederick-vs-ja A. Jiang (frederick-vs-ja) commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Towards #6156.

Some occurrences of constexpr in the related libcxx test are bogus, and I opened LLVM-222837 to remove them. But it's revealed that MSVC STL's use of compare_three_way (using deduced return type in its operator()) can cause more things to be instantiated and detected. It seems better to reduce instantiations a bit (at least in the exception specification).

This PR introduces a simplified version of compare_three_way using explicit return type, which should be able to stop undesired instantiation and reduce constraint checks.


Now LLVM-222837 has been merged, so this PR also mirrors it to MSVC STL's test file. I think it's still valuable to use the new simpler comparator even when there's no bogus constexpr or inline.

Copilot AI balanced review requested due to automatic review settings September 11, 2026 03:53
@frederick-vs-ja
A. Jiang (frederick-vs-ja) requested a review from a team as a code owner September 11, 2026 03:53
@github-project-automation github-project-automation Bot moved this to Initial Review in STL Code Reviews Sep 11, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused implementation preserves comparison semantics while avoiding the undesired return-type instantiation.

Pull request overview

Simplifies variant three-way comparison to reduce unnecessary template instantiation and resolves related Clang test failures.

Changes:

  • Adds an internal comparator with an explicit return type.
  • Updates variant::operator<=> to use the simpler comparator.
  • Removes obsolete Clang warning workarounds and expected failures.
File summaries
File Description
stl/inc/variant Implements and uses the simplified comparator.
tests/std/tests/P0088R3_variant/test.cpp Removes obsolete diagnostic suppression.
tests/libcxx/expected_results.txt Removes the now-passing libc++ test entry.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/std/tests/P0088R3_variant/test.cpp Outdated
Copilot AI review requested due to automatic review settings September 11, 2026 11:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused implementation and test updates are consistent and preserve comparison semantics while reducing instantiation.

Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) added the bug Something isn't working label Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Initial Review

Development

Successfully merging this pull request may close these issues.

3 participants