Subject: Re: [Boost-bugs] [Boost C++ Libraries] #12179: Including boost/optional/optional_fwd.hpp without first including boost/config.hpp doesn't compile.
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-05-14 08:36:15
#12179: Including boost/optional/optional_fwd.hpp without first including
boost/config.hpp doesn't compile.
-------------------------------+-----------------------
Reporter: c.d.glover@⦠| Owner: fcacciola
Type: Bugs | Status: new
Milestone: To Be Determined | Component: optional
Version: Boost 1.61.0 | Severity: Problem
Resolution: | Keywords:
-------------------------------+-----------------------
Comment (by post@â¦):
Here's a slightly different problem, but with the same solution:
If optional/optional_fwd.hpp is included before any boost header that
includes config.hpp (for example optional.hpp), there are multiple
problems. Example:
{{{
#include "boost/optional/optional_fwd.hpp"
#include "boost/optional.hpp"
int main() {
return 0;
}
}}}
The first problem is a build failure because of inconsistent defines:
1. optional/optional_fwd.hpp includes config/suffix.hpp
2. config/suffix.hpp uses an include guard to prevent multiple inclusions
of itself
3. config/suffix.hpp doesn't define int128_type and uint128_type because
BOOST_HAS_INT128 is not defined
4. another boost header includes config.hpp
5. config.hpp includes config/compiler/gcc.hpp
6. config/compiler/gcc.hpp defines BOOST_HAS_INT128
7. config.hpp includes config/suffix.hpp, but the include guard prevents
reevaluation of the file
Now, we have BOOST_HAS_INT128 defined, but boost::int128_type and
boost::uint128_type are not. If we now try to compile something that
includes type_traits/is_integral.hpp (which optional/optional.hpp
indirectly does), we get to this code, which doesn't compile due to
unknown types:
{{{
#ifdef BOOST_HAS_INT128
template<> struct is_integral<boost::int128_type> : public true_type{};
template<> struct is_integral<boost::uint128_type> : public true_type{};
#endif
}}}
The second class of problems are redefinition warnings. Here's an example
(there are multiple defines that get redefined):
1. optional/optional_fwd.hpp includes config/suffix.hpp
2. config/suffix.hpp first sets BOOST_LIKELY to a no-op default
3. another boost header includes config.hpp
4. config.hpp includes config/compiler/gcc.hpp
5. config/compiler/gcc.hpp redefines BOOST_LIKELY to work as intended ->
redefinition warning
As a conclusion, optional/optional_fwd.hpp should include config.hpp
instead of config/suffix.hpp Currently, optional/optional_fwd.hpp is the
only file in boost that includes config/suffix.hpp directly (not through
config.hpp), so it's probably not meant to be used this way.
(context: I'm using gcc 5.3.1 on Fedora 23)
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/12179#comment:1> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:20 UTC