Opened 10 years ago

Closed 6 years ago

#7391 closed Bugs (fixed)

phoenix::insert compile fails with libc++

Reported by: Naomasa Matsubayashi Owned by: Thomas Heller
Milestone: To Be Determined Component: phoenix
Version: Boost Development Trunk Severity: Problem
Keywords: Cc:

Description

Following code produces a compile error with libc++.

#include <vector>
#include <boost/phoenix.hpp>

int main() {
  std::vector< int > hoge;
  std::vector< int > fuga;
  namespace phx = boost::phoenix;
  phx::insert( phx::placeholders::_1, phx::placeholders::_2, fuga.begin(), fuga.end() )( hoge, hoge.end() );
}

That is because phoenix::insert expects the member function insert returns void when was is called with 3 arguments. That is correct in C++03 but not in C++11.( All insert overloads returns an iterator in C++11 [23.3.7.1] )

Since libstdc++ returns void even if the code was compiled as C++11, the problem doesn't appear. But at least with libc++, it fails to compile and following error message is produced.

      void function 'operator()' should not return a value [-Wreturn-type]
                return c.insert(arg1, arg2, arg3);
                ^      ~~~~~~~~~~~~~~~~~~~~~~~~~~

This patch fixed the problem on libc++. I think it needs more intelligent way to detect environments those insert always return a iterator. But I don't have any good idea on that :(

--- boost/phoenix/stl/container/container.hpp
+++ boost/phoenix/stl/container/container.hpp
@@ -425,6 +425,9 @@
                 choice_1;
 
                 typedef
+#ifdef _LIBCPP_VERSION
+                    iterator_of<C>
+#else
                     boost::mpl::eval_if_c<
                         boost::mpl::and_<
                             boost::is_same<Arg3, mpl::void_>
@@ -433,8 +436,8 @@
                       , iterator_of<C>
                       , boost::mpl::identity<void>
                     >
+#endif
                 choice_2;
-
             public:
 
                 typedef typename

Change History (1)

comment:1 by Kohei Takahashi, 6 years ago

Resolution: fixed
Status: newclosed

It might be already fixed in 4da68d2b04c8128b010e609697602991cbc17333, but next (1.63) release has better implementation c378960d48c0b3966a3f996b0144944dca954b86 .

Note: See TracTickets for help on using tickets.