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

Missing traits for std::vector<bool> #54

Closed
robinchrist opened this issue Jul 16, 2019 · 18 comments
Closed

Missing traits for std::vector<bool> #54

robinchrist opened this issue Jul 16, 2019 · 18 comments
Assignees

Comments

@robinchrist
Copy link

Hi,

We do crossbuilds for OSX and I stumbled upon a few issues.
I'll provide details later, but they are all related to the usage of std::vector<bool> and type traits not working.

This is most probably an OSX SDK issue though, but I think we might find a generic solution, because this could happen with different implementations too.

@ColinH
Copy link
Member

ColinH commented Jul 16, 2019

That's strange, we do CI builds on macOS, and my main development platform is macOS, and usually everything works. Which compiler and C++ library are you using? Are you actually cross-compiling?

@robinchrist
Copy link
Author

We use Clang 7.0.1 together with cmake-ts on Linux to crosscompile our native node addons for Windows, Linux and Mac.

@ColinH
Copy link
Member

ColinH commented Jul 16, 2019

We do CI builds with Clang 7, so it shouldn't be the compiler. Are you using libc++ or libstdc++?

@robinchrist
Copy link
Author

robinchrist commented Jul 16, 2019

The offending line was

templObj.emplace("FrontFacing", templ.getFrontFacing());

where

const std::vector<bool>& getFrontFacing() const;

Full error log:
https://pastebin.com/Xn04DyUu

My first workaround attempt was a helper function

tao::json::value booleanVecToArray(const std::vector<bool>& vec) {
    tao::json::value arr = tao::json::empty_array;
    for(const auto& val : vec) {
        arr.push_back(val);
    }

    return arr;
}

Which does not work too
https://pastebin.com/TDDdBXmd

Changing to

tao::json::value jsonValue = val;
arr.push_back(std::move(jsonValue));

doesn't work either

../../../../../secretprojectname/src/util/jsonutil.cpp:135:13: error: no matching member function for call to 'push_back'
        arr.push_back(val);
        ~~~~^~~~~~~~~
../../../../../secretprojectname/include/tao/json/binding/internal/../../basic_value.hpp:892:12: note: candidate function not viable: no known conversion from 'const std::__1::__bit_const_reference<std::__1::vector<bool, std::__1::allocator<bool> > >' to 'const tao::json::basic_value<traits>' for 1st argument
      void push_back( const basic_value& v )
           ^
../../../../../secretprojectname/include/tao/json/binding/internal/../../basic_value.hpp:898:12: note: candidate function not viable: no known conversion from 'const std::__1::__bit_const_reference<std::__1::vector<bool, std::__1::allocator<bool> > >' to 'tao::json::basic_value<traits>' for 1st argument
      void push_back( basic_value&& v )

Finally

for(const bool val : vec) {
        tao::json::value jsonValue = val;
        arr.push_back(std::move(jsonValue));
    }

So I'd say there are some serious issues with const-refs to std::vector<bool> with the libc++ OSX SDK

@ColinH
Copy link
Member

ColinH commented Jul 16, 2019

So the issue is that there is no tao::json::traits< std::vector< bool > > specialisation?

@robinchrist
Copy link
Author

@ColinH see my updated comment #54 (comment)

@ColinH
Copy link
Member

ColinH commented Jul 16, 2019

In the first work-around, try arr.push_back(bool(val)), since val will be the weird proxy object instead of the actual bool.

@robinchrist
Copy link
Author

robinchrist commented Jul 16, 2019

In the first work-around, try arr.push_back(bool(val)), since val will be the weird proxy object instead of the actual bool.

I'm sure this would work. However, I'm more concerned by the fact, that the OSX std::vector<bool> implementation is broken and delivers some weird proxy object (std::__1::__bit_const_reference<...>)

Actually nlohmann/json had the same problem, see nlohmann/json#494

@ColinH
Copy link
Member

ColinH commented Jul 16, 2019

That's not broken, std::vector< bool > is strange by (ancient) design, in other words it's not a bug it's a feature!

https://en.cppreference.com/w/cpp/container/vector_bool

@ColinH
Copy link
Member

ColinH commented Jul 16, 2019

What's missing is a specialisation of the traits for std::vector< bool >, shouldn't take too long, I'll see when I get around to it.

@ColinH ColinH self-assigned this Jul 16, 2019
@ColinH ColinH changed the title Build issues on OSX with std::vector<bool> Missing traits for std::vector<bool> Jul 16, 2019
@robinchrist
Copy link
Author

I know of the peculiarities of std::vector<bool>. I was really surprised, that it worked on Linux and Windows, but not on OSX...

@ColinH
Copy link
Member

ColinH commented Jul 16, 2019

That is somewhat surprising.

@d-frey
Copy link
Member

d-frey commented Jul 16, 2019 via email

@ColinH
Copy link
Member

ColinH commented Jul 16, 2019

@robinchrist Can you please test whether the latest commit fixes the issue?

@robinchrist
Copy link
Author

@ColinH Sure, will report back ASAP

@robinchrist
Copy link
Author

@ColinH CI build works fine!

@ColinH
Copy link
Member

ColinH commented Jul 16, 2019

Great. Did you see which library you are using on the different platforms?

@ColinH ColinH closed this as completed Jul 16, 2019
@robinchrist
Copy link
Author

As far as I know it's libstdc++ for linux and standard CRT for Windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants