Skip to content

Constrain maybe::assign to types with has_value()/value()#7

Open
HFTrader wants to merge 2 commits intoCons-Cat:mainfrom
HFTrader:fix-maybe-assign
Open

Constrain maybe::assign to types with has_value()/value()#7
HFTrader wants to merge 2 commits intoCons-Cat:mainfrom
HFTrader:fix-maybe-assign

Conversation

@HFTrader
Copy link
Copy Markdown

@HFTrader HFTrader commented Mar 2, 2026

Summary

Four bugs found via clang-tidy 23 (trunk) analysis:

1. Constrain maybe::assign template (commit 1)

2. Fix is_common_comparison_category concept (commit 2)

  • Changed && to || — the concept was always false since no type can simultaneously be strong_ordering, weak_ordering, AND partial_ordering
  • This made lexicographical_compare_three_way uncallable

3. Fix maybe_value_storage::assign self-assignment (commit 2)

  • hard_reset() destroyed m_storage before the assignment read from the maybe parameter
  • If maybe aliased m_storage, this was use-after-destroy
  • Added __builtin_addressof guard

4. Fix divide_by calling wrong functions (commit 2)

  • Wrap/saturate branches called wrap_mul/sat_mul instead of wrap_div/sat_div
  • Author-acknowledged with "TODO: This looks wrong"

Build verification

  • Clean 594/594 build with Clang 23.0.0git (llvm-project main, d7eec97bd83f)
  • PCH disabled (-DCAT_PCH=OFF)

Fixes #5, #6

HFTrader added 2 commits March 2, 2026 17:24
The unconstrained template accepted any type including plain int,
causing compilation errors when assign() called .has_value() on
non-maybe types. Add requires clause to all three storage variants.

Fixes Cons-Cat#5, Cons-Cat#6
1. is_common_comparison_category: concept used && where || was needed,
   making it always false and lexicographical_compare_three_way uncallable

2. maybe_value_storage::assign: hard_reset() destroyed m_storage before
   reading from the maybe parameter, causing use-after-destroy on
   self-assignment

3. divide_by: wrap and saturate branches called wrap_mul/sat_mul instead
   of wrap_div/sat_div (author-acknowledged TODO)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error while building with clang-21

1 participant