简体   繁体   English

clang libc ++错误:重载选择了隐式删除的副本分配运算符

[英]clang libc++ error: overload resolution selected implicitly-deleted copy assignment operator

I can't get a C++11 project using clang 3.1 to compile. 我无法使用clang 3.1编译C ++ 11项目。 The command to the compiler is this: 编译器的命令是这样的:

clang++-mp-3.1 -c -std=c++11 -stdlib=libc++ -Wall -g -Iinclude -I/usr/local/include -I/opt/local/include -I/usr/local/include/mongo -o world.o world.cpp

And the error I get, since I included the "-stdlib=libc++" directive, is this: 由于我包含了“ -stdlib = libc ++”指令,因此我得到的错误是:

In file included from world.cpp:1:
/usr/include/c++/v1/string:1952:10: error: overload resolution selected implicitly-deleted copy assignment operator
    __r_ = _STD::move(__str.__r_);
         ^
/usr/include/c++/v1/string:1942:9: note: in instantiation of member function 'std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__move_assign' requested here
        __move_assign(__str, true_type());
        ^
/usr/include/c++/v1/string:1961:5: note: in instantiation of member function 'std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__move_assign' requested here
    __move_assign(__str, integral_constant<bool,
    ^
/usr/include/c++/v1/utility:200:24: note: in instantiation of member function 'std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::operator=' requested here
struct _LIBCPP_VISIBLE pair
                       ^
/usr/include/c++/v1/memory:1941:5: note: copy assignment operator is implicitly deleted because '__compressed_pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>
      >::__rep, std::__1::allocator<char> >' has a user-declared move constructor
    __compressed_pair(__compressed_pair&& __p)
    ^
1 error generated.

Can anyone advise me on how I can get this to work? 谁能建议我如何使它工作?

The file I'm trying to compile doesn't even have to include any C++11 code for this error to occur, the "-stdlib=libc++" directive alone is enough to make it break. 我要编译的文件甚至不必包含任何C ++ 11代码即可发生此错误,仅“ -stdlib = libc ++”指令就足以使其损坏。

Thanks for any & all assistance, Doug. 感谢您提供的所有协助,道格。

UPDATE: Hi -- the code is pretty basic, but in making it as basic as possible, I came across this error: 更新:嗨-代码很基本,但是在使其尽可能基本的过程中,我遇到了此错误:

Undefined symbols for architecture x86_64:
  "std::__1::cout", referenced from:
      _main in world.o
  "std::__1::basic_ostream<char, std::__1::char_traits<char> >::sentry::sentry(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)", referenced from:
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<< <std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*) in world.o
  "std::__1::ios_base::clear(unsigned int)", referenced from:
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<< <std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*) in world.o
  "std::__1::basic_ostream<char, std::__1::char_traits<char> >::sentry::~sentry()", referenced from:
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<< <std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*) in world.o
  "std::__1::ios_base::__set_badbit_and_consider_rethrow()", referenced from:
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<< <std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*) in world.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

To get this error, I stripped my code back to this: 为了得到这个错误,我将代码剥离回去:

#include <iostream>
int main( int argc, char *argv[] )
{
  std::cout << "Hi.\n";
}

Which makes this look like something pretty fundamentally wrong. 这使得这看起来根本上是错误的。

I don't get this error when I take out the "-stdlib=libc++" directive to the compiler. 当我对编译器取出“ -stdlib = libc ++”指令时,没有出现此错误。

Perhaps you should consider installing clang from llvm itself. 也许您应该考虑从llvm本身安装clang。 This can be found here . 可以在这里找到。 I am not 100% sure but perhaps macports or similar has compiled your version against a different gcc than you have installed. 我不确定100%,但也许macports或类似产品已针对与您安装的gcc不同的gcc编译了您的版本。 The llvm downloads are compiled against the gcc that in installed and should prove ABI compatible. llvm下载是针对已安装的gcc编译的,应证明与ABI兼容。

You can also upgrade the libc++.dynlib if you follow the instructions in llvm, but be aware a great many progs in MAC depend on this so you must make a copy of the existing lib (just in case). 如果按照llvm中的说明进行操作,也可以升级libc ++。dynlib,但是请注意,MAC中的许多编都依赖于此,因此您必须复制现有lib(以防万一)。 If you want bleeding edge you may need to dive into these changes. 如果您想要前沿技术,则可能需要深入研究这些变化。 I have done this on a mac and it was perfectly fine and can compile c++11 code just fine. 我已经在Mac上完成了这项工作,这非常好,可以很好地编译c ++ 11代码。

To build libc++ see here 要构建libc ++,请参见此处

There's a similar question here . 有一个类似的问题在这里

In short, when this happens it is because one of the possible overloads was declared as forbidden, hence the overload resolution fails. 简而言之,发生这种情况是因为将可能的重载之一声明为禁止,因此重载解析失败。 To get around it you should explicitly cast to make that forbidden overload not be one of the resolutions for the call. 为了解决这个问题,您应该显式强制转换以使禁止的重载不是该调用的解决方案之一。

See the accepted answer to the linked question for a very detailed and well written explanation. 有关链接的问题的详细说明和书面说明,请参见接受的答案。

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

相关问题 叮当声:在libc ++中使用std :: Map时,副本分配运算符将被删除 - Clang: Copy assignment operator is getting deleted while using std::Map in libc++ 隐式删除的复制构造函数编译错误返回指针的值 - Implicitly-deleted copy constructor compile error returning value of a pointer 错误:调用“ Cadena”的隐式删除副本构造函数 - error: call to implicitly-deleted copy constructor of 'Cadena' 移动构造函数(错误:调用隐式删除的拷贝构造函数) - Move constructor (error: call to implicitly-deleted copy constructor) 调用RandGenerator的隐式删除的复制构造函数 - Call to implicitly-deleted copy constructor of RandGenerator C ++ - 隐式删除了复制赋值运算符 - C++ - Copy Assignment Operator is Implicitly Deleted 删除了隐式声明的复制赋值运算符 - Deleted implicitly-declared copy assignment operator gcc和clang在运算符重载解析期间隐式实例化模板参数 - gcc and clang implicitly instantiate template arguments during operator overload resolution 尝试将参数传递给方法时出现“调用隐式删除的复制构造函数”错误 - “call to implicitly-deleted copy constructor of” error when tried to pass argument to a method 向量 <unique_ptr<A> &gt;在构造函数中-错误:调用隐式删除的拷贝构造函数 - vector<unique_ptr<A> > in constructor - error: call to implicitly-deleted copy constructor
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM