Skip to content

Commit 1c3d9e9

Browse files
Fix MSVC build error: std::array size exceeds 32-bit limit (#14)
* Fix MSVC build error: reduce std::array placeholder size to comply with 32-bit limit Co-authored-by: StefanFabian <2090520+StefanFabian@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: StefanFabian <2090520+StefanFabian@users.noreply.github.com>
1 parent 0ffe45e commit 1c3d9e9

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.vscode/
33
cmake-build-debug/
44
cmake-build-release/
5+
_codeql_detected_source_root

ros_babel_fish/include/ros_babel_fish/messages/array_message.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ class ArrayMessage_ final : public ArrayMessageBase
9696
typename std::enable_if_t<FIXED_LENGTH || !std::is_same_v<ENABLED, bool>, Reference>
9797
operator[]( size_t index )
9898
{
99-
using Container =
100-
typename std::conditional_t<FIXED_LENGTH, std::array<T, 987654321000>, std::vector<T>>;
99+
// Using size 1 as placeholder since actual bounds checking is done separately via size()
100+
// and this array type is only used for reinterpret_cast, never actually instantiated.
101+
// Note: Using large values (e.g. 987654321000) causes MSVC to fail compilation.
102+
using Container = typename std::conditional_t<FIXED_LENGTH, std::array<T, 1>, std::vector<T>>;
101103
if ( member_->get_function == nullptr ) {
102104
if ( index >= size() )
103105
throw std::out_of_range( "Index was out of range of array!" );
@@ -119,8 +121,7 @@ class ArrayMessage_ final : public ArrayMessageBase
119121

120122
ConstReturnType operator[]( size_t index ) const
121123
{
122-
using Container =
123-
typename std::conditional_t<FIXED_LENGTH, std::array<T, 987654321000>, std::vector<T>>;
124+
using Container = typename std::conditional_t<FIXED_LENGTH, std::array<T, 1>, std::vector<T>>;
124125
if ( member_->get_function == nullptr ) {
125126
if ( index >= size() )
126127
throw std::out_of_range( "Index was out of range of array!" );

0 commit comments

Comments
 (0)