简体   繁体   English

调用 LLVM 中隐式删除的复制构造函数(将代码从 windows 移植到 mac)

[英]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.我们正在将一些 c++ 代码从 windows 移植到 mac,并且在使用 c++11 用 LLVM 6.1 编译它时遇到了问题。 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.然而,它们也出现在 LLVM 编译器的内存文件以及矢量文件中。

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?在将 c++ 代码从 Windows 移植到 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 auto使用模板参数推导,所以

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& .在上面的代码中, x被推导出为std::string类型,而不是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.所以循环的每次迭代都是从 _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.由于这会引起混淆,C++14 引入了decltype(auto)但如果 rhs 不是引用,则使用它会引入一个副本。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 调用RandGenerator的隐式删除的复制构造函数 - Call to implicitly-deleted copy constructor of RandGenerator 移动构造函数(错误:调用隐式删除的拷贝构造函数) - Move constructor (error: call to implicitly-deleted copy constructor) 错误:调用“ Cadena”的隐式删除副本构造函数 - error: call to implicitly-deleted copy constructor of 'Cadena' 调用隐式删除的默认构造函数 - Call to implicitly-deleted default constructor 在LLVM中调用隐式删除的复制构造函数 - Call to implicitly deleted copy constructor in LLVM LLVM find_if具有unique_ptr &lt;&gt;的隐式删除副本构造函数 - LLVM find_if implicitly-deleted copy constructor with unique_ptr<> 向量 <unique_ptr<A> &gt;在构造函数中-错误:调用隐式删除的拷贝构造函数 - vector<unique_ptr<A> > in constructor - error: call to implicitly-deleted copy constructor 尝试将参数传递给方法时出现“调用隐式删除的复制构造函数”错误 - “call to implicitly-deleted copy constructor of” error when tried to pass argument to a method 错误:使用auto调用unique_ptr的隐式删除的复制构造函数 - error: call to implicitly-deleted copy constructor of unique_ptr with auto 错误:调用 &#39;std::__1::unique_ptr 的隐式删除复制构造函数<A, std::__1::default_delete<A> &gt;&#39; - error: call to implicitly-deleted copy constructor of 'std::__1::unique_ptr<A, std::__1::default_delete<A> >'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM