考虑下面的人为例子
struct A {
A(int) {}
A(const A&) = delete;
~A() {}
};
struct B {
A a[2] = {{1}, {2}};
};
int main() {
B b;
}
Run Code Online (Sandbox Code Playgroud)
它可以在clang(任何版本)中正常编译,但在GCC(任何版本,任何标准> = C ++ 11)中均不能编译
<source>: In constructor 'constexpr B::B()':
<source>:7:8: error: use of deleted function 'A::A(const A&)'
struct B {
^
<source>:3:5: note: declared here
A(const A&) = delete;
^
<source>: In function 'int main()':
<source>:12:7: note: synthesized method 'constexpr B::B()' first required here
B b; …Run Code Online (Sandbox Code Playgroud)