cast.hpp: integer bounds raise ~3,600 Clang warnings and reject the long long minimum when long double is 64-bit

Aperta Adatta ai principianti
#381 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@skilledwolf ci sta già lavorando.

Dal 23/11/2026.

  • #484 di @skilledwolf — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp
Ambito
backend

Direzione di ricerca

Inizia da src/alps/utilities/include/alps/utilities/cast.hpp, in checked_integer_string, dove i limiti con segno e senza segno sono costruiti da numeric_limits più 1.L e meno 1.L. Sostituiscili con potenze di due tramite std::ldexp e rendi inclusivo il controllo del limite inferiore con segno, come descritto nell'issue. Poi estendi il test di cast esistente con il minimo di long long scritto in decimale, e verifica che venga accettato e che non compaia più l'avviso di Clang.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

P2

Problem

With Clang, checked_integer_string in src/alps/utilities/include/alps/utilities/cast.hpp raises -Wimplicit-const-int-float-conversion once for every file that includes it. A full macOS build with applications and tests (AppleClang 21) prints about 3,600 of these warnings, which hides real ones.

The bounds are written as (std::numeric_limits<long long>::max)() + 1.L and (std::numeric_limits<long long>::min)() - 1.L, and the same for unsigned long long. Neither value can be stored exactly in a long double that is a plain double, as on Apple arm64 and MSVC, so it is rounded:

  • The upper bounds round to exactly 2^63 and 2^64. Those are the values the code wants, so the checks still work.
  • The lower bound rounds to −2^63, and the test is real > bound. So the input -9223372036854775808.0 is rejected as out of range, even though it is the minimum of long long. With an 80-bit long double (x86 Linux) it is accepted.

Fix

Write the bounds as exact powers of two, and make the lower test inclusive:

// signed branch
long double const limit = std::ldexp(1.0L, std::numeric_limits<long long>::digits);       // 2^63
if (!(real >= -limit && real < limit))
// unsigned branch
long double const limit = std::ldexp(1.0L, std::numeric_limits<unsigned long long>::digits);  // 2^64
if (!(real < limit))

Results do not change for any input, except that the long long minimum written as a decimal is accepted on every platform. Add a case for it to the existing cast test.

Lingua principale
C++
Stelle
32
Fork
10
Merge medio
3g 19h
PR unite (30g)
100

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ALPSim/ALPS

Tutte le issue di ALPSim/ALPS

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.