Opened 15 years ago

Closed 14 years ago

Last modified 14 years ago

#1778 closed Bugs (fixed)

Possible regression in 1.35 serialization of 2D arrays

Reported by: dgt@… Owned by: Matthias Troyer
Milestone: Component: serialization
Version: Boost 1.35.0 Severity: Regression
Keywords: Cc:

Description

Our product has been using 1.34.1 for a while with no problems. However, upon upgrading to 1.35, I get the following compile error on MSVC2005 (32bit).

D:\tools\boost\boost_1_35_0\boost/archive/detail/oserializer.hpp(489) :

error C2440: 'static_cast' : cannot convert from 'const char (*w64 )[16]' to 'value_type *'

A 2D char array is being serialized as:

char c[5][16];

ar & make_nvp("c", c);


While I don't have but a high-level grasp of MPL, it seems to me that remove_all_extents<T>::type is stripping off all the dimensions, which causes line 489 to fail.

If instead, I serialize as:

ar & make_nvp("c", make_array(&c[0], sizeof(c)/sizeof(c[0]) );

It of course works. I can do the following as well:

ar & make_nvp("c", make_array(&c[0][0], sizeof(c)/sizeof(c[0][0]) );

I don't want to use any of the above because there are quite a few of these 2D arrays floating around. They don't contain large blocks of data, so I'm not interested in the make_array optimization at this time. I've created two wrappers which make things a little easier (shamelessly based on your make_array). I can't provide them as make_array overloads because oserializer then erroneously tries to pick one.

template<class T, std::size_t M, std::size_t N>
inline
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
const
#endif
array<T[N]> make_array2D( T (& t)[M][N] )
{
  return array<T[N]>(&t[0], M);
}


template<class T, std::size_t M, std::size_t N>
inline
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
const
#endif
array<T> make_array2D_flatten( T (& t)[M][N])
{
   return array<T>(static_cast<T*>(&t[0][0]), N*M);
}


Anyways, just thought I'd let you know what I've run into.

Change History (7)

comment:1 by dgt@…, 15 years ago

If this is in fact a deliberate regression, then a note in the documentation would be nice :)

comment:2 by Robert Ramey, 15 years ago

Owner: changed from Robert Ramey to Matthias Troyer

Matias - could you take a look at this one please?

Robert Ramey

comment:3 by dgt@…, 15 years ago

It seems that the code I need was commented out here [34068]. If this was just accidental as part of the MSVC 0-length array fix, I can simply copy the code into my own sources until Boost 1.35.1 is released. Otherwise, I can only assume it was commented out because there is a problem with it.

in reply to:  3 comment:4 by dgt@…, 15 years ago

Replying to dgt@acm.org:

It seems that the code I need was commented out here [34068]. If this was just accidental as part of the MSVC 0-length array fix, I can simply copy the code into my own sources until Boost 1.35.1 is released. Otherwise, I can only assume it was commented out because there is a problem with it.

I take that back. That code doesn't help. It looks like the previous behavior can only be attained by copying the data into a nested structure such as:

vector< vector<char> > c;
ar & make_nvp( "blah", c );

Or write my own wrapper class.

comment:5 by Matthias Troyer, 14 years ago

Milestone: To Be DeterminedBoost 1.35.1
Status: newassigned

comment:6 by Matthias Troyer, 14 years ago

Resolution: fixed
Status: assignedclosed

Fixed on the trunk

comment:7 by (none), 14 years ago

Milestone: Boost 1.35.1

Milestone Boost 1.35.1 deleted

Note: See TracTickets for help on using tickets.