← Back to Pull requests

Implement LWG-4072 `std::optional` comparisons: constrain harder #6424

Closed
unknown closed this pull request without merging on Oct 18, 2026 19:46 UTC
View on GitHub
unknown unknown commented on Aug 30, 2026 15:16 UTC
Author

Towards #4522 and #5272.

Previously, we've been constraining optional's comparison operators in ways quite similar to WG21-P2944R3, so I believe we've actually partially implemented that paper long time ago.

  • For operators comparing optional and other types, constraints were added in C++17 mode before the initial open-sourcing commit (219514876ea86491de191ceaa88632616bbc0f19).

  • For operators comparing two optional values, constraints were added since C++20 mode in #1937.
  • Note that there's currently inconsistency in C++17 mode, which doesn't seem to be a good thing. It's probably better to consistently constrain all these operators either in all modes or only since C++26 mode. As other implementations, especially libc++, constrain them in old modes, I guess we should constrain them in C++17 as indicated by WG21-P2944R3 patched by LWG-4072.

    There are three major parts of changes.

    1. First, this PR modifies the _Implicitly_convertible_to concept to handle return types whose prvalues can be converted to bool but xvalues can't. Such classes are implementable due C++23 WG21-P0847R7 "Deducing this" as patched by CWG-2813. This part also affects comparisons for move_iterator and reverse_iterator.
    2. Second, this PR uses the _Enable_meow helper alias templates for operators comparing two optionals instead of require-clauses. This makes the implementation strategy less clear but is necessary for C++17 mode.
    3. Third, this PR introduces the _Enable_self_if_not_optional helper alias templates to exactly implement LWG-4072. This approach seems somehow unconventional, but I think it's almost the cleanest way to reusing the existing _Enable_meow helpers.

    Test cases for the modification to _Implicitly_convertible_to is currently not enabled for MSVC because MSVC hasn't implemented CWG-2813 yet. See DevCom-10817483.

    Diff: 234 lines (+175 / -59) across 2 files Reviewer: amlel-el-mahrouss Review duration: 70829m
    All Vouch review confidence checks passed
    Residual risk 0.15 = Change Risk (0.37) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 234 lines diff across 2 files
    0.37
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.327
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #6424"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 37.1% (MEDIUM) · Higher = larger blast radius
    37.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 14.7% · Safe to merge
    14.7%
    Repository