[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 02:47:37 PDT 2022
Izaron updated this revision to Diff 416870.
Izaron added a comment.
Fixed as suggested by njames93. Thank you!
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.416870.patch
Type: text/x-patch
Size: 2367 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220321/9a1bc934/attachment-0001.bin>
More information about the cfe-commits
mailing list