mirror of
https://github.com/1dot13/source.git
synced 2026-08-19 14:20:30 +02:00
make narrowing conversions in braced initialisers explicit
A braced initialiser does not allow a narrowing conversion unless the value
is a constant expression the compiler can prove fits. Every site here holds a
runtime value: WORLD_COLS is the global guiWorldCols, the laptop screen
coordinates are built from iScreenWidthOffset, the sector limits come from the
externalised options. MSVC accepts all of it silently; clang rejects it, and
it is ill-formed.
Nothing about the generated code changes. MSVC was already performing these
conversions; the casts only say so out loud, at the 73 places where it was
happening implicitly.
The invariant: each site is wrapped in a static_cast to the element type the
initialiser already had, and nothing else is touched. No type is widened, no
expression is reassociated, no value is clamped or checked. static_cast rather
than a C-style cast so that a later reader can grep for the narrowings, and so
that none of these can quietly become a reinterpret_cast if a type changes.
Verification:
# every changed line differs only by inserted casts and their parentheses
git show HEAD -U0 | grep '^[+-][^+-]' |
sed -E 's/static_cast<[A-Za-z0-9_]+>//g; s/[()]//g; s/^[+-]//' |
sort | uniq -c | awk '$1 % 2' # no output
git show HEAD -U0 | grep -c '^+[^+]' # 38 lines, 73 casts
ninja -C build parse # narrowing class gone: 129 -> 91 sites
ninja -C build -k 0 # Release, four applications, green
ninja -C build-debug -k 0 # Debug, four applications, green
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
committed by
majcosta
co-authored by
Claude Opus 4.8
parent
5e2982c509
commit
70b11ee120
+5
-5
@@ -250,11 +250,11 @@ BOOLEAN EnterBobbyR()
|
||||
}
|
||||
//End Dealtar's Airport Externalization.
|
||||
// an array of mouse regions for the bobbies signs. Top Left corner, bottom right corner
|
||||
UINT16 usMouseRegionPosArray[] = {BOBBIES_USED_SIGN_X, BOBBIES_USED_SIGN_Y, BOBBIES_USED_SIGN_X+BOBBIES_USED_SIGN_WIDTH, BOBBIES_USED_SIGN_Y+BOBBIES_USED_SIGN_HEIGHT,
|
||||
BOBBIES_MISC_SIGN_X, BOBBIES_MISC_SIGN_Y, BOBBIES_MISC_SIGN_X+BOBBIES_MISC_SIGN_WIDTH, BOBBIES_MISC_SIGN_Y+BOBBIES_MISC_SIGN_HEIGHT,
|
||||
BOBBIES_GUNS_SIGN_X, BOBBIES_GUNS_SIGN_Y, BOBBIES_GUNS_SIGN_X+BOBBIES_GUNS_SIGN_WIDTH, BOBBIES_GUNS_SIGN_Y+BOBBIES_GUNS_SIGN_HEIGHT,
|
||||
BOBBIES_AMMO_SIGN_X, BOBBIES_AMMO_SIGN_Y, BOBBIES_AMMO_SIGN_X+BOBBIES_AMMO_SIGN_WIDTH, BOBBIES_AMMO_SIGN_Y+BOBBIES_AMMO_SIGN_HEIGHT,
|
||||
BOBBIES_ARMOUR_SIGN_X, BOBBIES_ARMOUR_SIGN_Y, BOBBIES_ARMOUR_SIGN_X+BOBBIES_ARMOUR_SIGN_WIDTH, BOBBIES_ARMOUR_SIGN_Y+BOBBIES_ARMOUR_SIGN_HEIGHT};
|
||||
UINT16 usMouseRegionPosArray[] = {static_cast<UINT16>(BOBBIES_USED_SIGN_X), static_cast<UINT16>(BOBBIES_USED_SIGN_Y), static_cast<UINT16>(BOBBIES_USED_SIGN_X+BOBBIES_USED_SIGN_WIDTH), static_cast<UINT16>(BOBBIES_USED_SIGN_Y+BOBBIES_USED_SIGN_HEIGHT),
|
||||
static_cast<UINT16>(BOBBIES_MISC_SIGN_X), static_cast<UINT16>(BOBBIES_MISC_SIGN_Y), static_cast<UINT16>(BOBBIES_MISC_SIGN_X+BOBBIES_MISC_SIGN_WIDTH), static_cast<UINT16>(BOBBIES_MISC_SIGN_Y+BOBBIES_MISC_SIGN_HEIGHT),
|
||||
static_cast<UINT16>(BOBBIES_GUNS_SIGN_X), static_cast<UINT16>(BOBBIES_GUNS_SIGN_Y), static_cast<UINT16>(BOBBIES_GUNS_SIGN_X+BOBBIES_GUNS_SIGN_WIDTH), static_cast<UINT16>(BOBBIES_GUNS_SIGN_Y+BOBBIES_GUNS_SIGN_HEIGHT),
|
||||
static_cast<UINT16>(BOBBIES_AMMO_SIGN_X), static_cast<UINT16>(BOBBIES_AMMO_SIGN_Y), static_cast<UINT16>(BOBBIES_AMMO_SIGN_X+BOBBIES_AMMO_SIGN_WIDTH), static_cast<UINT16>(BOBBIES_AMMO_SIGN_Y+BOBBIES_AMMO_SIGN_HEIGHT),
|
||||
static_cast<UINT16>(BOBBIES_ARMOUR_SIGN_X), static_cast<UINT16>(BOBBIES_ARMOUR_SIGN_Y), static_cast<UINT16>(BOBBIES_ARMOUR_SIGN_X+BOBBIES_ARMOUR_SIGN_WIDTH), static_cast<UINT16>(BOBBIES_ARMOUR_SIGN_Y+BOBBIES_ARMOUR_SIGN_HEIGHT)};
|
||||
|
||||
InitBobbyRWoodBackground();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user