Opened 3 years ago

Closed 16 months ago

#11875 closed Bugs (fixed)

Boost.Phoenix should not forward-declare std::unordered_set / map

Reported by: Jean-Michaël Celerier <jeanmichael.celerier@…> Owned by: Thomas Heller
Milestone: Boost 1.65.0 Component: phoenix
Version: Boost 1.64.0 Severity: Problem
Keywords: Cc: braden@…


Boost 1.60 introduced the header boost/phoenix/stl/algorithm/detail/std_unordered_set_or_map_fwd.hpp.

When building on Linux with libstdc++ debug mode (-DGLIBCXX_DEBUG) this causes ambiguous references to the forward-declared classes because in libstdc++ side, they now live in the std::debug namespace instead.

The following test cases triggers it :

#include <boost/spirit/include/phoenix.hpp>
#include <unordered_map>

void f()
	std::unordered_map<int, float> map;

when built with

g++ -std=c++11 -D_GLIBCXX_DEBUG=1 -c problem.cpp

Change History (5)

comment:1 Changed 3 years ago by Braden McDaniel <braden@…>

Cc: braden@… added

There are other problems with this, as well, using gcc/libstdc++ (4.9, at least). For instance, this template specialization fails to compile if the problem Phoenix header gets included:

template <typename T, typename TypeT, typename KeyT, typename HashT, typename KeyEqualT, typename AllocatorT>
class foo<T, std::unordered_map<KeyT, TypeT, HashT, KeyEqualT, AllocatorT> >

For the time being, I'm simply compiling my code with BOOST_PHOENIX_USING_LIBCPP defined, as this disables the forward declarations. But this is obviously undesirable if that macro ever gets used for something that is actually libc++-specific.

comment:2 Changed 2 years ago by Jean-Michaël Celerier

Got another similar problem (in boost 1.60) in boost/phoenix/stl/algorithm/detail/is_unordered_set_or_map.hpp . The BOOST_PHOENIX_USING_LIBCPP trick seems to work however.

comment:3 Changed 22 months ago by Kohei Takahashi

Milestone: To Be DeterminedBoost 1.62.0
Resolution: fixed
Status: newclosed

This should be fixed in 1.62 release (

comment:4 Changed 16 months ago by rogeeff@…

Milestone: Boost 1.62.0Boost 1.65.0
Resolution: fixed
Status: closedreopened
Version: Boost 1.60.0Boost 1.64.0

This is still wrong. There is no legal way to forward declare std::unordered_set/std::unordered_map. According to the standard ([namespace.std]), these forward declarations have undefined behavior.

This need to change to

#include <unordered_map> #include <unordered_set>

comment:5 Changed 16 months ago by Kohei Takahashi

Resolution: fixed
Status: reopenedclosed

OK, fwd-decl will be replaced with include by

Note: See TracTickets for help on using tickets.