@@ -808,38 +808,38 @@ void test13() {
808
808
} // namespace GH100526
809
809
810
810
namespace lifetime_capture_by {
811
- struct S {
811
+ struct X {
812
812
const int *x;
813
- void captureInt (const int &x [[clang::lifetime_capture_by(this )]]) { this ->x = &x; }
813
+ void captureInt (const int & x [[clang::lifetime_capture_by(this )]]) { this ->x = &x; }
814
814
void captureSV (std::string_view sv [[clang::lifetime_capture_by(this )]]);
815
815
};
816
816
// /////////////////////////
817
817
// Detect dangling cases.
818
818
// /////////////////////////
819
- void captureInt (const int &x [[clang::lifetime_capture_by(s )]], S&s );
820
- void captureRValInt (int &&x [[clang::lifetime_capture_by(s )]], S&s );
821
- void noCaptureInt (int x [[clang::lifetime_capture_by(s )]], S&s );
819
+ void captureInt (const int & i [[clang::lifetime_capture_by(x )]], X& x );
820
+ void captureRValInt (int && i [[clang::lifetime_capture_by(x )]], X& x );
821
+ void noCaptureInt (int i [[clang::lifetime_capture_by(x )]], X& x );
822
822
823
823
std::string_view substr (const std::string& s [[clang::lifetimebound]]);
824
824
std::string_view strcopy (const std::string& s);
825
825
826
- void captureSV (std::string_view x [[clang::lifetime_capture_by(s )]], S&s );
827
- void captureRValSV (std::string_view&& x [[clang::lifetime_capture_by(s )]], S&s );
828
- void noCaptureSV (std::string_view x, S&s );
829
- void captureS (const std::string& x [[clang::lifetime_capture_by(s )]], S&s );
830
- void captureRValS (std::string&& x [[clang::lifetime_capture_by(s )]], S&s );
826
+ void captureSV (std::string_view s [[clang::lifetime_capture_by(x )]], X& x );
827
+ void captureRValSV (std::string_view&& sv [[clang::lifetime_capture_by(x )]], X& x );
828
+ void noCaptureSV (std::string_view sv, X& x );
829
+ void captureS (const std::string& s [[clang::lifetime_capture_by(x )]], X& x );
830
+ void captureRValS (std::string&& s [[clang::lifetime_capture_by(x )]], X& x );
831
831
832
832
const std::string& getLB (const std::string& s[[clang::lifetimebound]]);
833
833
const std::string& getLB (std::string_view sv[[clang::lifetimebound]]);
834
834
const std::string* getPointerLB (const std::string& s[[clang::lifetimebound]]);
835
835
const std::string* getPointerNoLB (const std::string& s);
836
836
837
- void capturePointer (const std::string* x [[clang::lifetime_capture_by(s )]], S&s );
837
+ void capturePointer (const std::string* sp [[clang::lifetime_capture_by(x )]], X& x );
838
838
839
839
struct ThisIsCaptured {
840
- void capture (S& s ) [[clang::lifetime_capture_by(s )]];
841
- void bar (S& s ) [[clang::lifetime_capture_by(abcd)]]; // expected-error {{'lifetime_capture_by' attribute argument 'abcd' is not a known function parameter}}
842
- void baz (S& s ) [[clang::lifetime_capture_by(this )]]; // expected-error {{'lifetime_capture_by' argument references itself}}
840
+ void capture (X& x ) [[clang::lifetime_capture_by(x )]];
841
+ void bar (X& x ) [[clang::lifetime_capture_by(abcd)]]; // expected-error {{'lifetime_capture_by' attribute argument 'abcd' is not a known function parameter}}
842
+ void baz (X& x ) [[clang::lifetime_capture_by(this )]]; // expected-error {{'lifetime_capture_by' argument references itself}}
843
843
};
844
844
845
845
void captureByGlobal (std::string_view s [[clang::lifetime_capture_by(global)]]);
@@ -848,63 +848,63 @@ void captureByUnknown(std::string_view s [[clang::lifetime_capture_by(unknown)]]
848
848
void use () {
849
849
std::string_view local_sv;
850
850
std::string local_s;
851
- S s ;
851
+ X x ;
852
852
// Capture an 'int'.
853
853
int local;
854
- captureInt (1 , // expected-warning {{object whose reference is captured by 's ' will be destroyed at the end of the full-expression}}
855
- s );
856
- captureRValInt (1 , s ); // expected-warning {{object whose reference is captured by 's '}}
857
- captureInt (local, s );
858
- noCaptureInt (1 , s );
859
- noCaptureInt (local, s );
854
+ captureInt (1 , // expected-warning {{object whose reference is captured by 'x ' will be destroyed at the end of the full-expression}}
855
+ x );
856
+ captureRValInt (1 , x ); // expected-warning {{object whose reference is captured by 'x '}}
857
+ captureInt (local, x );
858
+ noCaptureInt (1 , x );
859
+ noCaptureInt (local, x );
860
860
861
861
// Capture using std::string_view.
862
- captureSV (local_sv, s );
863
- captureSV (std::string (), // expected-warning {{object whose reference is captured by 's '}}
864
- s );
862
+ captureSV (local_sv, x );
863
+ captureSV (std::string (), // expected-warning {{object whose reference is captured by 'x '}}
864
+ x );
865
865
captureSV (substr (
866
- std::string () // expected-warning {{object whose reference is captured by 's '}}
867
- ), s );
868
- captureSV (substr (local_s), s );
869
- captureSV (strcopy (std::string ()), s );
870
- captureRValSV (std::move (local_sv), s );
871
- captureRValSV (std::string (), s ); // expected-warning {{object whose reference is captured by 's '}}
872
- captureRValSV (std::string_view{" abcd" }, s );
873
- captureRValSV (substr (local_s), s );
874
- captureRValSV (substr (std::string ()), s ); // expected-warning {{object whose reference is captured by 's '}}
875
- captureRValSV (strcopy (std::string ()), s );
876
- noCaptureSV (local_sv, s );
877
- noCaptureSV (std::string (), s );
878
- noCaptureSV (substr (std::string ()), s );
866
+ std::string () // expected-warning {{object whose reference is captured by 'x '}}
867
+ ), x );
868
+ captureSV (substr (local_s), x );
869
+ captureSV (strcopy (std::string ()), x );
870
+ captureRValSV (std::move (local_sv), x );
871
+ captureRValSV (std::string (), x ); // expected-warning {{object whose reference is captured by 'x '}}
872
+ captureRValSV (std::string_view{" abcd" }, x );
873
+ captureRValSV (substr (local_s), x );
874
+ captureRValSV (substr (std::string ()), x ); // expected-warning {{object whose reference is captured by 'x '}}
875
+ captureRValSV (strcopy (std::string ()), x );
876
+ noCaptureSV (local_sv, x );
877
+ noCaptureSV (std::string (), x );
878
+ noCaptureSV (substr (std::string ()), x );
879
879
880
880
// Capture using std::string.
881
- captureS (std::string (), s ); // expected-warning {{object whose reference is captured by 's '}}
882
- captureS (local_s, s );
883
- captureRValS (std::move (local_s), s );
884
- captureRValS (std::string (), s ); // expected-warning {{object whose reference is captured by 's '}}
881
+ captureS (std::string (), x ); // expected-warning {{object whose reference is captured by 'x '}}
882
+ captureS (local_s, x );
883
+ captureRValS (std::move (local_s), x );
884
+ captureRValS (std::string (), x ); // expected-warning {{object whose reference is captured by 'x '}}
885
885
886
886
// Capture with lifetimebound.
887
- captureSV (getLB (std::string ()), s ); // expected-warning {{object whose reference is captured by 's '}}
888
- captureSV (getLB (substr (std::string ())), s ); // expected-warning {{object whose reference is captured by 's '}}
887
+ captureSV (getLB (std::string ()), x ); // expected-warning {{object whose reference is captured by 'x '}}
888
+ captureSV (getLB (substr (std::string ())), x ); // expected-warning {{object whose reference is captured by 'x '}}
889
889
captureSV (getLB (getLB (
890
- std::string () // expected-warning {{object whose reference is captured by 's '}}
891
- )), s );
892
- capturePointer (getPointerLB (std::string ()), s ); // expected-warning {{object whose reference is captured by 's '}}
890
+ std::string () // expected-warning {{object whose reference is captured by 'x '}}
891
+ )), x );
892
+ capturePointer (getPointerLB (std::string ()), x ); // expected-warning {{object whose reference is captured by 'x '}}
893
893
capturePointer (getPointerLB (*getPointerLB (
894
- std::string () // expected-warning {{object whose reference is captured by 's '}}
895
- )), s );
896
- capturePointer (getPointerNoLB (std::string ()), s );
894
+ std::string () // expected-warning {{object whose reference is captured by 'x '}}
895
+ )), x );
896
+ capturePointer (getPointerNoLB (std::string ()), x );
897
897
898
898
// Member functions.
899
- s .captureInt (1 ); // expected-warning {{object whose reference is captured by 's '}}
900
- s .captureSV (std::string ()); // expected-warning {{object whose reference is captured by 's '}}
901
- s .captureSV (substr (std::string ())); // expected-warning {{object whose reference is captured by 's '}}
902
- s .captureSV (strcopy (std::string ()));
899
+ x .captureInt (1 ); // expected-warning {{object whose reference is captured by 'x '}}
900
+ x .captureSV (std::string ()); // expected-warning {{object whose reference is captured by 'x '}}
901
+ x .captureSV (substr (std::string ())); // expected-warning {{object whose reference is captured by 'x '}}
902
+ x .captureSV (strcopy (std::string ()));
903
903
904
904
// 'this' is captured.
905
- ThisIsCaptured{}.capture (s ); // expected-warning {{object whose reference is captured by 's '}}
905
+ ThisIsCaptured{}.capture (x ); // expected-warning {{object whose reference is captured by 'x '}}
906
906
ThisIsCaptured TIS;
907
- TIS.capture (s );
907
+ TIS.capture (x );
908
908
909
909
// capture by global.
910
910
captureByGlobal (std::string ()); // expected-warning {{object whose reference is captured will be destroyed at the end of the full-expression}}
0 commit comments