Modify

Ticket #1778 (closed Bugs: fixed)

Opened 6 years ago

Last modified 5 years ago

Possible regression in 1.35 serialization of 2D arrays

Reported by: dgt@… Owned by: 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.

Attachments

Change History

comment:1 Changed 6 years ago by dgt@…

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

comment:2 Changed 6 years ago by ramey

  • Owner changed from ramey to troyer

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

Robert Ramey

comment:3 follow-up: ↓ 4 Changed 6 years ago by dgt@…

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.

comment:4 in reply to: ↑ 3 Changed 6 years ago by dgt@…

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 Changed 6 years ago by troyer

  • Status changed from new to assigned
  • Milestone changed from To Be Determined to Boost 1.35.1

comment:6 Changed 6 years ago by troyer

  • Status changed from assigned to closed
  • Resolution set to fixed

Fixed on the trunk

comment:7 Changed 5 years ago by anonymous

  • Milestone Boost 1.35.1 deleted

Milestone Boost 1.35.1 deleted

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.