[PATCH] D129596: [clang-tidy] Avoid extra parentheses around MemberExpr
Danny Mösch via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 26 13:36:13 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0734c02b34e4: [clang-tidy] Avoid extra parentheses around MemberExpr (authored by SimplyDanny).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D129596/new/
https://reviews.llvm.org/D129596
Files:
clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp
@@ -144,3 +144,14 @@
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: 'data' should be used for accessing the data pointer instead of taking the address of the 0-th element [readability-container-data-pointer]
// CHECK-FIXES: {{^ }}return (**v)->data();{{$}}
}
+
+struct VectorHolder {
+ std::vector<int> v;
+};
+
+int *r() {
+ VectorHolder holder;
+ return &holder.v[0];
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: 'data' should be used for accessing the data pointer instead of taking the address of the 0-th element [readability-container-data-pointer]
+ // CHECK-FIXES: {{^ }}return holder.v.data();{{$}}
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -255,6 +255,9 @@
<clang-tidy/checks/readability/const-return-type>` when a pure virtual function
overrided has a const return type. Removed the fix for a virtual function.
+- Skipped addition of extra parentheses around member accesses (``a.b``) in fix-it for
+ :doc:`readability-container-data-pointer <clang-tidy/checks/readability/container-data-pointer>`.
+
- Fixed incorrect suggestions for :doc:`readability-container-size-empty
<clang-tidy/checks/readability/container-size-empty>` when smart pointers are involved.
Index: clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp
@@ -98,7 +98,8 @@
Lexer::getSourceText(CharSourceRange::getTokenRange(SrcRange),
*Result.SourceManager, getLangOpts())};
- if (!isa<DeclRefExpr, ArraySubscriptExpr, CXXOperatorCallExpr, CallExpr>(CE))
+ if (!isa<DeclRefExpr, ArraySubscriptExpr, CXXOperatorCallExpr, CallExpr,
+ MemberExpr>(CE))
ReplacementText = "(" + ReplacementText + ")";
if (CE->getType()->isPointerType())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129596.447816.patch
Type: text/x-patch
Size: 2431 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220726/ec3cbc62/attachment.bin>
More information about the cfe-commits
mailing list