Opened 7 years ago

Closed 5 years 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@…

Description

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 by Braden McDaniel <braden@…>, 7 years ago

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 by Jean-Michaël Celerier, 7 years ago

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 by Kohei Takahashi, 6 years ago

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

This should be fixed in 1.62 release (https://github.com/boostorg/phoenix/pull/33).

comment:4 by rogeeff@…, 5 years ago

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 by Kohei Takahashi, 5 years ago

Resolution: fixed
Status: reopenedclosed

OK, fwd-decl will be replaced with include by https://github.com/boostorg/phoenix/pull/54.

Note: See TracTickets for help on using tickets.