Skip to content

Commit

Permalink
Codechange: switch our codebase to C++20
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueBrain committed Jan 16, 2024
1 parent fd59393 commit bb49112
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ jobs:
matrix:
include:
- name: Clang - Debug
compiler: clang
cxxcompiler: clang++
compiler: clang-15
cxxcompiler: clang++-15
libraries: libsdl2-dev
- name: Clang - Release
compiler: clang
cxxcompiler: clang++
compiler: clang-15
cxxcompiler: clang++-15
libraries: libsdl2-dev
extra-cmake-parameters: -DCMAKE_BUILD_TYPE=RelWithDebInfo -DOPTION_USE_ASSERTS=OFF
- name: GCC - SDL2
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ set_directory_options()
include(Static)
set_static_if_needed()

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)

Expand Down
2 changes: 1 addition & 1 deletion src/blitter/32bpp_anim_sse4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static FBlitter_32bppSSE4_Anim iFBlitter_32bppSSE4_Anim;
IGNORE_UNINITIALIZED_WARNING_START
template <BlitterMode mode, Blitter_32bppSSE2::ReadMode read_mode, Blitter_32bppSSE2::BlockType bt_last, bool translucent, bool animated>
GNU_TARGET("sse4.1")
inline void Blitter_32bppSSE4_Anim::Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom)
inline void Blitter_32bppSSE4_Anim::Draw(const BlitterParams *bp, ZoomLevel zoom)
{
const byte * const remap = bp->remap;
Colour *dst_line = (Colour *) bp->dst + bp->top * bp->pitch + bp->left;
Expand Down
8 changes: 4 additions & 4 deletions src/direction_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ inline DirDiff DirDifference(Direction d0, Direction d1)
assert(IsValidDirection(d1));
/* Cast to uint so compiler can use bitmask. If the difference is negative
* and we used int instead of uint, further "+ 8" would have to be added. */
return (DirDiff)((uint)(d0 - d1) % 8);
return static_cast<DirDiff>(static_cast<uint>(d0) - static_cast<uint>(d1) % 8);
}

/**
Expand All @@ -88,7 +88,7 @@ inline DirDiff DirDifference(Direction d0, Direction d1)
inline DirDiff ChangeDirDiff(DirDiff d, DirDiff delta)
{
/* Cast to uint so compiler can use bitmask. Result can never be negative. */
return (DirDiff)((uint)(d + delta) % 8);
return static_cast<DirDiff>((static_cast<uint>(d) + static_cast<uint>(delta)) % 8);
}

/**
Expand All @@ -105,7 +105,7 @@ inline Direction ChangeDir(Direction d, DirDiff delta)
{
assert(IsValidDirection(d));
/* Cast to uint so compiler can use bitmask. Result can never be negative. */
return (Direction)((uint)(d + delta) % 8);
return static_cast<Direction>((static_cast<uint>(d) + static_cast<uint>(delta)) % 8);
}


Expand Down Expand Up @@ -150,7 +150,7 @@ inline DiagDirection ChangeDiagDir(DiagDirection d, DiagDirDiff delta)
{
assert(IsValidDiagDirection(d));
/* Cast to uint so compiler can use bitmask. Result can never be negative. */
return (DiagDirection)((uint)(d + delta) % 4);
return static_cast<DiagDirection>((static_cast<uint>(d) + static_cast<uint>(delta)) % 4);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/fileio_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ enum FiosType {
*/
inline AbstractFileType GetAbstractFileType(FiosType fios_type)
{
return static_cast<AbstractFileType>(fios_type & FT_MASK);
return static_cast<AbstractFileType>(static_cast<uint>(fios_type) & FT_MASK);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/script/api/script_rail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
EnforceCompanyModeValid(false);
EnforcePrecondition(false, ::IsValidTile(tile));
EnforcePrecondition(false, rail_track != 0);
EnforcePrecondition(false, (rail_track & ~::TRACK_BIT_ALL) == 0);
EnforcePrecondition(false, (static_cast<uint>(rail_track) & ~static_cast<uint>(::TRACK_BIT_ALL)) == 0);
EnforcePrecondition(false, KillFirstBit((uint)rail_track) == 0);
EnforcePrecondition(false, IsRailTypeAvailable(GetCurrentRailType()));

Expand Down
2 changes: 1 addition & 1 deletion src/script/api/script_station.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ template<bool Tfrom, bool Tvia>
if (!IsValidStation(station_id)) return false;
if (!HasExactlyOneBit(station_type)) return false;

return (::Station::Get(station_id)->facilities & station_type) != 0;
return (::Station::Get(station_id)->facilities & static_cast<StationFacility>(station_type)) != 0;
}

/* static */ bool ScriptStation::HasRoadType(StationID station_id, ScriptRoad::RoadType road_type)
Expand Down
2 changes: 1 addition & 1 deletion src/script/api/script_stationlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ScriptStationList::ScriptStationList(ScriptStation::StationType station_type)
CompanyID owner = ScriptObject::GetCompany();
ScriptList::FillList<Station>(this,
[is_deity, owner, station_type](const Station *st) {
return (is_deity || st->owner == owner) && (st->facilities & station_type) != 0;
return (is_deity || st->owner == owner) && (st->facilities & static_cast<StationFacility>(station_type)) != 0;
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/script/api/script_waypoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@
if (!IsValidWaypoint(waypoint_id)) return false;
if (!HasExactlyOneBit(waypoint_type)) return false;

return (::Waypoint::Get(waypoint_id)->facilities & waypoint_type) != 0;
return (::Waypoint::Get(waypoint_id)->facilities & static_cast<StationFacility>(waypoint_type)) != 0;
}
2 changes: 1 addition & 1 deletion src/script/api/script_waypointlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ScriptWaypointList::ScriptWaypointList(ScriptWaypoint::WaypointType waypoint_typ
CompanyID owner = ScriptObject::GetCompany();
ScriptList::FillList<Waypoint>(this,
[is_deity, owner, waypoint_type](const Waypoint *wp) {
return (is_deity || wp->owner == owner || wp->owner == OWNER_NONE) && (wp->facilities & waypoint_type) != 0;
return (is_deity || wp->owner == owner || wp->owner == OWNER_NONE) && (wp->facilities & static_cast<StationFacility>(waypoint_type)) != 0;
}
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/slope_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ inline Foundation InclinedFoundation(Axis axis)
inline Foundation HalftileFoundation(Corner corner)
{
assert(IsValidCorner(corner));
return (Foundation)(FOUNDATION_HALFTILE_W + corner);
return static_cast<Foundation>(static_cast<uint>(FOUNDATION_HALFTILE_W) + static_cast<uint>(corner));
}

/**
Expand All @@ -403,7 +403,7 @@ inline Foundation HalftileFoundation(Corner corner)
inline Foundation SpecialRailFoundation(Corner corner)
{
assert(IsValidCorner(corner));
return (Foundation)(FOUNDATION_RAIL_W + corner);
return static_cast<Foundation>(static_cast<uint>(FOUNDATION_RAIL_W) + static_cast<uint>(corner));
}

/**
Expand Down

0 comments on commit bb49112

Please sign in to comment.