diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp @@ -24,6 +24,7 @@ hasGlobalStorage(), unless(anyOf( isLocalVarDecl(), isConstexpr(), hasType(isConstQualified()), + isPrivate(), isProtected(), hasType(referenceType())))); // References can't be changed, only the // data they reference can be changed. diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-non-const-global-variables.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-non-const-global-variables.cpp --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-non-const-global-variables.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-non-const-global-variables.cpp @@ -228,6 +228,20 @@ template constexpr T templateVariable = T(0L); +// CHECKING FOR NON-CONST STATIC PRIVATE/PROTECTED CLASS MEMBERS ////////////// +class Foo { + static int nonConstStaticPrivateMember; +protected: + static int nonConstStaticProtectedMember; +}; + +struct Bar { +private: + static int nonConstStaticPrivateMember; +protected: + static int nonConstStaticProtectedMember; +}; + // CHECKING AGAINST FALSE POSITIVES INSIDE FUNCTION SCOPE ///////////////////// int main() { for (int i = 0; i < 3; ++i) {