Opened 14 years ago

Closed 14 years ago

#2760 closed Bugs (fixed)

A problem with serialization libraries when compilin on vc9 with /Za

Reported by: Greg Ravikovich <grisharav@…> Owned by: Robert Ramey
Milestone: Boost 1.39.0 Component: serialization
Version: Boost 1.38.0 Severity: Problem
Keywords: Cc:

Description

I have a compilation problem when serializing to a text_oarchive. The problem doesn't happen when serializing to a binary_oarchive. here's a sample code:

#include <boost/test/unit_test.hpp>

#include <boost/serialization/serialization.hpp> #include <boost/archive/text_oarchive.hpp> #include <boost/archive/binary_oarchive.hpp> #include <boost/serialization/tracking.hpp>

struct SerializableStruct {

int m_data;

};

namespace boost {

namespace serialization {

template<class Archive> void serialize(Archive & ar, SerializableStruct & s, unsigned int ) {

ar & s.m_data;

}

}

}

BOOST_CLASS_TRACKING(SerializableStruct,boost::serialization::track_never);

BOOST_AUTO_TEST_SUITE(TestGeneralSerialize)

BOOST_AUTO_TEST_CASE(TestTextArchive) {

boost::archive::text_oarchive out(std::cout); SerializableStruct s; s.m_data = 10; out << s;

}

BOOST_AUTO_TEST_CASE(TestBinaryArchive) {

std::stringstream str; boost::archive::binary_oarchive out(str); SerializableStruct s; s.m_data = 10; out << s;

}

BOOST_AUTO_TEST_SUITE_END();

The code compiles fine under boost 1.35, or when using /Za (Enable language extensions), but fails in boost\archive\detail\oserializer.hpp line 538, BOOST_STATIC_WARNING (...) This code should require no language extension during compilation.

Greg

Change History (7)

comment:1 by Robert Ramey, 14 years ago

This is likely an issue with the implementation of BOOST_STATIC_WARNING for this compiler. Perhaps you want to run test_static_warning and post the results. Assuming that this is correct, perhaps you might want to suggest a tweak to BOOST_STATIC_WARNING which would address the issue.

Robert Ramey

comment:2 by Greg Ravikovich <grisharav@…>, 14 years ago

I have played around with this and found out the following: The code: #include <boost/static_warning.hpp>

void ShouldCompile() {

BOOST_STATIC_WARNING(true);

} Doesn't compile with /Za

If I change the line # 163 from just a bracket to "} a" The code compiles fine. This is not a solution since there are lots of different implementations depending on the compiler, the writer of BOOST_STATIC_WARNING should check this.

Greg

comment:3 by Greg Ravikovich <grisharav@…>, 14 years ago

Line 163 in static_warning.hpp, is the line...

comment:4 by Robert Ramey, 14 years ago

Can't figure out what you're suggesting here. Line 163 in static_warning.hpp is a comment.

in reply to:  4 comment:5 by Greg Ravikovich <grisharav@…>, 14 years ago

Replying to ramey:

Can't figure out what you're suggesting here. Line 163 in static_warning.hpp is a comment.

No, line 163 in static_warning.hpp is the closing bracket for an unnamed struct containing the actual implementation. Giving it some name ('a' for example) solves the compilation error. I don't really have a suggestion there, I think the best way would be to use some other implementation of static_warning (maybe another one from the same file?) Greg

comment:6 by Greg Ravikovich <grisharav@…>, 14 years ago

Another thought might be changing to BOOST_STATIC_ASSERT

comment:7 by Robert Ramey, 14 years ago

Resolution: fixed
Status: newclosed

OK - think I fixed this in the next version

Note: See TracTickets for help on using tickets.