[llvm-branch-commits] [clang-tools-extra-branch] r351844 - Merging r351686:
Hans Wennborg via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Jan 22 09:32:41 PST 2019
Author: hans
Date: Tue Jan 22 09:32:41 2019
New Revision: 351844
URL: http://llvm.org/viewvc/llvm-project?rev=351844&view=rev
Log:
Merging r351686:
------------------------------------------------------------------------
r351686 | vmiklos | 2019-01-20 15:28:27 +0100 (Sun, 20 Jan 2019) | 5 lines
[clang-tidy] misc-non-private-member-variables-in-classes: ignore implicit methods
Otherwise we don't warn on a struct containing a single public int, but
we warn on a struct containing a single public std::string, which is
inconsistent.
------------------------------------------------------------------------
Modified:
clang-tools-extra/branches/release_80/ (props changed)
clang-tools-extra/branches/release_80/clang-tidy/misc/NonPrivateMemberVariablesInClassesCheck.cpp
clang-tools-extra/branches/release_80/docs/clang-tidy/checks/misc-non-private-member-variables-in-classes.rst
clang-tools-extra/branches/release_80/test/clang-tidy/misc-non-private-member-variables-in-classes.cpp
Propchange: clang-tools-extra/branches/release_80/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jan 22 09:32:41 2019
@@ -1 +1 @@
-/clang-tools-extra/trunk:351463,351466-351468
+/clang-tools-extra/trunk:351463,351466-351468,351686
Modified: clang-tools-extra/branches/release_80/clang-tidy/misc/NonPrivateMemberVariablesInClassesCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/branches/release_80/clang-tidy/misc/NonPrivateMemberVariablesInClassesCheck.cpp?rev=351844&r1=351843&r2=351844&view=diff
==============================================================================
--- clang-tools-extra/branches/release_80/clang-tidy/misc/NonPrivateMemberVariablesInClassesCheck.cpp (original)
+++ clang-tools-extra/branches/release_80/clang-tidy/misc/NonPrivateMemberVariablesInClassesCheck.cpp Tue Jan 22 09:32:41 2019
@@ -23,8 +23,8 @@ AST_MATCHER(CXXRecordDecl, hasMethods) {
return std::distance(Node.method_begin(), Node.method_end()) != 0;
}
-AST_MATCHER(CXXRecordDecl, hasNonStaticMethod) {
- return hasMethod(unless(isStaticStorageClass()))
+AST_MATCHER(CXXRecordDecl, hasNonStaticNonImplicitMethod) {
+ return hasMethod(unless(anyOf(isStaticStorageClass(), isImplicit())))
.matches(Node, Finder, Builder);
}
@@ -67,10 +67,11 @@ void NonPrivateMemberVariablesInClassesC
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(),
+ hasNonStaticNonImplicitMethod(),
unless(ShouldIgnoreRecord),
forEach(InterestingField.bind("field")))
.bind("record"),
Modified: clang-tools-extra/branches/release_80/docs/clang-tidy/checks/misc-non-private-member-variables-in-classes.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/branches/release_80/docs/clang-tidy/checks/misc-non-private-member-variables-in-classes.rst?rev=351844&r1=351843&r2=351844&view=diff
==============================================================================
--- clang-tools-extra/branches/release_80/docs/clang-tidy/checks/misc-non-private-member-variables-in-classes.rst (original)
+++ clang-tools-extra/branches/release_80/docs/clang-tidy/checks/misc-non-private-member-variables-in-classes.rst Tue Jan 22 09:32:41 2019
@@ -6,11 +6,11 @@ misc-non-private-member-variables-in-cla
`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-declared
+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
-------
Modified: clang-tools-extra/branches/release_80/test/clang-tidy/misc-non-private-member-variables-in-classes.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/branches/release_80/test/clang-tidy/misc-non-private-member-variables-in-classes.cpp?rev=351844&r1=351843&r2=351844&view=diff
==============================================================================
--- clang-tools-extra/branches/release_80/test/clang-tidy/misc-non-private-member-variables-in-classes.cpp (original)
+++ clang-tools-extra/branches/release_80/test/clang-tidy/misc-non-private-member-variables-in-classes.cpp Tue Jan 22 09:32:41 2019
@@ -35,6 +35,23 @@ private:
int S1_v3;
};
+// Only data and implicit or static methods, do not warn
+
+class C {
+public:
+ C() {}
+ ~C() {}
+};
+
+struct S1Implicit {
+ C S1Implicit_v0;
+};
+
+struct S1ImplicitAndStatic {
+ C S1Implicit_v0;
+ static void s() {}
+};
+
//----------------------------------------------------------------------------//
// All functions are static, do not warn.
More information about the llvm-branch-commits
mailing list