[clang-cl] Ignore /Wv and /Wv:17 flags
[llvm-project.git] / clang / test / CXX / special / class.copy / p11.0x.copy.cpp
blobe7256bcf9485f7923e7ffbf42628b5945a9b3827
1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
3 struct Trivial {};
4 struct NonTrivial {
5 NonTrivial(const NonTrivial&);
6 };
8 // A defaulted copy constructor for a class X is defined as deleted if X has:
10 // -- a variant member with a non-trivial corresponding constructor
11 union DeletedNTVariant {
12 NonTrivial NT; // expected-note{{copy constructor of 'DeletedNTVariant' is implicitly deleted because variant field 'NT' has a non-trivial copy constructor}}
13 DeletedNTVariant();
15 DeletedNTVariant DVa;
16 DeletedNTVariant DVb(DVa); // expected-error{{call to implicitly-deleted copy constructor}}
18 struct DeletedNTVariant2 {
19 union {
20 NonTrivial NT; // expected-note{{copy constructor of 'DeletedNTVariant2' is implicitly deleted because variant field 'NT' has a non-trivial copy constructor}}
22 DeletedNTVariant2();
24 DeletedNTVariant2 DV2a;
25 DeletedNTVariant2 DV2b(DV2a); // expected-error{{call to implicitly-deleted copy constructor}}
27 // -- a non-static data member of class type M (or array thereof) that cannot be
28 // copied because overload resolution results in an ambiguity or a function
29 // that is deleted or inaccessible
30 struct NoAccess {
31 NoAccess() = default;
32 private:
33 NoAccess(const NoAccess&);
35 friend struct HasAccess;
38 struct HasNoAccess {
39 NoAccess NA; // expected-note{{copy constructor of 'HasNoAccess' is implicitly deleted because field 'NA' has an inaccessible copy constructor}}
41 HasNoAccess HNAa;
42 HasNoAccess HNAb(HNAa); // expected-error{{call to implicitly-deleted copy constructor}}
44 struct HasAccess {
45 NoAccess NA;
48 HasAccess HAa;
49 HasAccess HAb(HAa);
51 struct NonConst {
52 NonConst(NonConst&);
54 struct Ambiguity {
55 Ambiguity(const Ambiguity&);
56 Ambiguity(volatile Ambiguity&);
59 struct IsAmbiguous {
60 NonConst NC;
61 Ambiguity A; // expected-note 2{{copy constructor of 'IsAmbiguous' is implicitly deleted because field 'A' has multiple copy constructors}}
62 IsAmbiguous();
64 IsAmbiguous IAa;
65 IsAmbiguous IAb(IAa); // expected-error{{call to implicitly-deleted copy constructor}}
67 struct Deleted {
68 IsAmbiguous IA; // expected-note{{copy constructor of 'Deleted' is implicitly deleted because field 'IA' has a deleted copy constructor}}
70 Deleted Da;
71 Deleted Db(Da); // expected-error{{call to implicitly-deleted copy constructor}}
73 // It's implied (but not stated) that this also applies in the case where
74 // overload resolution would fail.
75 struct VolatileMember {
76 volatile Trivial vm; // expected-note {{has no copy}}
77 } vm1, vm2(vm1); // expected-error {{deleted}}
79 // -- a direct or virtual base class B that cannot be copied because overload
80 // resolution results in an ambiguity or a function that is deleted or
81 // inaccessible
82 struct AmbiguousCopyBase : Ambiguity { // expected-note 2{{copy constructor of 'AmbiguousCopyBase' is implicitly deleted because base class 'Ambiguity' has multiple copy constructors}}
83 NonConst NC;
85 extern AmbiguousCopyBase ACBa;
86 AmbiguousCopyBase ACBb(ACBa); // expected-error {{deleted copy constructor}}
88 struct DeletedCopyBase : AmbiguousCopyBase {}; // expected-note {{copy constructor of 'DeletedCopyBase' is implicitly deleted because base class 'AmbiguousCopyBase' has a deleted copy constructor}}
89 extern DeletedCopyBase DCBa;
90 DeletedCopyBase DCBb(DCBa); // expected-error {{deleted copy constructor}}
92 struct InaccessibleCopyBase : NoAccess {}; // expected-note {{copy constructor of 'InaccessibleCopyBase' is implicitly deleted because base class 'NoAccess' has an inaccessible copy constructor}}
93 extern InaccessibleCopyBase ICBa;
94 InaccessibleCopyBase ICBb(ICBa); // expected-error {{deleted copy constructor}}
96 // -- any direct or virtual base class or non-static data member of a type with
97 // a destructor that is deleted or inaccessible
98 struct NoAccessDtor {
99 private:
100 ~NoAccessDtor();
101 friend struct HasAccessDtor;
104 struct HasNoAccessDtor {
105 NoAccessDtor NAD; // expected-note{{copy constructor of 'HasNoAccessDtor' is implicitly deleted because field 'NAD' has an inaccessible destructor}}
106 HasNoAccessDtor();
107 ~HasNoAccessDtor();
109 HasNoAccessDtor HNADa;
110 HasNoAccessDtor HNADb(HNADa); // expected-error{{call to implicitly-deleted copy constructor}}
112 struct HasAccessDtor {
113 NoAccessDtor NAD;
115 HasAccessDtor HADa;
116 HasAccessDtor HADb(HADa);
118 struct HasNoAccessDtorBase : NoAccessDtor { // expected-note{{copy constructor of 'HasNoAccessDtorBase' is implicitly deleted because base class 'NoAccessDtor' has an inaccessible destructor}}
120 extern HasNoAccessDtorBase HNADBa;
121 HasNoAccessDtorBase HNADBb(HNADBa); // expected-error{{implicitly-deleted copy constructor}}
123 // -- a non-static data member of rvalue reference type
124 int some_int;
125 struct RValue {
126 int && ri = static_cast<int&&>(some_int); // expected-note{{copy constructor of 'RValue' is implicitly deleted because field 'ri' is of rvalue reference type 'int &&'}}
128 RValue RVa;
129 RValue RVb(RVa); // expected-error{{call to implicitly-deleted copy constructor}}
131 // FIXME: The error on the class-name is attached to the location of the
132 // constructor. This is not especially clear.
133 struct RValueTmp { // expected-error {{reference member 'ri' binds to a temporary}}
134 int && ri = 1; // expected-note{{copy constructor of 'RValueTmp' is implicitly deleted because field 'ri' is of rvalue reference type 'int &&'}} // expected-note {{default member init}}
136 RValueTmp RVTa; // expected-note {{implicit default constructor for 'RValueTmp' first required here}}
137 RValueTmp RVTb(RVTa); // expected-error{{call to implicitly-deleted copy constructor}}
139 namespace PR13381 {
140 struct S {
141 S(const S&);
142 S(const volatile S&) = delete; // expected-note{{deleted here}}
144 struct T {
145 volatile S s; // expected-note{{field 's' has a deleted copy constructor}}
147 T &f();
148 T t = f(); // expected-error{{call to implicitly-deleted copy constructor}}
151 namespace Mutable {
152 struct A {
153 A(const A &);
154 A(A &) = delete; // expected-note {{deleted here}}
157 struct B {
158 A a;
159 B(const B &);
161 B::B(const B &) = default;
163 struct C {
164 mutable A a; // expected-note {{deleted because field 'a' has a deleted copy constructor}}
165 C(const C &);
167 C::C(const C &) = default; // expected-error{{would delete}}