1 // RUN: %clang_cc1 -fsyntax-only -std=c++2b -Woverloaded-virtual %s -verify
4 // FIXME: can we improve these diagnostics?
5 void f(this); // expected-error{{variable has incomplete type 'void'}} \
6 // expected-error{{invalid use of 'this' outside of a non-static member function}}
8 void g(this auto); // expected-error{{an explicit object parameter cannot appear in a non-member function}}
10 auto l1
= [] (this auto) static {}; // expected-error{{an explicit object parameter cannot appear in a static lambda}}
11 auto l2
= [] (this auto) mutable {}; // expected-error{{a lambda with an explicit object parameter cannot be mutable}}
12 auto l3
= [](this auto...){}; // expected-error {{the explicit object parameter cannot be a function parameter pack}}
13 auto l4
= [](int, this auto){}; // expected-error {{an explicit object parameter can only appear as the first parameter of the lambda}}
16 static void f(this auto); // expected-error{{an explicit object parameter cannot appear in a static function}}
17 virtual void f(this S
); // expected-error{{an explicit object parameter cannot appear in a virtual function}}
19 // new and delete are implicitly static
20 void *operator new(this unsigned long); // expected-error{{an explicit object parameter cannot appear in a static function}}
21 void operator delete(this void*); // expected-error{{an explicit object parameter cannot appear in a static function}}
23 void g(this auto) const; // expected-error{{explicit object member function cannot have 'const' qualifier}}
24 void h(this auto) &; // expected-error{{explicit object member function cannot have '&' qualifier}}
25 void i(this auto) &&; // expected-error{{explicit object member function cannot have '&&' qualifier}}
26 void j(this auto) volatile; // expected-error{{explicit object member function cannot have 'volatile' qualifier}}
27 void k(this auto) __restrict
; // expected-error{{explicit object member function cannot have '__restrict' qualifier}}
28 void l(this auto) _Nonnull
; // expected-error{{explicit object member function cannot have '' qualifie}}
31 void variadic(this auto...); // expected-error{{the explicit object parameter cannot be a function parameter pack}}
32 void not_first(int, this auto); // expected-error {{an explicit object parameter can only appear as the first parameter of the function}}
34 S(this auto); // expected-error {{an explicit object parameter cannot appear in a constructor}}
35 ~S(this S
) {} // expected-error {{an explicit object parameter cannot appear in a destructor}} \
36 // expected-error {{destructor cannot have any parameters}}
41 virtual void f(); // expected-note 2{{here}}
42 virtual void g(int); // expected-note {{here}}
43 virtual void h() const; // expected-note 5{{here}}
48 int f(this B
&, int); // expected-warning {{hides overloaded virtual function}}
49 int f(this B
&); // expected-error {{an explicit object parameter cannot appear in a virtual function}}
50 int g(this B
&); // expected-warning {{hides overloaded virtual function}}
51 int h(this B
&); // expected-error {{an explicit object parameter cannot appear in a virtual function}}
52 int h(this B
&&); // expected-error {{an explicit object parameter cannot appear in a virtual function}}
53 int h(this const B
&&); // expected-error {{an explicit object parameter cannot appear in a virtual function}}
54 int h(this A
&); // expected-error {{an explicit object parameter cannot appear in a virtual function}}
55 int h(this int); // expected-error {{an explicit object parameter cannot appear in a virtual function}}
59 namespace DefaultArgs
{
60 struct Test
{ void f(this const auto& = Test
{}); };
61 // expected-error@-1 {{the explicit object parameter cannot have a default argument}}
62 auto L
= [](this const auto& = Test
{}){};
63 // expected-error@-1 {{the explicit object parameter cannot have a default argument}}
66 struct CannotUseThis
{
70 this->fun(); // expected-error{{invalid use of 'this' in a function with an explicit object parameter}}
71 fun(); // expected-error {{call to non-static member function without an object argument}}
72 m
= 0; // expected-error {{invalid use of member 'm' in explicit object member function}}
76 struct CannotUseThisBase
{
82 struct CannotUseThisDerived
: CannotUseThisBase
{
84 foo(); // expected-error {{call to non-static member function without an object argument}}
85 n
= 12; // expected-error {{invalid use of member 'n' in explicit object member function}}
90 namespace ThisInLambdaWithCaptures
{
98 [i
= 0](this Test
) { }();
99 // expected-error@-1 {{invalid explicit object parameter type 'ThisInLambdaWithCaptures::Test' in lambda with capture; the type must be the same as, or derived from, the lambda}}
102 auto ok
= [i
= 0](this const Derived
&) {};
103 auto ko
= [i
= 0](this const Test
&) {};
104 // expected-error@-1 {{invalid explicit object parameter type 'ThisInLambdaWithCaptures::Test' in lambda with capture; the type must be the same as, or derived from, the lambda}}
106 struct Derived
: decltype(ok
){};
110 struct DerivedErr
: decltype(ko
){};
114 auto alsoOk
= [](this const Test
&) {};
119 auto nothingIsOkay
= [i
= 0](this const Frobble
&) {}; // expected-note {{candidate function not viable: requires 0 non-object arguments, but 1 was provided}}
122 nothingIsOkay(f
); // expected-error {{no matching function for call to object of type}}
127 struct Corresponding
{
128 void a(this Corresponding
&); // expected-note 2{{here}}
129 void a(); // expected-error{{cannot be redeclared}}
130 void a() &; // expected-error{{cannot be redeclared}}
131 void a(this Corresponding
&, int);
132 void a(this Corresponding
&, double);
134 void b(this const Corresponding
&); // expected-note 2{{here}}
135 void b() const; // expected-error{{cannot be redeclared}}
136 void b() const &; // expected-error{{cannot be redeclared}}
138 void c(this Corresponding
&&); // expected-note {{here}}
139 void c() &&; // expected-error{{cannot be redeclared}}
141 void d(this Corresponding
&);
142 void d(this Corresponding
&&);
143 void d(this const Corresponding
&);
144 void d(this const int&);
145 void d(this const int); // expected-note {{previous declaration is here}}
146 void d(this int); // expected-error {{class member cannot be redeclared}}
148 void e(this const Corresponding
&&); // expected-note {{here}}
149 void e() const &&; // expected-error{{cannot be redeclared}}
153 template <typename T
>
154 struct CorrespondingTpl
{
155 void a(this CorrespondingTpl
&); // expected-note 2{{here}}
156 void a(); // expected-error{{cannot be redeclared}}
157 void a() &; // expected-error{{cannot be redeclared}}
158 void a(this Corresponding
&, int);
159 void a(this Corresponding
&, double);
163 void b(this const CorrespondingTpl
&); // expected-note 2{{here}}
164 void b() const; // expected-error{{cannot be redeclared}}
165 void b() const &; // expected-error{{cannot be redeclared}}
167 void c(this CorrespondingTpl
&&); // expected-note {{here}}
168 void c() &&; // expected-error{{cannot be redeclared}}
170 void d(this Corresponding
&);
171 void d(this Corresponding
&&);
172 void d(this const Corresponding
&);
173 void d(this const int&);
174 void d(this const int); // expected-note {{previous declaration is here}}
175 void d(this int); // expected-error {{class member cannot be redeclared}}
176 void e(this const CorrespondingTpl
&&); // expected-note {{here}}
177 void e() const &&; // expected-error{{cannot be redeclared}}
181 template <typename T
>
186 (void)[=](this auto&&) { return i
; }();
187 (void)[=](this const auto&) { return i
; }();
188 (void)[i
](this C
) { return i
; }(); // expected-error{{invalid explicit object parameter type 'C'}}
189 (void)[=](this C
) { return i
; }(); // expected-error{{invalid explicit object parameter type 'C'}}
190 (void)[](this C
) { return 42; }();
191 auto l
= [=](this auto&) {};
192 struct D
: decltype(l
) {};
197 void TestMutationInLambda() {
198 [i
= 0](this auto &&){ i
++; }();
199 [i
= 0](this auto){ i
++; }();
200 [i
= 0](this const auto&){ i
++; }(); // expected-error {{cannot assign to a variable captured by copy in a non-mutable lambda}}
203 const auto l1
= [x
](this auto&) { x
= 42; }; // expected-error {{cannot assign to a variable captured by copy in a non-mutable lambda}}
204 const auto l2
= [=](this auto&) { x
= 42; }; // expected-error {{cannot assign to a variable captured by copy in a non-mutable lambda}}
206 const auto l3
= [&x
](this auto&) {
207 const auto l3a
= [x
](this auto&) { x
= 42; }; // expected-error {{cannot assign to a variable captured by copy in a non-mutable lambda}}
208 l3a(); // expected-note {{in instantiation of}}
211 const auto l4
= [&x
](this auto&) {
212 const auto l4a
= [=](this auto&) { x
= 42; }; // expected-error {{cannot assign to a variable captured by copy in a non-mutable lambda}}
213 l4a(); // expected-note {{in instantiation of}}
216 const auto l5
= [x
](this auto&) {
217 const auto l5a
= [x
](this auto&) { x
= 42; }; // expected-error {{cannot assign to a variable captured by copy in a non-mutable lambda}}
218 l5a(); // expected-note {{in instantiation of}}
221 const auto l6
= [=](this auto&) {
222 const auto l6a
= [=](this auto&) { x
= 42; }; // expected-error {{cannot assign to a variable captured by copy in a non-mutable lambda}}
223 l6a(); // expected-note {{in instantiation of}}
226 const auto l7
= [x
](this auto&) {
227 const auto l7a
= [=](this auto&) { x
= 42; }; // expected-error {{cannot assign to a variable captured by copy in a non-mutable lambda}}
228 l7a(); // expected-note {{in instantiation of}}
231 const auto l8
= [=](this auto&) {
232 const auto l8a
= [x
](this auto&) { x
= 42; }; // expected-error {{cannot assign to a variable captured by copy in a non-mutable lambda}}
233 l8a(); // expected-note {{in instantiation of}}
236 const auto l9
= [&](this auto&) {
237 const auto l9a
= [x
](this auto&) { x
= 42; }; // expected-error {{cannot assign to a variable captured by copy in a non-mutable lambda}}
238 l9a(); // expected-note {{in instantiation of}}
241 const auto l10
= [&](this auto&) {
242 const auto l10a
= [=](this auto&) { x
= 42; }; // expected-error {{cannot assign to a variable captured by copy in a non-mutable lambda}}
243 l10a(); // expected-note {{in instantiation of}}
246 const auto l11
= [x
](this auto&) {
247 const auto l11a
= [&x
](this auto&) { x
= 42; }; // expected-error {{cannot assign to a variable captured by copy in a non-mutable lambda}} expected-note {{while substituting}}
251 const auto l12
= [x
](this auto&) {
252 const auto l12a
= [&](this auto&) { x
= 42; }; // expected-error {{cannot assign to a variable captured by copy in a non-mutable lambda}} expected-note {{while substituting}}
256 const auto l13
= [=](this auto&) {
257 const auto l13a
= [&x
](this auto&) { x
= 42; }; // expected-error {{cannot assign to a variable captured by copy in a non-mutable lambda}} expected-note {{while substituting}}
264 return [*this] (this auto&&) {
265 x
= 42; // expected-error {{read-only variable is not assignable}}
266 [*this] () mutable { x
= 42; } ();
267 [*this] (this auto&&) { x
= 42; } ();
268 [*this] () { x
= 42; } (); // expected-error {{read-only variable is not assignable}}
269 const auto l
= [*this] (this auto&&) { x
= 42; }; // expected-error {{read-only variable is not assignable}}
270 l(); // expected-note {{in instantiation of}}
275 return [&] (this auto&&) {
277 const auto l
= [*this] (this auto&&) { x
= 42; }; // expected-error {{read-only variable is not assignable}}
278 l(); // expected-note {{in instantiation of}}
283 const auto l2
= T
{}.g();
284 l2(); // expected-note {{in instantiation of}}
289 const auto l14
= S
{}.f();
291 l1(); // expected-note {{in instantiation of}}
292 l2(); // expected-note {{in instantiation of}}
293 l3(); // expected-note {{in instantiation of}}
294 l4(); // expected-note {{in instantiation of}}
295 l5(); // expected-note {{in instantiation of}}
296 l6(); // expected-note {{in instantiation of}}
297 l7(); // expected-note {{in instantiation of}}
298 l8(); // expected-note {{in instantiation of}}
299 l9(); // expected-note {{in instantiation of}}
300 l10(); // expected-note {{in instantiation of}}
301 l11(); // expected-note {{in instantiation of}}
302 l12(); // expected-note {{in instantiation of}}
303 l13(); // expected-note {{in instantiation of}}
304 l14(); // expected-note 3 {{in instantiation of}}
307 const auto l1
= [&x
](this auto&) { x
= 42; };
308 const auto l2
= [&](this auto&) { x
= 42; };
313 // Check that we don't crash if the lambda has type sugar.
314 const auto l15
= [=](this auto&&) [[clang::annotate_type("foo")]] [[clang::annotate_type("bar")]] {
318 const auto l16
= [=]() [[clang::annotate_type("foo")]] [[clang::annotate_type("bar")]] {
326 struct Over_Call_Func_Example
{
329 a(); // ok, (*this).a()
332 void f(this const Over_Call_Func_Example
&); // expected-note {{here}}
334 f(); // ok: (*this).f()
335 f(*this); // expected-error{{too many non-object arguments to function call}}
340 f(); // expected-error{{call to non-static member function without an object argument}}
341 f(Over_Call_Func_Example
{}); // expected-error{{call to non-static member function without an object argument}}
342 Over_Call_Func_Example
{}.f(); // ok
346 operator int() const;
347 void m(this const Over_Call_Func_Example
& c
) {
352 struct AmbiguousConversion
{
353 void f(this int); // expected-note {{candidate function}}
354 void f(this float); // expected-note {{candidate function}}
356 operator int() const;
357 operator float() const;
359 void test(this const AmbiguousConversion
&s
) {
360 s
.f(); // expected-error {{call to member function 'f' is ambiguous}}
366 operator int() const;
367 void test(this const IntToShort
&val
) {
374 operator short() const;
375 void test(this const ShortToInt
&val
) {
380 namespace arity_diagnostics
{
382 void f(this auto &&, auto, auto); // expected-note {{requires 2 non-object arguments, but 0 were provided}}
383 void g(this auto &&, auto, auto); // expected-note {{requires 2 non-object arguments, but 3 were provided}}
384 void h(this auto &&, int, int i
= 0); // expected-note {{requires at least 1 non-object argument, but 0 were provided}}
385 void i(this S
&&, int); // expected-note 2{{declared here}}
389 void(*f
)(S
&&, int, int) = &S::f
;
391 f(S
{}, 1); // expected-error {{too few arguments to function call, expected 3, have 2}}
392 f(S
{}); // expected-error {{too few arguments to function call, expected 3, have 1}}
393 f(S
{}, 1, 2, 3); //expected-error {{too many arguments to function call, expected 3, have 4}}
396 S
{}.f(); // expected-error{{no matching member function for call to 'f'}}
397 S
{}.g(1,2,3); // expected-error {{no matching member function for call to 'g'}}
398 S
{}.h(); // expected-error {{no matching member function for call to 'h'}}
399 S
{}.i(); // expected-error {{too few non-object arguments to function call, expected 1, have 0}}
400 S
{}.i(1, 2, 3); // expected-error {{too many non-object arguments to function call, expected 1, have 3}}
405 namespace AddressOf
{
409 void f(this auto &&) {}
410 void g(this s
&&) {};
414 F
* a
= &f
; // expected-error {{must explicitly qualify name of member function when taking its address}}
415 F
* b
= &g
; // expected-error {{must explicitly qualify name of member function when taking its address}}
432 struct strong_ordering
{
434 constexpr operator int() const { return n
; }
435 static const strong_ordering equal
, greater
, less
;
437 constexpr strong_ordering
strong_ordering::equal
= {0};
438 constexpr strong_ordering
strong_ordering::greater
= {1};
439 constexpr strong_ordering
strong_ordering::less
= {-1};
441 template<typename T
> constexpr __remove_reference_t(T
)&& move(T
&& t
) noexcept
{
442 return static_cast<__remove_reference_t(T
)&&>(t
);
446 namespace operators_deduction
{
448 template <typename T
, typename U
>
449 constexpr bool is_same
= false;
451 template <typename T
>
452 constexpr bool is_same
<T
, T
> = true;
454 template <template <typename
> typename T
>
458 operator int(this auto&& self
) {
459 static_assert(is_same
<decltype(self
), typename T
<S
>::type
>);
462 Wrap
* operator->(this auto&& self
) {
463 static_assert(is_same
<decltype(self
), typename T
<S
>::type
>);
466 int operator[](this auto&& self
, int) {
467 static_assert(is_same
<decltype(self
), typename T
<S
>::type
>);
470 int operator()(this auto&& self
, int) {
471 static_assert(is_same
<decltype(self
), typename T
<S
>::type
>);
474 int operator++(this auto&& self
, int) {
475 static_assert(is_same
<decltype(self
), typename T
<S
>::type
>);
478 int operator++(this auto&& self
) {
479 static_assert(is_same
<decltype(self
), typename T
<S
>::type
>);
482 int operator--(this auto&& self
, int) {
483 static_assert(is_same
<decltype(self
), typename T
<S
>::type
>);
486 int operator--(this auto&& self
) {
487 static_assert(is_same
<decltype(self
), typename T
<S
>::type
>);
490 int operator*(this auto&& self
) {
491 static_assert(is_same
<decltype(self
), typename T
<S
>::type
>);
494 bool operator==(this auto&& self
, int) {
495 static_assert(is_same
<decltype(self
), typename T
<S
>::type
>);
498 bool operator<=>(this auto&& self
, int) {
499 static_assert(is_same
<decltype(self
), typename T
<S
>::type
>);
502 bool operator<<(this auto&& self
, int b
) {
503 static_assert(is_same
<decltype(self
), typename T
<S
>::type
>);
509 template <typename T
>
510 struct lvalue_reference
{
513 template <typename T
>
514 struct const_lvalue_reference
{
515 using type
= const T
&;
517 template <typename T
>
518 struct volatile_lvalue_reference
{
519 using type
= volatile T
&;
521 template <typename T
>
522 struct rvalue_reference
{
525 template <typename T
>
526 struct const_rvalue_reference
{
527 using type
= const T
&&;
533 Wrap
<lvalue_reference
>::S s
;
559 const Wrap
<const_lvalue_reference
>::S s
;
585 volatile Wrap
<volatile_lvalue_reference
>::S s
;
611 Wrap
<rvalue_reference
>::S s
;
612 using M
= Wrap
<rvalue_reference
>::S
&&;
614 ((M
)s
).operator++(0);
618 ((M
)s
).operator--(0);
622 ((M
)s
).operator[](0);
624 ((M
)s
).operator()(0);
631 ((M
)s
).operator<<(0);
633 ((M
)s
).operator==(0);
634 (void)(((M
)s
) <=> 0);
635 ((M
)s
).operator<=>(0);
640 namespace conversions
{
642 struct Y
{ Y(int); }; //expected-note 3{{candidate}}
643 struct A
{ operator int(this auto&&); }; //expected-note {{candidate}}
644 Y y1
= A(); // expected-error{{no viable conversion from 'A' to 'Y'}}
646 struct X
{ X(); }; //expected-note 3{{candidate}}
647 struct B
{ operator X(this auto&&); };
649 X x
{{b
}}; // expected-error{{no matching constructor for initialization of 'X'}}
651 struct T
{}; // expected-note 2{{candidate constructor}}
653 operator T (this int); // expected-note {{candidate function not viable: no known conversion from 'C' to 'int' for object argument}}
654 operator int() const; // expected-note {{candidate function}}
658 T d
= c
; // expected-error {{no viable conversion from 'C' to 'T'}}
663 namespace surrogate
{
666 operator fn_t
* (this C
const &);
678 S(this auto &self
) {} // expected-error {{an explicit object parameter cannot appear in a constructor}}
679 virtual void f(this S self
) {} // expected-error {{an explicit object parameter cannot appear in a virtual function}}
680 void g(this auto &self
) const {} // expected-error {{explicit object member function cannot have 'const' qualifier}}
681 void h(this S self
= S
{}) {} // expected-error {{the explicit object parameter cannot have a default argument}}
682 void i(int i
, this S self
= S
{}) {} // expected-error {{an explicit object parameter can only appear as the first parameter of the function}}
683 ~S(this S
&&self
); // expected-error {{an explicit object parameter cannot appear in a destructor}} \
684 // expected-error {{destructor cannot have any parameters}}
686 static void j(this S s
); // expected-error {{an explicit object parameter cannot appear in a static function}}
689 void nonmember(this S s
); // expected-error {{an explicit object parameter cannot appear in a non-member function}}
709 template<typename Self
, typename
... Args
>
710 Thing(this Self
&& self
, Args
&& ... args
) { } // expected-error {{an explicit object parameter cannot appear in a constructor}}
713 class Server
: public Thing
{
722 S
& operator=(this Base
& self
, const S
&) = default;
723 // expected-warning@-1 {{explicitly defaulted copy assignment operator is implicitly deleted}}
724 // expected-note@-2 {{function is implicitly deleted because its declared type does not match the type of an implicit copy assignment operator}}
725 // expected-note@-3 {{explicitly defaulted function was implicitly deleted here}}
729 S2
& operator=(this int&& self
, const S2
&);
730 S2
& operator=(this int&& self
, S2
&&);
734 S2
& S2::operator=(this int&& self
, const S2
&) = default;
735 // expected-error@-1 {{the type of the explicit object parameter of an explicitly-defaulted copy assignment operator should be reference to 'S2'}}
737 S2
& S2::operator=(this int&& self
, S2
&&) = default;
738 // expected-error@-1 {{the type of the explicit object parameter of an explicitly-defaulted move assignment operator should be reference to 'S2'}}
741 Move
& operator=(this int&, Move
&&) = default;
742 // expected-warning@-1 {{explicitly defaulted move assignment operator is implicitly deleted}}
743 // expected-note@-2 {{function is implicitly deleted because its declared type does not match the type of an implicit move assignment operator}}
744 // expected-note@-3 {{copy assignment operator is implicitly deleted because 'Move' has a user-declared move assignment operator}}
749 s
= s
; // expected-error {{object of type 'S' cannot be assigned because its copy assignment operator is implicitly deleted}}
754 m
= Move
{}; // expected-error {{object of type 'Move' cannot be assigned because its copy assignment operator is implicitly deleted}}
761 auto serialize(auto&& archive
, auto&& c
){ }
763 auto serialize(this auto&& self
, auto&& archive
) {
764 serialize(archive
, self
); // expected-error {{call to explicit member function without an object argument}}
771 auto f(this auto self
...) { }
784 return [*this](this auto&&) {
785 x
= 10; // expected-error {{read-only variable is not assignable}}
792 const auto l
= s
.foo();
793 l(); // expected-note {{in instantiation of}}
795 const auto g
= [x
= 10](this auto&& self
) { x
= 20; }; // expected-error {{cannot assign to a variable captured by copy in a non-mutable lambda}}
796 g(); // expected-note {{in instantiation of}}
806 struct mutex
{} cursor_guard
;
807 [&cursor_guard
](this auto self
) {
808 unique_lock
a(cursor_guard
);
814 struct function
{}; // expected-note 2 {{not viable}}
817 [&list
](this auto self
) {
818 list
= self
; // expected-error {{no viable overloaded '='}}
819 }(); // expected-note {{in instantiation of}}
823 function2
& operator=(function2
const&) = delete; // expected-note {{candidate function not viable}}
827 [&list
](this auto self
) {
828 list
= self
; // expected-error {{no viable overloaded '='}}
829 }(); // expected-note {{in instantiation of}}
833 function3
& operator=(function3
const&) = delete; // expected-note {{has been explicitly deleted}}
837 [&list
](this auto self
) {
838 list
= function3
{}; // expected-error {{selected deleted operator '='}}
846 void operator+=(this auto &&, const char (&)[N
]);
847 void operator+=(this auto &&, auto &&) = delete;
849 void f1(this A
&, auto &);
850 void f1(this A
&, auto &&) = delete;
853 void f2(this auto&&) = delete;
856 void f3(this A
&, auto&&) = delete;
858 void f4(auto&&) & = delete;
859 void f4(this A
&, auto&);
861 static void f5(auto&);
862 void f5(this A
&, auto&&) = delete;
864 static void f6(auto&&) = delete;
865 void f6(this A
&, auto&);
867 void implicit_this() {
878 void operator-(this A
&, auto&&) = delete;
879 friend void operator-(A
&, auto&);
881 void operator*(this A
&, auto&);
882 friend void operator*(A
&, auto&&) = delete;
902 int bar(void) { return 55; }
903 int (&fref
)(void) = bar
;
906 void c(this const C
&); // #first
907 void c() &; // #second
908 static void c(int = 0); // #third
911 c(); // expected-error {{call to member function 'c' is ambiguous}}
912 // expected-note@#first {{candidate function}}
913 // expected-note@#second {{candidate function}}
914 // expected-note@#third {{candidate function}}
916 (C::c
)(); // expected-error {{call to member function 'c' is ambiguous}}
917 // expected-note@#first {{candidate function}}
918 // expected-note@#second {{candidate function}}
919 // expected-note@#third {{candidate function}}
921 (&(C::c
))(); // expected-error {{cannot create a non-constant pointer to member function}}
923 (&C::c
)(*this); // expected-error {{call to non-static member function without an object argument}}
941 int (S::*x
)(this int); // expected-error {{an explicit object parameter can only appear as the first parameter of a member function}}
942 int (*y
)(this int); // expected-error {{an explicit object parameter can only appear as the first parameter of a member function}}
943 int (***z
)(this int); // expected-error {{an explicit object parameter can only appear as the first parameter of a member function}}
947 friend int h(this S
); // expected-error {{an explicit object parameter cannot appear in a non-member function}}
948 int h(int x
, int (*)(this S
)); // expected-error {{an explicit object parameter can only appear as the first parameter of a member function}}
954 friend int T::f(this T
);
955 friend int N::A::f(this N::A
);
956 friend int N::f(this N::A
); // expected-error {{an explicit object parameter cannot appear in a non-member function}}
957 int friend func(this T
); // expected-error {{an explicit object parameter cannot appear in a non-member function}}
960 using T
= int (*)(this int); // expected-error {{an explicit object parameter can only appear as the first parameter of a member function}}
961 using U
= int (S::*)(this int); // expected-error {{an explicit object parameter can only appear as the first parameter of a member function}}
962 int h(this int); // expected-error {{an explicit object parameter cannot appear in a non-member function}}
964 int S::f(this S
) { return 1; }
969 void a::f(this auto) {} // expected-error {{an explicit object parameter cannot appear in a non-member function}}
976 void operator()(this X
);
981 [x
= X
{}](this auto) {}();
985 std::move([x
= X
{}](this auto) {})();
987 } // namespace GH100341
989 void f(this auto &&self
, int &&r_value_ref
) {} // expected-note {{candidate function template not viable: expects an rvalue for 2nd argument}}
990 void g(int &&r_value_ref
) {
991 f(r_value_ref
); // expected-error {{no matching member function for call to 'f'}}
997 bool operator == (this const int&, const A
&);
999 bool A::operator == (this const int&, const A
&) = default;
1000 // expected-error@-1 {{invalid parameter type for defaulted equality comparison operator; found 'const int &', expected 'const GH100329::A &'}}
1001 } // namespace GH100329
1003 namespace defaulted_assign
{
1005 A
& operator=(this A
, const A
&) = default;
1006 // expected-warning@-1 {{explicitly defaulted copy assignment operator is implicitly deleted}}
1007 // expected-note@-2 {{function is implicitly deleted because its declared type does not match the type of an implicit copy assignment operator}}
1008 A
& operator=(this int, const A
&) = default;
1009 // expected-warning@-1 {{explicitly defaulted copy assignment operator is implicitly deleted}}
1010 // expected-note@-2 {{function is implicitly deleted because its declared type does not match the type of an implicit copy assignment operator}}
1012 } // namespace defaulted_assign
1014 namespace defaulted_compare
{
1016 bool operator==(this A
&, const A
&) = default;
1017 // expected-error@-1 {{defaulted member equality comparison operator must be const-qualified}}
1018 bool operator==(this const A
, const A
&) = default;
1019 // expected-error@-1 {{invalid parameter type for defaulted equality comparison operator; found 'const A', expected 'const defaulted_compare::A &'}}
1020 bool operator==(this A
, A
) = default;
1024 bool operator==(this B
, B
) = default;
1026 static_assert(B
{0} == B
{0});
1027 static_assert(B
{0} != B
{1});
1030 static_assert(__is_same(X
<B
{0}>, X
<B
{0}>));
1031 static_assert(!__is_same(X
<B
{0}>, X
<B
{1}>));
1032 } // namespace defaulted_compare
1034 namespace static_overloaded_operator
{
1037 static void operator()(const char (&)[N
]);
1038 void operator()(this auto &&, auto &&);
1040 void implicit_this() {
1047 void operator()(this auto &&, const char (&)[N
]);
1048 static void operator()(auto &&);
1050 void implicit_this() {
1057 static void operator[](const char (&)[N
]);
1058 void operator[](this auto &&, auto &&);
1060 void implicit_this() {
1067 void operator[](this auto &&, const char (&)[N
]);
1068 static void operator[](auto &&);
1070 void implicit_this() {
1075 } // namespace static_overloaded_operator
1077 namespace GH102025
{
1080 constexpr auto operator[](this T
&&self
, auto... i
) // expected-note {{candidate template ignored: substitution failure [with T = Foo &, i:auto = <>]: member '_evaluate' used before its declaration}}
1081 -> decltype(_evaluate(self
, i
...)) {
1082 return self
._evaluate(i
...);
1087 constexpr auto _evaluate(this T
&&self
, auto... i
) -> decltype((i
+ ...));
1092 return foo
[]; // expected-error {{no viable overloaded operator[] for type 'Foo'}}
1096 namespace GH100394
{
1098 void f(this const C1
);
1099 void f() const; // ok
1103 void f(this const C2
); // expected-note {{previous declaration is here}}
1104 void f(this volatile C2
); // expected-error {{class member cannot be redeclared}} \
1105 // expected-warning {{volatile-qualified parameter type 'volatile C2' is deprecated}}
1109 void f(this volatile C3
); // expected-note {{previous declaration is here}} \
1110 // expected-warning {{volatile-qualified parameter type 'volatile C3' is deprecated}}
1111 void f(this const C3
); // expected-error {{class member cannot be redeclared}}
1115 void f(this const C4
); // expected-note {{previous declaration is here}}
1116 void f(this const volatile C4
); // expected-error {{class member cannot be redeclared}} \
1117 // expected-warning {{volatile-qualified parameter type 'const volatile C4' is deprecated}}
1122 namespace GH112559
{
1125 constexpr operator Wrap (this const S
& self
) {
1128 constexpr int operator <<(this Wrap self
, int i
) {
1132 // Purposefully invalid expression to check an assertion in the
1133 // expression recovery machinery.
1134 static_assert((S
{} << 11) == a
);
1135 // expected-error@-1 {{use of undeclared identifier 'a'}}