xref: /llvm-project/clang/test/SemaObjCXX/block-capture.mm (revision e1c3e16d24b5cc097ff08e9283f53319acd3f245)
1ba15d186SMark de Wever// RUN: %clang_cc1 -std=c++23 -fsyntax-only -fobjc-arc -fblocks                       -verify=cxx98_23,cxx11_23,cxx23 %s
2ba15d186SMark de Wever// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fobjc-arc -fblocks                       -verify=cxx98_23,cxx11_23       %s
3ba15d186SMark de Wever// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fobjc-arc -fblocks                       -verify=cxx98_23,cxx11_23       %s
4ba15d186SMark de Wever// RUN: %clang_cc1 -std=c++98 -fsyntax-only -fobjc-arc -fblocks -Wno-c++11-extensions -verify=cxx98_23,cxx98          %s
512c90e2eSMatheus Izvekov
612c90e2eSMatheus Izvekov#define TEST(T) void test_##T() { \
712c90e2eSMatheus Izvekov  __block T x;                    \
812c90e2eSMatheus Izvekov  (void)^(void) { (void)x; };     \
912c90e2eSMatheus Izvekov}
1012c90e2eSMatheus Izvekov
1112c90e2eSMatheus Izvekovstruct CopyOnly {
12ba15d186SMark de Wever  CopyOnly();           // cxx23-note {{not viable}}
13ba15d186SMark de Wever  CopyOnly(CopyOnly &); // cxx23-note {{not viable}}
1412c90e2eSMatheus Izvekov};
15ba15d186SMark de WeverTEST(CopyOnly); // cxx23-error {{no matching constructor}}
1612c90e2eSMatheus Izvekov
1703282f2fSMatheus Izvekov// Both ConstCopyOnly and NonConstCopyOnly are
1803282f2fSMatheus Izvekov// "pure" C++98 tests (pretend 'delete' means 'private').
1903282f2fSMatheus Izvekov// However we may extend implicit moves into C++98, we must make sure the
2003282f2fSMatheus Izvekov// results in these are not changed.
217d2d5a3aSMatheus Izvekovstruct ConstCopyOnly {
227d2d5a3aSMatheus Izvekov  ConstCopyOnly();
237d2d5a3aSMatheus Izvekov  ConstCopyOnly(ConstCopyOnly &) = delete; // cxx98-note {{marked deleted here}}
247d2d5a3aSMatheus Izvekov  ConstCopyOnly(const ConstCopyOnly &);
257d2d5a3aSMatheus Izvekov};
267d2d5a3aSMatheus IzvekovTEST(ConstCopyOnly); // cxx98-error {{call to deleted constructor}}
277d2d5a3aSMatheus Izvekov
287d2d5a3aSMatheus Izvekovstruct NonConstCopyOnly {
297d2d5a3aSMatheus Izvekov  NonConstCopyOnly();
307d2d5a3aSMatheus Izvekov  NonConstCopyOnly(NonConstCopyOnly &);
31ba15d186SMark de Wever  NonConstCopyOnly(const NonConstCopyOnly &) = delete; // cxx11_23-note {{marked deleted here}}
327d2d5a3aSMatheus Izvekov};
33ba15d186SMark de WeverTEST(NonConstCopyOnly); // cxx11_23-error {{call to deleted constructor}}
347d2d5a3aSMatheus Izvekov
3512c90e2eSMatheus Izvekovstruct CopyNoMove {
3612c90e2eSMatheus Izvekov  CopyNoMove();
3712c90e2eSMatheus Izvekov  CopyNoMove(CopyNoMove &);
38ba15d186SMark de Wever  CopyNoMove(CopyNoMove &&) = delete; // cxx98_23-note {{marked deleted here}}
3912c90e2eSMatheus Izvekov};
40ba15d186SMark de WeverTEST(CopyNoMove); // cxx98_23-error {{call to deleted constructor}}
4112c90e2eSMatheus Izvekov
4212c90e2eSMatheus Izvekovstruct MoveOnly {
4312c90e2eSMatheus Izvekov  MoveOnly();
4403282f2fSMatheus Izvekov  MoveOnly(MoveOnly &) = delete;
4512c90e2eSMatheus Izvekov  MoveOnly(MoveOnly &&);
4612c90e2eSMatheus Izvekov};
4703282f2fSMatheus IzvekovTEST(MoveOnly);
4812c90e2eSMatheus Izvekov
4912c90e2eSMatheus Izvekovstruct NoCopyNoMove {
5012c90e2eSMatheus Izvekov  NoCopyNoMove();
5103282f2fSMatheus Izvekov  NoCopyNoMove(NoCopyNoMove &) = delete;
52ba15d186SMark de Wever  NoCopyNoMove(NoCopyNoMove &&) = delete; // cxx98_23-note {{marked deleted here}}
5312c90e2eSMatheus Izvekov};
54ba15d186SMark de WeverTEST(NoCopyNoMove); // cxx98_23-error {{call to deleted constructor}}
5512c90e2eSMatheus Izvekov
5612c90e2eSMatheus Izvekovstruct ConvertingRVRef {
5712c90e2eSMatheus Izvekov  ConvertingRVRef();
5803282f2fSMatheus Izvekov  ConvertingRVRef(ConvertingRVRef &) = delete;
5912c90e2eSMatheus Izvekov
6012c90e2eSMatheus Izvekov  struct X {};
6112c90e2eSMatheus Izvekov  ConvertingRVRef(X &&);
6212c90e2eSMatheus Izvekov  operator X() const & = delete;
6312c90e2eSMatheus Izvekov  operator X() &&;
6412c90e2eSMatheus Izvekov};
6503282f2fSMatheus IzvekovTEST(ConvertingRVRef);
6612c90e2eSMatheus Izvekov
6712c90e2eSMatheus Izvekovstruct ConvertingCLVRef {
6812c90e2eSMatheus Izvekov  ConvertingCLVRef();
6912c90e2eSMatheus Izvekov  ConvertingCLVRef(ConvertingCLVRef &);
7012c90e2eSMatheus Izvekov
7112c90e2eSMatheus Izvekov  struct X {};
72ba15d186SMark de Wever  ConvertingCLVRef(X &&); // cxx98_23-note {{passing argument to parameter here}}
7312c90e2eSMatheus Izvekov  operator X() const &;
74ba15d186SMark de Wever  operator X() && = delete; // cxx98_23-note {{marked deleted here}}
7512c90e2eSMatheus Izvekov};
76ba15d186SMark de WeverTEST(ConvertingCLVRef); // cxx98_23-error {{invokes a deleted function}}
7712c90e2eSMatheus Izvekov
7812c90e2eSMatheus Izvekovstruct SubSubMove {};
7912c90e2eSMatheus Izvekovstruct SubMove : SubSubMove {
8012c90e2eSMatheus Izvekov  SubMove();
8103282f2fSMatheus Izvekov  SubMove(SubMove &) = delete;
8212c90e2eSMatheus Izvekov
8312c90e2eSMatheus Izvekov  SubMove(SubSubMove &&);
8412c90e2eSMatheus Izvekov};
8503282f2fSMatheus IzvekovTEST(SubMove);
86*e1c3e16dSAkira Hatanaka
87*e1c3e16dSAkira Hatanaka
88*e1c3e16dSAkira Hatanaka#if __cplusplus >= 202302L
89*e1c3e16dSAkira Hatanaka// clang used to crash compiling this code.
90*e1c3e16dSAkira Hatanakanamespace BlockInLambda {
91*e1c3e16dSAkira Hatanaka  struct S {
92*e1c3e16dSAkira Hatanaka    constexpr ~S();
93*e1c3e16dSAkira Hatanaka  };
94*e1c3e16dSAkira Hatanaka
95*e1c3e16dSAkira Hatanaka  void func(S const &a) {
96*e1c3e16dSAkira Hatanaka    [a](auto b) {
97*e1c3e16dSAkira Hatanaka      ^{
98*e1c3e16dSAkira Hatanaka        (void)a;
99*e1c3e16dSAkira Hatanaka      }();
100*e1c3e16dSAkira Hatanaka    }(12);
101*e1c3e16dSAkira Hatanaka  }
102*e1c3e16dSAkira Hatanaka}
103*e1c3e16dSAkira Hatanaka#endif
104