[PATCH] D56966: [clang-tidy] misc-non-private-member-variables-in-classes: ignore implicit methods
Miklos Vajna via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 20 05:47:04 PST 2019
vmiklos updated this revision to Diff 182702.
vmiklos marked 3 inline comments as done.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D56966/new/
https://reviews.llvm.org/D56966
Files:
clang-tidy/misc/NonPrivateMemberVariablesInClassesCheck.cpp
docs/clang-tidy/checks/misc-non-private-member-variables-in-classes.rst
test/clang-tidy/misc-non-private-member-variables-in-classes.cpp
Index: test/clang-tidy/misc-non-private-member-variables-in-classes.cpp
===================================================================
--- test/clang-tidy/misc-non-private-member-variables-in-classes.cpp
+++ test/clang-tidy/misc-non-private-member-variables-in-classes.cpp
@@ -35,6 +35,18 @@
int S1_v3;
};
+// Only data and implicit methods, do not warn
+
+class C {
+public:
+ C() {}
+ ~C() {}
+};
+
+struct S1Implicit {
+ C S1Implicit_v0;
+};
+
//----------------------------------------------------------------------------//
// All functions are static, do not warn.
Index: docs/clang-tidy/checks/misc-non-private-member-variables-in-classes.rst
===================================================================
--- docs/clang-tidy/checks/misc-non-private-member-variables-in-classes.rst
+++ docs/clang-tidy/checks/misc-non-private-member-variables-in-classes.rst
@@ -6,11 +6,11 @@
`cppcoreguidelines-non-private-member-variables-in-classes` redirects here
as an alias for this check.
-Finds classes that contain non-static data members in addition to non-static
-member functions and diagnose all data members declared with a non-``public``
-access specifier. The data members should be declared as ``private`` and
-accessed through member functions instead of exposed to derived classes or
-class consumers.
+Finds classes that contain non-static data members in addition to user-provided
+non-static member functions and diagnose all data members declared with a
+non-``public`` access specifier. The data members should be declared as
+``private`` and accessed through member functions instead of exposed to derived
+classes or class consumers.
Options
-------
Index: clang-tidy/misc/NonPrivateMemberVariablesInClassesCheck.cpp
===================================================================
--- clang-tidy/misc/NonPrivateMemberVariablesInClassesCheck.cpp
+++ clang-tidy/misc/NonPrivateMemberVariablesInClassesCheck.cpp
@@ -23,7 +23,7 @@
}
AST_MATCHER(CXXRecordDecl, hasNonStaticMethod) {
- return hasMethod(unless(isStaticStorageClass()))
+ return hasMethod(unless(anyOf(isStaticStorageClass(), isImplicit())))
.matches(Node, Finder, Builder);
}
@@ -66,8 +66,9 @@
IgnorePublicMemberVariables ? isProtected() : unless(isPrivate()));
// We only want the records that not only contain the mutable data (non-static
- // member variables), but also have some logic (non-static member functions).
- // We may optionally ignore records where all the member variables are public.
+ // member variables), but also have some logic (non-static, non-implicit
+ // member functions). We may optionally ignore records where all the member
+ // variables are public.
Finder->addMatcher(cxxRecordDecl(anyOf(isStruct(), isClass()), hasMethods(),
hasNonStaticMethod(),
unless(ShouldIgnoreRecord),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56966.182702.patch
Type: text/x-patch
Size: 2928 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190120/d5cdfc47/attachment.bin>
More information about the cfe-commits
mailing list