mirror of
https://github.com/1dot13/source.git
synced 2026-08-12 14:10:23 +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
@@ -6934,22 +6934,22 @@ void HandlePlayerTeamQuotesWhenEnteringSector( INT16 sSectorX, INT16 sSectorY, I
|
||||
ENTER_SECTOR_PLAYER_QUOTE PlayerSectorDescQuote[ NUM_VALID_SECTORS ] =
|
||||
{
|
||||
//SEC_H9-0
|
||||
{ SECTOR( gGameUBOptions.SectorGuardPostX, gGameUBOptions.SectorGuardPostY ), gGameUBOptions.SectorGuardPostZ, QUOTE_HATED_1_ON_TEAM },
|
||||
{ SECTOR( gGameUBOptions.SectorGuardPostX, gGameUBOptions.SectorGuardPostY ), static_cast<INT8>(gGameUBOptions.SectorGuardPostZ), QUOTE_HATED_1_ON_TEAM },
|
||||
|
||||
//SEC_I9-0
|
||||
{ SECTOR( gGameUBOptions.I9SectorPlayerQuoteX, gGameUBOptions.I9SectorPlayerQuoteY ), gGameUBOptions.I9SectorPlayerQuoteZ, QUOTE_LEARNED_TO_HATE_MERC_ON_TEAM },
|
||||
{ SECTOR( gGameUBOptions.I9SectorPlayerQuoteX, gGameUBOptions.I9SectorPlayerQuoteY ), static_cast<INT8>(gGameUBOptions.I9SectorPlayerQuoteZ), QUOTE_LEARNED_TO_HATE_MERC_ON_TEAM },
|
||||
|
||||
//SEC_H10-0
|
||||
{ SECTOR( gGameUBOptions.H10SectorPlayerQuoteX, gGameUBOptions.H10SectorPlayerQuoteY ), gGameUBOptions.H10SectorPlayerQuoteZ, QUOTE_LEARNED_TO_HATE_MERC_ON_TEAM },
|
||||
{ SECTOR( gGameUBOptions.H10SectorPlayerQuoteX, gGameUBOptions.H10SectorPlayerQuoteY ), static_cast<INT8>(gGameUBOptions.H10SectorPlayerQuoteZ), QUOTE_LEARNED_TO_HATE_MERC_ON_TEAM },
|
||||
|
||||
//SEC_I10-0
|
||||
{ SECTOR( gGameUBOptions.FristSectorTownX, gGameUBOptions.FristSectorTownY ), gGameUBOptions.FristSectorTownZ, QUOTE_HATED_2_ON_TEAM },
|
||||
{ SECTOR( gGameUBOptions.FristSectorTownX, gGameUBOptions.FristSectorTownY ), static_cast<INT8>(gGameUBOptions.FristSectorTownZ), QUOTE_HATED_2_ON_TEAM },
|
||||
|
||||
//SEC_J13-0
|
||||
{ SECTOR( gGameUBOptions.SectorFanX, gGameUBOptions.SectorFanY ), gGameUBOptions.SectorFanZ, QUOTE_ENTER_SECTOR_WITH_FAN_1 },
|
||||
{ SECTOR( gGameUBOptions.SectorFanX, gGameUBOptions.SectorFanY ), static_cast<INT8>(gGameUBOptions.SectorFanZ), QUOTE_ENTER_SECTOR_WITH_FAN_1 },
|
||||
|
||||
//SEC_J14-1
|
||||
{ SECTOR( gGameUBOptions.SectorGuardPostX, gGameUBOptions.SectorGuardPostY ), gGameUBOptions.ExitForFanToPowerGenSectorZ, 0 },
|
||||
{ SECTOR( gGameUBOptions.SectorGuardPostX, gGameUBOptions.SectorGuardPostY ), static_cast<INT8>(gGameUBOptions.ExitForFanToPowerGenSectorZ), 0 },
|
||||
};
|
||||
|
||||
//loop through all the sectors that have the quotes
|
||||
|
||||
Reference in New Issue
Block a user