Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#9619 closed Bugs (invalid)

Deserialization of deep object tree fails on VS2012 when a templated function is called in the same cpp file

Reported by: Yodan Tauber <yodan.tauber@…> Owned by: Robert Ramey
Milestone: To Be Determined Component: serialization
Version: Boost 1.55.0 Severity: Problem
Keywords: Cc:

Description

When using Visual Studio 2012, error C2996 ("recursive function template definition") is reported by the compiler when all of the following conditions apply:

  1. A C++ object is deserialized using Boost Serialization somewhere in the *.cpp file.
  2. The serialized object is "deep enough" (~5 levels - i.e. A contains a vector of B, B contains a vector of C, etc. until E).
  3. Somewhere in the same *.cpp file (not necessarily in the same function), some templated function is called.

The error is no longer reported if the object is changed to be more "shallow". The error is no longer reported if the call to the templated function is removed.

This error does not reproduce in VS2010. It occurs in VS2012 as well as VS2013. Tested with Boost versions 1.49, 1.52, 1.55 - same problem.

Note: while this may be caused by an underlying bug in VS2012 (and I have opened an issue with Microsoft Connect regarding this), I think we need a workaround within Boost, as the chances that Microsoft will fix this are slim at best.

Note: about to attach a cpp file which reproduces the problem.

Attachments (1)

BugC2996.cpp (3.0 KB ) - added by Yodan Tauber <yodan.tauber@…> 9 years ago.
Code to reproduce the problem

Download all attachments as: .zip

Change History (5)

by Yodan Tauber <yodan.tauber@…>, 9 years ago

Attachment: BugC2996.cpp added

Code to reproduce the problem

comment:2 by Robert Ramey, 9 years ago

Typically something like this occurs when templates are nested "too deep". Try using the compiler switch to increase template depth to 256 levels. I forget what the template switch name is - you'll have to look it up. You can also look a the bjam files for tests and build. Respond here if the problem can be fixed this way.

comment:3 by Robert Ramey, 9 years ago

Resolution: invalid
Status: newclosed

in reply to:  2 comment:4 by Yodan Tauber <yodan.tauber@…>, 9 years ago

Replying to ramey:

Typically something like this occurs when templates are nested "too deep". Try using the compiler switch to increase template depth to 256 levels. I forget what the template switch name is - you'll have to look it up. You can also look a the bjam files for tests and build. Respond here if the problem can be fixed this way.

Unfortunately there is no such switch in MSVC. As far as I can understand, bjam's "c++-template-depth" argument is not used when building with MSVC.

Anyway, how is it that an object tree just 5 levels deep is deep enough to hit the compiler limit when Boost serialization is used?

Note: See TracTickets for help on using tickets.