File tree Expand file tree Collapse file tree 3 files changed +50
-7
lines changed Expand file tree Collapse file tree 3 files changed +50
-7
lines changed Original file line number Diff line number Diff line change @@ -11353,12 +11353,14 @@ void Sema::CheckExplicitObjectMemberFunction(Declarator &D,
11353
11353
Diag(ExplicitObjectParam->getBeginLoc(),
11354
11354
diag::err_explicit_object_parameter_nonmember)
11355
11355
<< D.getSourceRange() << /*static=*/0 << IsLambda;
11356
+ D.setInvalidType();
11356
11357
}
11357
11358
11358
11359
if (D.getDeclSpec().isVirtualSpecified()) {
11359
11360
Diag(ExplicitObjectParam->getBeginLoc(),
11360
11361
diag::err_explicit_object_parameter_nonmember)
11361
11362
<< D.getSourceRange() << /*virtual=*/1 << IsLambda;
11363
+ D.setInvalidType();
11362
11364
}
11363
11365
11364
11366
if (IsLambda && FTI.hasMutableQualifier()) {
@@ -11374,16 +11376,19 @@ void Sema::CheckExplicitObjectMemberFunction(Declarator &D,
11374
11376
Diag(ExplicitObjectParam->getLocation(),
11375
11377
diag::err_explicit_object_parameter_nonmember)
11376
11378
<< D.getSourceRange() << /*non-member=*/2 << IsLambda;
11379
+ D.setInvalidType();
11377
11380
return;
11378
11381
}
11379
11382
11380
11383
// CWG2674: constructors and destructors cannot have explicit parameters.
11381
11384
if (Name.getNameKind() == DeclarationName::CXXConstructorName ||
11382
- Name.getNameKind() == DeclarationName::CXXDestructorName)
11385
+ Name.getNameKind() == DeclarationName::CXXDestructorName) {
11383
11386
Diag(ExplicitObjectParam->getBeginLoc(),
11384
11387
diag::err_explicit_object_parameter_constructor)
11385
11388
<< (Name.getNameKind() == DeclarationName::CXXDestructorName)
11386
11389
<< D.getSourceRange();
11390
+ D.setInvalidType();
11391
+ }
11387
11392
}
11388
11393
11389
11394
namespace {
Original file line number Diff line number Diff line change @@ -85,19 +85,14 @@ using ::dr2521::operator""_div;
85
85
#if __cplusplus >= 202302L
86
86
namespace dr2553 { // dr2553: 18
87
87
struct B {
88
- virtual void f (this B&); // expected-error {{an explicit object parameter cannot appear in a virtual function}} \
89
- // expected-note {{here}}
88
+ virtual void f (this B&); // expected-error {{an explicit object parameter cannot appear in a virtual function}}
90
89
static void f (this B&); // expected-error {{an explicit object parameter cannot appear in a static function}}
91
90
virtual void g (); // expected-note {{here}}
92
91
};
93
92
struct D : B {
94
93
void g (this D&); // expected-error {{an explicit object parameter cannot appear in a virtual function}}
95
94
};
96
95
97
- struct D2 : B {
98
- void f (this B&); // expected-error {{an explicit object parameter cannot appear in a virtual function}}
99
- };
100
-
101
96
}
102
97
#endif
103
98
Original file line number Diff line number Diff line change @@ -542,3 +542,46 @@ void foo(C c) {
542
542
}
543
543
544
544
}
545
+
546
+
547
+ namespace GH69838 {
548
+ struct S {
549
+ S (this auto &self) {} // expected-error {{an explicit object parameter cannot appear in a constructor}}
550
+ virtual void f (this S self) {} // expected-error {{an explicit object parameter cannot appear in a virtual function}}
551
+ void g (this auto &self) const {} // expected-error {{explicit object member function cannot have 'const' qualifier}}
552
+ void h (this S self = S{}) {} // expected-error {{the explicit object parameter cannot have a default argument}}
553
+ void i (int i, this S self = S{}) {} // expected-error {{an explicit object parameter can only appear as the first parameter of the function}}
554
+ ~S (this S &&self); // expected-error {{an explicit object parameter cannot appear in a destructor}} \
555
+ // expected-error {{destructor cannot have any parameters}}
556
+
557
+ static void j (this S s); // expected-error {{an explicit object parameter cannot appear in a static function}}
558
+ };
559
+
560
+ void nonmember (this S s); // expected-error {{an explicit object parameter cannot appear in a non-member function}}
561
+
562
+ int test () {
563
+ S s;
564
+ s.f ();
565
+ s.g ();
566
+ s.h ();
567
+ s.i (0 );
568
+ s.j ({});
569
+ nonmember (S{});
570
+ }
571
+
572
+ }
573
+
574
+ namespace GH69962 {
575
+ struct S {
576
+ S (const S&);
577
+ };
578
+
579
+ struct Thing {
580
+ template <typename Self, typename ... Args>
581
+ Thing (this Self&& self, Args&& ... args) { } // expected-error {{an explicit object parameter cannot appear in a constructor}}
582
+ };
583
+
584
+ class Server : public Thing {
585
+ S name_;
586
+ };
587
+ }
You can’t perform that action at this time.
0 commit comments