| OLD | NEW | 
|    1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |    1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 
|    2 // Use of this source code is governed by a BSD-style license that can be |    2 // Use of this source code is governed by a BSD-style license that can be | 
|    3 // found in the LICENSE file. |    3 // found in the LICENSE file. | 
|    4  |    4  | 
|    5 // This file defines a bunch of recurring problems in the Chromium C++ code. |    5 // This file defines a bunch of recurring problems in the Chromium C++ code. | 
|    6 // |    6 // | 
|    7 // Checks that are implemented: |    7 // Checks that are implemented: | 
|    8 // - Constructors/Destructors should not be inlined if they are of a complex |    8 // - Constructors/Destructors should not be inlined if they are of a complex | 
|    9 //   class type. |    9 //   class type. | 
|   10 // - Missing "virtual" keywords on methods that should be virtual. |   10 // - Missing "virtual" keywords on methods that should be virtual. | 
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   97     // The fourth normal class member should trigger the warning. |   97     // The fourth normal class member should trigger the warning. | 
|   98     dtor_score += non_trivial_member * 3; |   98     dtor_score += non_trivial_member * 3; | 
|   99  |   99  | 
|  100     int ctor_score = dtor_score; |  100     int ctor_score = dtor_score; | 
|  101     // You should be able to have 9 ints before we warn you. |  101     // You should be able to have 9 ints before we warn you. | 
|  102     ctor_score += trivial_member; |  102     ctor_score += trivial_member; | 
|  103  |  103  | 
|  104     if (ctor_score >= 10) { |  104     if (ctor_score >= 10) { | 
|  105       if (!record->hasUserDeclaredConstructor()) { |  105       if (!record->hasUserDeclaredConstructor()) { | 
|  106         emitWarning(record_location, |  106         emitWarning(record_location, | 
|  107                     "Complex class/struct needs a declared constructor."); |  107                     "Complex class/struct needs an explicit out-of-line " | 
 |  108                     "constructor."); | 
|  108       } else { |  109       } else { | 
|  109         // Iterate across all the constructors in this file and yell if we |  110         // Iterate across all the constructors in this file and yell if we | 
|  110         // find one that tries to be inline. |  111         // find one that tries to be inline. | 
|  111         for (CXXRecordDecl::ctor_iterator it = record->ctor_begin(); |  112         for (CXXRecordDecl::ctor_iterator it = record->ctor_begin(); | 
|  112              it != record->ctor_end(); ++it) { |  113              it != record->ctor_end(); ++it) { | 
|  113           if (it->hasInlineBody()) { |  114           if (it->hasInlineBody()) { | 
|  114             emitWarning(it->getInnerLocStart(), |  115             emitWarning(it->getInnerLocStart(), | 
|  115                         "Complex constructor has an inlined body."); |  116                         "Complex constructor has an inlined body."); | 
|  116           } |  117           } | 
|  117         } |  118         } | 
|  118       } |  119       } | 
|  119     } |  120     } | 
|  120  |  121  | 
|  121     // The destructor side is equivalent except that we don't check for |  122     // The destructor side is equivalent except that we don't check for | 
|  122     // trivial members; 20 ints don't need a destructor. |  123     // trivial members; 20 ints don't need a destructor. | 
|  123     if (dtor_score >= 10 && !record->hasTrivialDestructor()) { |  124     if (dtor_score >= 10 && !record->hasTrivialDestructor()) { | 
|  124       if (!record->hasUserDeclaredDestructor()) { |  125       if (!record->hasUserDeclaredDestructor()) { | 
|  125         emitWarning(record_location, |  126         emitWarning( | 
|  126                     "Complex class/struct needs a declared destructor."); |  127             record_location, | 
 |  128             "Complex class/struct needs a needs an explicit out-of-line " | 
 |  129             "destructor."); | 
|  127       } else if (CXXDestructorDecl* dtor = record->getDestructor()) { |  130       } else if (CXXDestructorDecl* dtor = record->getDestructor()) { | 
|  128         if (dtor->hasInlineBody()) { |  131         if (dtor->hasInlineBody()) { | 
|  129           emitWarning(dtor->getInnerLocStart(), |  132           emitWarning(dtor->getInnerLocStart(), | 
|  130                       "Complex destructor has an inline body."); |  133                       "Complex destructor has an inline body."); | 
|  131         } |  134         } | 
|  132       } |  135       } | 
|  133     } |  136     } | 
|  134   } |  137   } | 
|  135  |  138  | 
|  136   // Makes sure there is a "virtual" keyword on virtual methods and that there |  139   // Makes sure there is a "virtual" keyword on virtual methods and that there | 
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  253                  const std::vector<std::string>& args) { |  256                  const std::vector<std::string>& args) { | 
|  254     // We don't take any additional arguments here. |  257     // We don't take any additional arguments here. | 
|  255     return true; |  258     return true; | 
|  256   } |  259   } | 
|  257 }; |  260 }; | 
|  258  |  261  | 
|  259 }  // namespace |  262 }  // namespace | 
|  260  |  263  | 
|  261 static FrontendPluginRegistry::Add<FindBadConstructsAction> |  264 static FrontendPluginRegistry::Add<FindBadConstructsAction> | 
|  262 X("find-bad-constructs", "Finds bad C++ constructs"); |  265 X("find-bad-constructs", "Finds bad C++ constructs"); | 
| OLD | NEW |