Opened 3 years ago

#12040 new Bugs

The result of compilation relies upon the inclusion order of grep_serialize.hpp and gregorian.hpp

Reported by: laurent.stacul@… Owned by: az_sw_dude
Milestone: To Be Determined Component: date_time
Version: Boost 1.58.0 Severity: Problem
Keywords: Cc:

Description

The compilation success of a program should not rely upon the order in which a developer includes the headers.

This is unfortunately the case when we want to serialize an object in which one of its member is a boost::gregorian::date.

For the time being, a developer must include <boost/date_time/gregorian/gregorian.hpp> before <boost/date_time/gregorian/grep_serialize.hpp> otherwise the following error is thrown (with gcc, but it is reproduceable in clang):

[18:34]stac@macdebian:~/development/cpp-sandbox/boost>g++ --std=c++14 -g -I$HOME/development/date_time/include -lboost_serialization -lboost_date_time serialization.cpp
In file included from serialization.cpp:6:0:
/home/stac/development/date_time/include/boost/date_time/gregorian/greg_serialize.hpp: In function ‘void boost::serialization::save(Archive&, const boost::gregorian::date&, unsigned int)’:
/home/stac/development/date_time/include/boost/date_time/gregorian/greg_serialize.hpp:59:35: error: there are no arguments to ‘to_iso_string’ that depend on a template parameter, so a declaration of ‘to_iso_string’ must be available [-fpermissive]
   std::string ds = to_iso_string(d);
                                   ^
/home/stac/development/date_time/include/boost/date_time/gregorian/greg_serialize.hpp:59:35: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
zsh: exit 1     g++ --std=c++14 -g -I$HOME/development/date_time/include -lboost_serializatio

Current architecture: Linux macdebian 4.3.0-1-amd64 #1 SMP Debian 4.3.5-1 (2016-02-06) x86_64 GNU/Linux

Compilers: gcc: g++ (Debian 5.3.1-8) 5.3.1 20160205

clang: Debian clang version 3.6.2-3 (tags/RELEASE_362/final) (based on LLVM 3.6.2) Target: x86_64-pc-linux-gnu Thread model: posix

A solution could be to forward declare the boost::gregorian::to_iso_string(const boost::gregorian::date&) in greg_serialize.hpp. Or to include gregorian/formatters[_limited].hpp

Remark: This problem does not occur with posix_time.

Attachments (1)

serialization.cpp (798 bytes) - added by laurent.stacul@… 3 years ago.
Reproducer

Download all attachments as: .zip

Change History (1)

Changed 3 years ago by laurent.stacul@…

Attachment: serialization.cpp added

Reproducer

Note: See TracTickets for help on using tickets.