Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile error when using flat_map::extract_sequence with small_vector #288

Closed
arthaud opened this issue Sep 2, 2024 · 1 comment
Closed

Comments

@arthaud
Copy link

arthaud commented Sep 2, 2024

Hi,

My project started seeing compilation errors with boost 1.86.0, when using flat_map::extract_sequence in combination with small_vector.

Here is a repro:

#include <boost/container/flat_map.hpp>
#include <boost/container/small_vector.hpp>
#include <iostream>

using SmallVector = boost::container::small_vector<std::pair<int, int>, 1>;
using FlatMap = boost::container::flat_map<int, int, std::less<int>, SmallVector>;

int main()
{
    FlatMap map;
    map.insert_or_assign(1, 1);

    auto container = map.extract_sequence();
    map.adopt_sequence(boost::container::ordered_unique_range,
        std::move(container));

    std::cout << "size: " << map.size() << "\n";
    return 0;
}

This results in:

/Users/arthaud/homebrew/opt/boost/include/boost/container/flat_map.hpp:77:11: error: non-const lvalue reference to type 'small_vector<[2 * ...], void, [...]>' cannot bind to a value of unrelated type 'small_vector<[2 * ...], boost::container::new_allocator<std::pair<int, int>>, [...]>'
{  return s; }
          ^
/Users/arthaud/homebrew/opt/boost/include/boost/container/flat_map.hpp:1605:31: note: in instantiation of function template specialization 'boost::container::dtl::force<boost::container::small_vector<std::pair<int, int>, 1>, boost::container::small_vector<std::pair<int, int>, 1, boost::container::new_allocator<std::pair<int, int>>>>' requested here
      return boost::move(dtl::force<sequence_type>(m_flat_tree.get_sequence_ref()));
                              ^
test.cpp:13:26: note: in instantiation of member function 'boost::container::flat_map<int, int, std::less<int>, boost::container::small_vector<std::pair<int, int>, 1>>::extract_sequence' requested here
    auto container = map.extract_sequence();
                         ^
In file included from test.cpp:1:
/Users/arthaud/homebrew/opt/boost/include/boost/container/flat_map.hpp:77:11: error: non-const lvalue reference to type 'small_vector<[2 * ...], boost::container::new_allocator<std::pair<int, int>>, [...]>' cannot bind to a value of unrelated type 'small_vector<[2 * ...], void, [...]>'
{  return s; }
          ^
/Users/arthaud/homebrew/opt/boost/include/boost/container/flat_map.hpp:1627:90: note: in instantiation of function template specialization 'boost::container::dtl::force<boost::container::small_vector<std::pair<int, int>, 1, boost::container::new_allocator<std::pair<int, int>>>, boost::container::small_vector<std::pair<int, int>, 1>>' requested here
   {  this->m_flat_tree.adopt_sequence_unique(ordered_unique_range_t(), boost::move(dtl::force<impl_sequence_type>(seq)));  }
                                                                                         ^
test.cpp:14:9: note: in instantiation of member function 'boost::container::flat_map<int, int, std::less<int>, boost::container::small_vector<std::pair<int, int>, 1>>::adopt_sequence' requested here
    map.adopt_sequence(boost::container::ordered_unique_range,
        ^
2 errors generated.

This is also visible in CI here: https://github.com/facebook/mariana-trench/actions/runs/10595093691/job/29360092181

I think this is related to dtl::force<impl_sequence_type>, but I didn't dig deeper.
FYI this issue is not present with older version (for instance, boost 1.77.0).

facebook-github-bot pushed a commit to facebook/redex that referenced this issue Sep 4, 2024
Summary:
Boost 1.86.0 has a bug with flat_map::extract_sequence.
Let's use a workaround for now.

See boostorg/container#288 for upstream report.

Reviewed By: arnaudvenet

Differential Revision: D62103078

fbshipit-source-id: c54777faff875635ed025b16e78a99aaf555453f
facebook-github-bot pushed a commit to facebook/redex that referenced this issue Sep 4, 2024
Summary:
Boost 1.86.0 has a bug with flat_map::extract_sequence.
Let's use a workaround for now.

See boostorg/container#288 for upstream report.

Reviewed By: arnaudvenet

Differential Revision: D62103078

fbshipit-source-id: c54777faff875635ed025b16e78a99aaf555453f
facebook-github-bot pushed a commit to facebook/SPARTA that referenced this issue Sep 4, 2024
Summary:
Boost 1.86.0 has a bug with flat_map::extract_sequence.
Let's use a workaround for now.

See boostorg/container#288 for upstream report.

Reviewed By: arnaudvenet

Differential Revision: D62103078

fbshipit-source-id: c54777faff875635ed025b16e78a99aaf555453f
@igaztanaga
Copy link
Member

Many thanks for the issue. Trying to reproduce it I found that extract/adopt were not properly tested and in general, flat_map tests needed to test more combinations of types (move-only, etc) and underlying containers (small_vector, devector, etc.). I've committed those changes first (daa81ed) and then commit changes to fix your bug.

So your bug report has been very useful, thanks!

facebook-github-bot pushed a commit to facebook/redex that referenced this issue Sep 11, 2024
Summary:
The bug with `boost::container::flat_map::extract_sequence` has been fixed (see boostorg/container#288)
This should go out in boost 1.87 (probably in a few months).

Therefore, let's re-enable the optimization for boost versions != 1.86

Reviewed By: arnaudvenet

Differential Revision: D62436361

fbshipit-source-id: b2010fbae81f4b65039ee1dd6459c5e7021dbc3f
facebook-github-bot pushed a commit to facebook/redex that referenced this issue Sep 11, 2024
Summary:
The bug with `boost::container::flat_map::extract_sequence` has been fixed (see boostorg/container#288)
This should go out in boost 1.87 (probably in a few months).

Therefore, let's re-enable the optimization for boost versions != 1.86

Reviewed By: arnaudvenet

Differential Revision: D62436361

fbshipit-source-id: b2010fbae81f4b65039ee1dd6459c5e7021dbc3f
facebook-github-bot pushed a commit to facebook/SPARTA that referenced this issue Sep 11, 2024
Summary:
The bug with `boost::container::flat_map::extract_sequence` has been fixed (see boostorg/container#288)
This should go out in boost 1.87 (probably in a few months).

Therefore, let's re-enable the optimization for boost versions != 1.86

Reviewed By: arnaudvenet

Differential Revision: D62436361

fbshipit-source-id: b2010fbae81f4b65039ee1dd6459c5e7021dbc3f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants