Commit Graph

8 Commits

Author SHA1 Message Date
Mateusz Pusz 01bf044919 fix: resolve MSVC C2666 on safe_int<T> × safe_int<U> via Hidden Friend Injection
Adds heterogeneous arithmetic operators (+ - * / %) to `detail::safe_int_binary_ops`,
following the same idiom already used for `==` and `<=>`.  The non-template homogeneous
inline-friends inside `safe_int<T>` keep winning same-T calls; the new template friends
in the base unambiguously handle the T != U calls without changing the converting-ctor
semantics.  Resolves the ambiguity that triggered C2666 on `safe_int<int> + safe_int<long>`
when `int` and `long` have equal width (Windows).

Also:
  * `mul_overflows<T>` now gates on `integer_rep_width_v<int128_t>` so MSVC's synthetic
    `double_width_int<int64_t>` counts as a usable wider type for the overflow check.
  * Replace the platform-dependent `safe_int<long>` widening test with a portable
    `long long` variant — on Windows the original test's RHS
    `static_cast<long>(INT_MAX) + 1L` is itself constexpr-invalid 32-bit overflow.
  * Add convertibility coverage tests for `safe_int<T> op raw_U` mixing short / int /
    long / uint8_t to lock down that the `safe_int op integral` overload wins by exact
    match over the converting ctor on every platform.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-24 19:31:09 +02:00
Mateusz Pusz 70eadc49ad feat: cross sign and cross error policy comparisons added for safe_int
Co-authored-by: Copilot <copilot@github.com>
2026-04-27 23:27:31 +02:00
Mateusz Pusz eb5dfa62df feat: int128 types are now universally treated as integral on all platforms and safe_int depends on it
Co-authored-by: Copilot <copilot@github.com>
2026-04-27 13:00:04 +02:00
Mateusz Pusz 659738044a feat: safe_int implicit conversions improved and refactored the operators + widening for scaling now preserves sign
Co-authored-by: Copilot <copilot@github.com>
2026-04-26 16:03:09 +02:00
Mateusz Pusz f080c80317 style: pre-commit 2026-04-12 14:15:13 +02:00
Mateusz Pusz ad77bcc106 feat: safe_int::operator T made explicit 2026-04-12 14:12:15 +02:00
Mateusz Pusz 4b6eb91a61 fix: safe_int_test fixed for freestanding 2026-04-11 20:57:16 +02:00
Mateusz Pusz 12300bcd23 feat: safe_int and blog article about it added 2026-04-11 20:30:28 +02:00