c++ - 使用 uclibc 编译已删除的函数失败

标签 c++ gcc glibc uclibc

我有一个项目要从 glibc 移植到 uclibc,但遇到了这个问题。

gcc --std=c++11 Foo.cpp -o Foo-glibc
x86_64-linux-uclibc-gcc --std=c++11 Foo.cpp -o Foo-uclibc

// Compiles under glibc and uclibc
class Foo {
  Foo() = default;
  Foo(const Foo& arg) = delete;
  ~Foo() = default;
};

// Only compiles under glibc
class Foo {
  Foo() = default;
  Foo(const Foo& arg);
  ~Foo() = default;
};
Foo::Foo(const Foo& arg) = delete; // uclibc - Error: deleted definition of 'Foo::Foo(const Foo&)'

为什么会出现这个错误?这是预期的行为吗?我读过的任何内容都表明 uclibc 不应该能够处理这个问题。

最佳答案

这很可能是旧 gcc 版本中的错误。

在 4.8.5 中它 worked , 但在 5.1.0 中它是 doesn't .

引用 Alan Birtles 的话

[I]t makes no sense to declare a constructor in the class declaration[,] then delete it out of line. How would a consumer of the class know that the constructor is deleted?

关于c++ - 使用 uclibc 编译已删除的函数失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52098695/

相关文章:

c++ - x86、C++、gcc 和内存对齐

c++11 - g++ 4.8.* std::chrono 未声明

gcc - 如何在编译时删除 `GLIBC_2.27' 要求?

c - malloc() 和 memset() 行为

linux - 在 CentOS 7 上构建 C 项目,链接器不能使用 -ldl 、 -lc

C++ 枚举类 : Cast to non existing entry

c++ - "Symbol ' 在命名空间中映射 ' could not be resolved"

c++ - 在指向父对象的指针上初始化子对象

c++ - Mac OS X 上的异步 I/O

c - gcc 目标文件链接