简体   繁体   中英

Call to implicitly-deleted copy constructor in LLVM(Porting code from windows to mac)

We are in the process of porting some c++ code from windows to mac and are having issues compiling it with LLVM 6.1 using c++11. We are encountering errors all over the place of "Call to implicitly-deleted copy contructor" Some of these errors are popping up in our code.

for (auto it : _unhandledFiles)//ERROR HERE
{
    if (it.first == file)
    {
        return true;
    }
}
return false;

However they are also showing up in the memory file of the LLVM compiler as well as the vector file.

template <class _Up, class... _Args>
    _LIBCPP_INLINE_VISIBILITY
    void
    construct(_Up* __p, _Args&&... __args)
    {
        ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);//ERROR HERE
    }


vector<_Tp, _Allocator>::operator=(const vector& __x)
{
if (this != &__x)
{
    __base::__copy_assign_alloc(__x);
    assign(__x.__begin_, __x.__end_);//ERROR HERE
}
return *this;
}

Has anyone ever experienced this error before when porting c++ code from Windows to Mac? I feel as if it is compiler related and there must be some simple fix that I am just unaware of as I'm getting errors in places I can't actually edit (memory, vector etc....)

This line of code is very ambiguous:

for (auto it : _unhandledFiles)//ERROR HERE

auto uses template argument deduction, so

std::string s;
std::string& sr = sr;
auto x = sr;

in the above code x is deduced to be of type std::string , not std::string& . So your loop is equivalent to:

for (_unhandledFiles::value_type it : _unhandledFiles)
// aka
for (auto uhfIt = _unhandledFiles.cbegin();
         uhfIt != _unhandledFiles.cend();
         ++uhfIt) {
    _unhandledFiles::value_type it = *uhfIt; // COPY
    // ... your code here ...
    it.dtor(); // obviously not, I'm just emphasizing.
}

not

for (_unhandledFiles::value_type& it : _unhandledFiles)

So each iteration of the loop is copying values from _unhandledFiles.

The fix would be to either use iterators or:

for (auto& it: _unhandledFiles)
---------^

---- edit ----

Because of the confusion this causes, C++14 introduces decltype(auto) but using that would introduce a copy if the rhs was not a reference.

std::string s;
std::string& sr = s;

auto xr1 = sr; // std::string xr1 -> copy
auto& xr2 = sr; // std::string& xr2 -> reference
decltype(auto) xr3 = sr; // std::string& xr3 -> reference

auto xv1 = s; // std::string xv1 -> copy
auto& xv2 = s; // std::string& xv2 -> reference
decltype(auto) xv3 = s; // std::string xv3 -> copy

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM