I have code which used to work when it was compiled with libstdc++ library on macOS (Sierra 10.12.4). I'm now switching over to libc++ and it gives compile-time error:
main.cpp:41:44: error: calling a private constructor of class 'std::__1::__wrap_iter<const unsigned char *>'
std::vector<uint8_t>::const_iterator i1 = std::vector<uint8_t>::const_iterator(data);
^
/Applications/http://ift.tt/2rRWiLe: note: declared private here
_LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
^
main.cpp:42:44: error: calling a private constructor of class 'std::__1::__wrap_iter<const unsigned char *>'
std::vector<uint8_t>::const_iterator i2 = std::vector<uint8_t>::const_iterator(data+n);
^
/Applications/http://ift.tt/2rRWiLe: note: declared private here
_LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
^
2 errors generated.
Apparently, const_iterator constructor which takes raw data pointers is now private in macOS' libc++ library.
The code below fails when compiled as g++ main.cpp -std=c++11 and succeeds when compiled as g++ main.cpp -std=c++11 -stdlib=libstdc++:
#include <iostream>
#include <vector>
class Blob {
public:
size_t size() const { return (end_-begin_); }
uint8_t operator[](size_t pos) const { return *(begin_+pos); }
const uint8_t* data() const { return &(*begin_); }
Blob(const Blob& b):begin_(b.begin_), end_(b.end_){}
Blob(const std::vector<uint8_t>::const_iterator& begin,
const std::vector<uint8_t>::const_iterator& end):
begin_(begin), end_(end){}
Blob& operator=(const Blob& b)
{
if (this != &b)
{
begin_ = b.begin_;
end_ = b.end_;
}
return *this;
}
std::vector<uint8_t>::const_iterator begin() const
{ return begin_; }
std::vector<uint8_t>::const_iterator end() const
{ return end_; }
protected:
std::vector<uint8_t>::const_iterator begin_, end_;
Blob() = delete;
};
int main()
{
std::cout << "hello" << std::endl;
int n = 100;
uint8_t *data = new uint8_t(n);
Blob b(std::vector<uint8_t>::const_iterator(data),
std::vector<uint8_t>::const_iterator(data+n));
}
How do I make it compile with libc++?
Aucun commentaire:
Enregistrer un commentaire