diff --git a/src/pathfinder/yapf/yapf_common.hpp b/src/pathfinder/yapf/yapf_common.hpp index 42f69a1d79..3871822b5d 100644 --- a/src/pathfinder/yapf/yapf_common.hpp +++ b/src/pathfinder/yapf/yapf_common.hpp @@ -28,7 +28,9 @@ protected: /** to access inherited path finder */ inline Tpf& Yapf() { - return *static_cast(this); + /* use two lines to avoid false-positive Undefined Behavior Sanitizer warnings when alignof(Tpf) > alignof(*this) and *this does not meet alignof(Tpf) */ + Tpf *p = static_cast(this); + return *p; } public: @@ -72,7 +74,9 @@ protected: /** to access inherited path finder */ inline Tpf& Yapf() { - return *static_cast(this); + /* use two lines to avoid false-positive Undefined Behavior Sanitizer warnings when alignof(Tpf) > alignof(*this) and *this does not meet alignof(Tpf) */ + Tpf *p = static_cast(this); + return *p; } public: diff --git a/src/pathfinder/yapf/yapf_road.cpp b/src/pathfinder/yapf/yapf_road.cpp index 818ff78027..252ad0b9cd 100644 --- a/src/pathfinder/yapf/yapf_road.cpp +++ b/src/pathfinder/yapf/yapf_road.cpp @@ -42,7 +42,9 @@ protected: /** to access inherited path finder */ Tpf& Yapf() { - return *static_cast(this); + /* use two lines to avoid false-positive Undefined Behavior Sanitizer warnings when alignof(Tpf) > alignof(*this) and *this does not meet alignof(Tpf) */ + Tpf *p = static_cast(this); + return *p; } int SlopeCost(TileIndex tile, TileIndex next_tile, Trackdir trackdir)