1

我有一个项目要从 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 不应该能够处理这个问题。

4

1 回答 1

3

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

在 4.8.5 中它可以工作,但在 5.1.0 中它没有

引用 Alan Birtles

[我]在类声明[,]中声明构造函数然后将其删除是没有意义的。类的消费者如何知道构造函数已被删除?

于 2018-08-31T06:04:54.940 回答