forked from SonarOpenCommunity/sonar-cxx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- [Explicit object parameter (deducing this)](https://en.cppreference.com/w/cpp/language/member_functions#Expli) [P0847R7](https://wg21.link/P0847R7) - linked SonarOpenCommunity#2536
- Loading branch information
Showing
4 changed files
with
46 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
cxx-squid/src/test/resources/parser/own/C++23/deducing-this.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
struct X { | ||
void foo(this X const& self, int i); // same as void foo(int i) const &; | ||
// void foo(int i) const &; // Error: already declared | ||
void bar(this X self, int i); // pass object by value: makes a copy of “*this” | ||
}; | ||
|
||
struct Y { | ||
template<typename Self> | ||
void foo(this Self&&, int); | ||
}; | ||
|
||
struct D : Y {}; | ||
|
||
void ex(Y& y, D& d) | ||
{ | ||
y.foo(1); // Self = Y& | ||
move(x).foo(2); // Self = Y | ||
d.foo(3); // Self = D& | ||
} | ||
|
||
// a CRTP trait | ||
struct add_postfix_increment { | ||
template<typename Self> | ||
auto operator++(this Self&& self, int) { | ||
auto tmp = self; // Self deduces to "some_type" | ||
++self; | ||
return tmp; | ||
} | ||
}; | ||
|
||
struct some_type : add_postfix_increment { | ||
some_type& operator++() { /*...*/ } | ||
}; |