@@ -20,14 +20,13 @@ using namespace clang::ast_matchers;
2020using  namespace  clang ::ast_matchers::internal; 
2121
2222namespace  clang ::tidy::modernize {
23- namespace  {
2423
25- const  char  IteratorDeclStmtId[] = " iterator_decl"  ;
26- const  char  DeclWithNewId[] = " decl_new"  ;
27- const  char  DeclWithCastId[] = " decl_cast"  ;
28- const  char  DeclWithTemplateCastId[] = " decl_template"  ;
24+ static   const  char  IteratorDeclStmtId[] = " iterator_decl"  ;
25+ static   const  char  DeclWithNewId[] = " decl_new"  ;
26+ static   const  char  DeclWithCastId[] = " decl_cast"  ;
27+ static   const  char  DeclWithTemplateCastId[] = " decl_template"  ;
2928
30- size_t  getTypeNameLength (bool  RemoveStars, StringRef Text) {
29+ static   size_t  getTypeNameLength (bool  RemoveStars, StringRef Text) {
3130  enum  CharType { Space, Alpha, Punctuation };
3231  CharType LastChar = Space, BeforeSpace = Punctuation;
3332  size_t  NumChars = 0 ;
@@ -54,6 +53,7 @@ size_t getTypeNameLength(bool RemoveStars, StringRef Text) {
5453  return  NumChars;
5554}
5655
56+ namespace  {
5757// / Matches variable declarations that have explicit initializers that
5858// / are not initializer lists.
5959// /
@@ -65,7 +65,7 @@ size_t getTypeNameLength(bool RemoveStars, StringRef Text) {
6565// /   MyType C;
6666// / \endcode
6767// /
68- // / varDecl(hasWrittenNonListInitializer()) maches  \c I and \c A but not \c B
68+ // / varDecl(hasWrittenNonListInitializer()) matches  \c I and \c A but not \c B
6969// / or \c C.
7070AST_MATCHER (VarDecl, hasWrittenNonListInitializer) {
7171  const  Expr *Init = Node.getAnyInitializer ();
@@ -108,6 +108,15 @@ AST_MATCHER_P(QualType, isSugarFor, Matcher<QualType>, SugarMatcher) {
108108  }
109109}
110110
111+ // / Matches declaration reference or member expressions with explicit template
112+ // / arguments.
113+ AST_POLYMORPHIC_MATCHER (hasExplicitTemplateArgs,
114+                         AST_POLYMORPHIC_SUPPORTED_TYPES (DeclRefExpr,
115+                                                         MemberExpr)) {
116+   return  Node.hasExplicitTemplateArgs ();
117+ }
118+ } //  namespace
119+ 
111120// / Matches named declarations that have one of the standard iterator
112121// / names: iterator, reverse_iterator, const_iterator, const_reverse_iterator.
113122// /
@@ -118,7 +127,7 @@ AST_MATCHER_P(QualType, isSugarFor, Matcher<QualType>, SugarMatcher) {
118127// / \endcode
119128// /
120129// / namedDecl(hasStdIteratorName()) matches \c I and \c CI.
121- Matcher<NamedDecl> hasStdIteratorName () {
130+ static   Matcher<NamedDecl> hasStdIteratorName () {
122131  static  const  StringRef IteratorNames[] = {" iterator"  , " reverse_iterator"  ,
123132                                            " const_iterator"  ,
124133                                            " const_reverse_iterator"  };
@@ -137,7 +146,7 @@ Matcher<NamedDecl> hasStdIteratorName() {
137146// /
138147// / recordDecl(hasStdContainerName()) matches \c vector and \c forward_list
139148// / but not \c my_vec.
140- Matcher<NamedDecl> hasStdContainerName () {
149+ static   Matcher<NamedDecl> hasStdContainerName () {
141150  static  StringRef ContainerNames[] = {" array"  ,         " deque"  ,
142151                                       " forward_list"  ,  " list"  ,
143152                                       " vector"  ,
@@ -154,37 +163,29 @@ Matcher<NamedDecl> hasStdContainerName() {
154163  return  hasAnyName (ContainerNames);
155164}
156165
157- // / Matches declaration reference or member expressions with explicit template
158- // / arguments.
159- AST_POLYMORPHIC_MATCHER (hasExplicitTemplateArgs,
160-                         AST_POLYMORPHIC_SUPPORTED_TYPES (DeclRefExpr,
161-                                                         MemberExpr)) {
162-   return  Node.hasExplicitTemplateArgs ();
163- }
164- 
165166// / Returns a DeclarationMatcher that matches standard iterators nested
166167// / inside records with a standard container name.
167- DeclarationMatcher standardIterator () {
168+ static   DeclarationMatcher standardIterator () {
168169  return  decl (
169170      namedDecl (hasStdIteratorName ()),
170171      hasDeclContext (recordDecl (hasStdContainerName (), isInStdNamespace ())));
171172}
172173
173174// / Returns a TypeMatcher that matches typedefs for standard iterators
174175// / inside records with a standard container name.
175- TypeMatcher typedefIterator () {
176+ static   TypeMatcher typedefIterator () {
176177  return  typedefType (hasDeclaration (standardIterator ()));
177178}
178179
179180// / Returns a TypeMatcher that matches records named for standard
180181// / iterators nested inside records named for standard containers.
181- TypeMatcher nestedIterator () {
182+ static   TypeMatcher nestedIterator () {
182183  return  recordType (hasDeclaration (standardIterator ()));
183184}
184185
185186// / Returns a TypeMatcher that matches types declared with using
186187// / declarations and which name standard iterators for standard containers.
187- TypeMatcher iteratorFromUsingDeclaration () {
188+ static   TypeMatcher iteratorFromUsingDeclaration () {
188189  auto  HasIteratorDecl = hasDeclaration (namedDecl (hasStdIteratorName ()));
189190  //  Unwrap the nested name specifier to test for one of the standard
190191  //  containers.
@@ -198,7 +199,7 @@ TypeMatcher iteratorFromUsingDeclaration() {
198199
199200// / This matcher returns declaration statements that contain variable
200201// / declarations with written non-list initializer for standard iterators.
201- StatementMatcher makeIteratorDeclMatcher () {
202+ static   StatementMatcher makeIteratorDeclMatcher () {
202203  return  declStmt (unless (has (
203204                      varDecl (anyOf (unless (hasWrittenNonListInitializer ()),
204205                                    unless (hasType (isSugarFor (anyOf (
@@ -207,7 +208,7 @@ StatementMatcher makeIteratorDeclMatcher() {
207208      .bind (IteratorDeclStmtId);
208209}
209210
210- StatementMatcher makeDeclWithNewMatcher () {
211+ static   StatementMatcher makeDeclWithNewMatcher () {
211212  return  declStmt (
212213             unless (has (varDecl (anyOf (
213214                 unless (hasInitializer (ignoringParenImpCasts (cxxNewExpr ()))),
@@ -225,13 +226,13 @@ StatementMatcher makeDeclWithNewMatcher() {
225226      .bind (DeclWithNewId);
226227}
227228
228- StatementMatcher makeDeclWithCastMatcher () {
229+ static   StatementMatcher makeDeclWithCastMatcher () {
229230  return  declStmt (
230231             unless (has (varDecl (unless (hasInitializer (explicitCastExpr ()))))))
231232      .bind (DeclWithCastId);
232233}
233234
234- StatementMatcher makeDeclWithTemplateCastMatcher () {
235+ static   StatementMatcher makeDeclWithTemplateCastMatcher () {
235236  auto  ST =
236237      substTemplateTypeParmType (hasReplacementType (equalsBoundNode (" arg"  )));
237238
@@ -252,7 +253,7 @@ StatementMatcher makeDeclWithTemplateCastMatcher() {
252253      .bind (DeclWithTemplateCastId);
253254}
254255
255- StatementMatcher makeCombinedMatcher () {
256+ static   StatementMatcher makeCombinedMatcher () {
256257  return  declStmt (
257258      //  At least one varDecl should be a child of the declStmt to ensure
258259      //  it's a declaration list and avoid matching other declarations,
@@ -265,8 +266,6 @@ StatementMatcher makeCombinedMatcher() {
265266            makeDeclWithCastMatcher (), makeDeclWithTemplateCastMatcher ()));
266267}
267268
268- } //  namespace
269- 
270269UseAutoCheck::UseAutoCheck (StringRef Name, ClangTidyContext *Context)
271270    : ClangTidyCheck(Name, Context),
272271      MinTypeNameLength(Options.get(" MinTypeNameLength"  , 5 )),
0 commit comments