pubby / flat

Flat containers for C++
Boost Software License 1.0
56 stars 9 forks source link

Incompatibility with std::vector<bool> #4

Open jcelerier opened 6 years ago

jcelerier commented 6 years ago

Due to the (admittedly braindead) std::vector<bool> implementation :

#include <flat_set.hpp>

fc::vector_set<bool>* set_a;
void foo()
{
    set_a->find(true);
}

$ clang++ -Wreturn-stack-address wtf.cpp -Ipath/to/flat/include
In file included from wtf.cpp:1:
In file included from /home/jcelerier/score/API/3rdparty/flat/include/flat_set.hpp:8:
/home/jcelerier/score/API/3rdparty/flat/include/impl/flat_impl.hpp:72:42: warning: returning reference to local temporary object
      [-Wreturn-stack-address]
    reference operator*() const { return *underlying; }
                                         ^~~~~~~~~~~
/home/jcelerier/score/API/3rdparty/flat/include/impl/flat_impl.hpp:269:61: note: in instantiation of member function
      'fc::impl::flat_iterator<std::_Bit_iterator, fc::impl::dummy_iterator<std::_Bit_iterator>,
      std::random_access_iterator_tag>::operator*' requested here
        if(it == self()->end() || self()->value_comp()(key, *it))
                                                            ^
wtf.cpp:7:12: note: in instantiation of member function 'fc::impl::flat_container_base<fc::flat_set<std::vector<bool,
      std::allocator<bool> >, std::less<void> >, bool, std::vector<bool, std::allocator<bool> >, std::less<void>, int>::find' requested
      here
    set_a->find(true);
           ^
1 warning generated.

(of course in itself a set is quite dumb, but it's a case that can happen, for instance in generic code ; maybe a static_assert should be in place to prevent such cases ?)

pubby commented 6 years ago

Looks like operator+ and - was wrong. I've fixed it in bfa3b77 and it should work now.

Thanks :+1:

jcelerier commented 6 years ago

thanks for the fix ! but it's about the other issue, #5, right ?

pubby commented 6 years ago

Ha, whoops. That's correct.