Skip to content

Commit 51f5bdc

Browse files
authored
Reduce the number of MSVC warnings in CI workflow builds on Windows (#7254)
1 parent 1ba78bf commit 51f5bdc

File tree

9 files changed

+106
-13
lines changed

9 files changed

+106
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Unreleased
22
- Changes from 6.0.0
3+
- Build:
4+
- FIXED: Reduce MSVC compiler warnings by suppressing informational warnings while preserving bug-indicating warnings [#7253](https://github.com/Project-OSRM/osrm-backend/issues/7253)
35
- Misc:
46
- CHANGED: Update fmt library to version 11.2.0 [#7238](https://github.com/Project-OSRM/osrm-backend/issues/7238)
57
- CHANGED: Upgrade protozero from v1.7.1 to v1.8.1 [#7239](https://github.com/Project-OSRM/osrm-backend/pull/7239)

cmake/warnings.cmake

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
include (CheckCXXCompilerFlag)
22
include (CheckCCompilerFlag)
33

4-
# Try to add -Wflag if compiler supports it
4+
# Try to add -Wflag if compiler supports it (GCC/Clang)
55
macro (add_warning flag)
66
string(REPLACE "-" "_" underscored_flag ${flag})
77
string(REPLACE "+" "x" underscored_flag ${underscored_flag})
@@ -22,6 +22,37 @@ macro (add_warning flag)
2222
endif()
2323
endmacro()
2424

25+
# MSVC warning management macros
26+
macro (msvc_warning_level level)
27+
if (MSVC)
28+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W${level}")
29+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W${level}")
30+
endif()
31+
endmacro()
32+
33+
# Disable specific MSVC warning by code (e.g., 4711)
34+
macro (msvc_disable_warning code)
35+
if (MSVC)
36+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd${code}")
37+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd${code}")
38+
endif()
39+
endmacro()
40+
41+
# Enable specific MSVC warning by code
42+
macro (msvc_enable_warning code)
43+
if (MSVC)
44+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /w1${code}")
45+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /w1${code}")
46+
endif()
47+
endmacro()
48+
49+
# Disable MSVC warning for specific target
50+
macro (target_msvc_disable_warning target code)
51+
if (MSVC)
52+
target_compile_options(${target} PRIVATE "/wd${code}")
53+
endif()
54+
endmacro()
55+
2556
# Try to add -Wno flag if compiler supports it
2657
macro (no_warning flag)
2758
add_warning(no-${flag})
@@ -85,4 +116,57 @@ no_warning(restrict)
85116
no_warning(free-nonheap-object)
86117
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
87118
no_warning(stringop-overflow)
119+
endif()
120+
121+
# MSVC-specific warning configuration
122+
if(MSVC)
123+
# Set warning level 3 (default level with reasonable warnings)
124+
msvc_warning_level(3)
125+
126+
# Disable excessive informational warnings that don't indicate bugs
127+
msvc_disable_warning(4711) # Function selected for automatic inline expansion
128+
msvc_disable_warning(4710) # Function not inlined
129+
msvc_disable_warning(4514) # Unreferenced inline function removed
130+
msvc_disable_warning(4820) # Padding added to struct/class
131+
132+
# Disable implicit special member function warnings (often unavoidable in modern C++)
133+
msvc_disable_warning(4626) # Assignment operator implicitly deleted
134+
msvc_disable_warning(4625) # Copy constructor implicitly deleted
135+
msvc_disable_warning(5027) # Move assignment operator implicitly deleted
136+
msvc_disable_warning(5026) # Move constructor implicitly deleted
137+
msvc_disable_warning(4623) # Default constructor implicitly deleted
138+
139+
# Disable other low-value warnings
140+
msvc_disable_warning(5219) # Implicit conversion from T to bool
141+
msvc_disable_warning(5045) # Spectre mitigation
142+
msvc_disable_warning(5246) # Aggregate initialization
143+
msvc_disable_warning(4686) # Template specialization
144+
msvc_disable_warning(5266) # const qualifier discarded
145+
msvc_disable_warning(4800) # Implicit conversion to bool
146+
msvc_disable_warning(4868) # Left-to-right evaluation order
147+
msvc_disable_warning(4371) # Layout change from previous compiler version
148+
msvc_disable_warning(4127) # Conditional expression is constant
149+
msvc_disable_warning(4355) # 'this' used in member initializer list
150+
msvc_disable_warning(4668) # Preprocessor macro not defined
151+
msvc_disable_warning(5039) # Exception specification issue
152+
msvc_disable_warning(4777) # Format string mismatch
153+
msvc_disable_warning(5264) # Variable declared but not used
154+
155+
# KEEP these warnings enabled - they indicate potential bugs:
156+
# C4365: Signed/unsigned mismatch
157+
# C4267: Conversion with possible loss of data
158+
# C4244: Data conversion with possible loss
159+
# C4242: Data conversion with possible loss
160+
# C4458: Declaration hides class member
161+
# C4245: Signed/unsigned mismatch in conversion
162+
# C4389: Signed/unsigned mismatch in equality
163+
# C4457: Declaration hides function parameter
164+
# C4146: Unary minus applied to unsigned type
165+
# C4456: Declaration hides previous local declaration
166+
# C4996: Deprecated function usage
167+
# C4100: Unreferenced formal parameter
168+
# C4101: Unreferenced local variable
169+
# C4061: Switch statement case not handled
170+
171+
message(STATUS "MSVC warning configuration applied - suppressed informational warnings, kept bug-indicating warnings")
88172
endif()

include/contractor/contracted_edge_container.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct ContractedEdgeContainer
6161
void Filter(const std::vector<bool> &filter, std::size_t index)
6262
{
6363
BOOST_ASSERT(index < sizeof(MergedFlags) * CHAR_BIT);
64-
const MergedFlags flag = 1 << index;
64+
const MergedFlags flag = MergedFlags{1} << index;
6565

6666
for (auto edge_index : util::irange<std::size_t>(0, edges.size()))
6767
{
@@ -81,7 +81,7 @@ struct ContractedEdgeContainer
8181
{
8282
BOOST_ASSERT(index < sizeof(MergedFlags) * CHAR_BIT);
8383

84-
const MergedFlags flag = 1 << index++;
84+
const MergedFlags flag = MergedFlags{1} << index++;
8585

8686
auto edge_iter = edges.cbegin();
8787
auto edge_end = edges.cend();
@@ -151,7 +151,7 @@ struct ContractedEdgeContainer
151151
std::vector<std::vector<bool>> filters(index);
152152
for (const auto flag_index : util::irange<std::size_t>(0, index))
153153
{
154-
MergedFlags mask = 1 << flag_index;
154+
MergedFlags mask = MergedFlags{1} << flag_index;
155155
for (const auto flag : flags)
156156
{
157157
filters[flag_index].push_back(flag & mask);

include/engine/douglas_peucker.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ inline std::vector<std::uint64_t> generateThreshold(double min_pixel, unsigned n
2424
const double shift = (1u << zoom) * 256;
2525
const double b = shift / 2.0;
2626
const double pixel_to_deg = 180. / b;
27-
const std::uint64_t min_deg = min_pixel * pixel_to_deg * COORDINATE_PRECISION;
27+
// Safe conversion: geographic coordinate calculation always produces positive integers
28+
const std::uint64_t min_deg =
29+
static_cast<std::uint64_t>(min_pixel * pixel_to_deg * COORDINATE_PRECISION);
2830
thresholds[zoom] = min_deg * min_deg;
2931
}
3032

include/engine/guidance/assemble_steps.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,9 @@ inline std::vector<RouteStep> assembleSteps(const datafacade::BaseDataFacade &fa
215215
{
216216
intersection.entry.push_back(entry_class.allowsEntry(idx));
217217
}
218+
// Safe conversion: bearing values [0,360) fit comfortably in int16_t
218219
std::int16_t bearing_in_driving_direction =
219-
util::bearing::reverse(std::round(bearings.first));
220+
static_cast<std::int16_t>(util::bearing::reverse(std::round(bearings.first)));
220221
maneuver = {intersection.location,
221222
bearing_in_driving_direction,
222223
bearings.second,

include/guidance/turn_bearing.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ class TurnBearing
1414
public:
1515
static constexpr double bearing_scale = 360.0 / 256.0;
1616
// discretizes a bearing into distinct units of 1.4 degrees
17-
TurnBearing(const double value = 0) : bearing(value / bearing_scale)
17+
TurnBearing(const double value = 0)
18+
// Safe conversion: [0,360) / 1.40625 = [0,256) fits exactly in uint8_t
19+
: bearing(static_cast<std::uint8_t>(value / bearing_scale))
1820
{
1921
BOOST_ASSERT_MSG(value >= 0 && value < 360.0,
2022
"Bearing value needs to be between 0 and 360 (exclusive)");

include/partitioner/multi_level_partition.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <climits>
1616
#include <cmath>
1717
#include <cstdint>
18+
#include <limits>
1819
#include <numeric>
1920
#include <vector>
2021

@@ -217,9 +218,10 @@ template <storage::Ownership Ownership> class MultiLevelPartitionImpl final
217218
BOOST_ASSERT(next_offset <= NUM_PARTITION_BITS);
218219
// Check offset for shift overflow. Offsets are strictly increasing,
219220
// so we only need the check on the last mask.
220-
PartitionID next_mask = next_offset == NUM_PARTITION_BITS
221-
? -1ULL
222-
: (1ULL << next_offset) - 1ULL;
221+
PartitionID next_mask =
222+
next_offset == NUM_PARTITION_BITS
223+
? std::numeric_limits<PartitionID>::max()
224+
: (1ULL << next_offset) - 1ULL;
223225
// 001100
224226
masks[lidx++] = next_mask ^ mask;
225227
});

include/storage/shared_datatype.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class ContiguousDataLayout final : public BaseDataLayout
146146
inline void *align(void *&ptr) const noexcept
147147
{
148148
const auto intptr = reinterpret_cast<std::uintptr_t>(ptr);
149-
const auto aligned = (intptr - 1u + BLOCK_ALIGNMENT) & -BLOCK_ALIGNMENT;
149+
const auto aligned = (intptr - 1u + BLOCK_ALIGNMENT) & ~(BLOCK_ALIGNMENT - 1u);
150150
return ptr = reinterpret_cast<void *>(aligned);
151151
}
152152

include/util/xor_fast_hash.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ template <std::size_t MaxNumElements = (1u << 16u)> class XORFastHash
4444
{
4545
std::mt19937 generator(1); // impl. defined but deterministic default seed
4646

47-
std::iota(begin(table1), end(table1), 0u);
47+
std::iota(begin(table1), end(table1), std::uint16_t{0});
4848
std::shuffle(begin(table1), end(table1), generator);
4949

50-
std::iota(begin(table2), end(table2), 0u);
50+
std::iota(begin(table2), end(table2), std::uint16_t{0});
5151
std::shuffle(begin(table2), end(table2), generator);
5252
}
5353

0 commit comments

Comments
 (0)