[PATCH] D122075: [clang-tidy] Skip parentheses in `readability-make-member-function-const`
Evgeny Shulgin via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 21 04:18:24 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfc354d375232: [clang-tidy] Skip parentheses in `readability-make-member-function-const` (authored by Izaron).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D122075/new/
https://reviews.llvm.org/D122075
Files:
clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/readability-make-member-function-const.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/readability-make-member-function-const.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/readability-make-member-function-const.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-make-member-function-const.cpp
@@ -40,6 +40,12 @@
return ConstM;
}
+ int read_fields_in_parentheses() {
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: method 'read_fields_in_parentheses' can be made const
+ // CHECK-FIXES: {{^}} int read_fields_in_parentheses() const {
+ return (this)->M + (((((Struct.M))))) + ((this->ConstM));
+ }
+
void call_const_member() {
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: method 'call_const_member' can be made const
// CHECK-FIXES: {{^}} void call_const_member() const {
Index: clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp
@@ -66,6 +66,13 @@
return Parents.begin()->get<T>();
}
+ const Expr *getParentExprIgnoreParens(const Expr *E) {
+ const Expr *Parent = getParent<Expr>(E);
+ while (isa_and_nonnull<ParenExpr>(Parent))
+ Parent = getParent<Expr>(Parent);
+ return Parent;
+ }
+
bool VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *) {
// An UnresolvedMemberExpr might resolve to a non-const non-static
// member function.
@@ -140,7 +147,7 @@
return true;
}
- const auto *Parent = getParent<Expr>(Member);
+ const auto *Parent = getParentExprIgnoreParens(Member);
if (const auto *Cast = dyn_cast_or_null<ImplicitCastExpr>(Parent)) {
// A read access to a member is safe when the member either
@@ -167,12 +174,12 @@
bool VisitCXXThisExpr(const CXXThisExpr *E) {
Usage = Const;
- const auto *Parent = getParent<Expr>(E);
+ const auto *Parent = getParentExprIgnoreParens(E);
// Look through deref of this.
if (const auto *UnOp = dyn_cast_or_null<UnaryOperator>(Parent)) {
if (UnOp->getOpcode() == UO_Deref) {
- Parent = getParent<Expr>(UnOp);
+ Parent = getParentExprIgnoreParens(UnOp);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122075.416890.patch
Type: text/x-patch
Size: 2367 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220321/80b5e190/attachment.bin>
More information about the cfe-commits
mailing list