Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: tools/clang/plugins/FindBadConstructsConsumer.cpp

Issue 1126413004: plugin: Don't warn about inline virtual methods from system macros; whitelist two non-system macros. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/clang/plugins/tests/system/windows.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "FindBadConstructsConsumer.h" 5 #include "FindBadConstructsConsumer.h"
6 6
7 #include "clang/Frontend/CompilerInstance.h" 7 #include "clang/Frontend/CompilerInstance.h"
8 #include "clang/AST/Attr.h" 8 #include "clang/AST/Attr.h"
9 #include "clang/Lex/Lexer.h" 9 #include "clang/Lex/Lexer.h"
10 #include "llvm/Support/raw_ostream.h" 10 #include "llvm/Support/raw_ostream.h"
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 } 501 }
502 } 502 }
503 503
504 void FindBadConstructsConsumer::CheckVirtualBodies( 504 void FindBadConstructsConsumer::CheckVirtualBodies(
505 const CXXMethodDecl* method) { 505 const CXXMethodDecl* method) {
506 // Virtual methods should not have inline definitions beyond "{}". This 506 // Virtual methods should not have inline definitions beyond "{}". This
507 // only matters for header files. 507 // only matters for header files.
508 if (method->hasBody() && method->hasInlineBody()) { 508 if (method->hasBody() && method->hasInlineBody()) {
509 if (CompoundStmt* cs = dyn_cast<CompoundStmt>(method->getBody())) { 509 if (CompoundStmt* cs = dyn_cast<CompoundStmt>(method->getBody())) {
510 if (cs->size()) { 510 if (cs->size()) {
511 emitWarning(cs->getLBracLoc(), 511 SourceLocation loc = cs->getLBracLoc();
512 "virtual methods with non-empty bodies shouldn't be " 512 // CR_BEGIN_MSG_MAP_EX and BEGIN_SAFE_MSG_MAP_EX try to be compatible
513 "declared inline."); 513 // to BEGIN_MSG_MAP(_EX). So even though they are in chrome code,
514 // we can't easily fix them, so explicitly whitelist them here.
515 bool emit = true;
516 if (loc.isMacroID()) {
517 SourceManager& manager = instance().getSourceManager();
518 if (InBannedDirectory(manager.getSpellingLoc(loc)))
519 emit = false;
520 else {
521 StringRef name = Lexer::getImmediateMacroName(
522 loc, manager, instance().getLangOpts());
523 if (name == "CR_BEGIN_MSG_MAP_EX" ||
524 name == "BEGIN_SAFE_MSG_MAP_EX")
525 emit = false;
526 }
527 }
528 if (emit)
529 emitWarning(loc,
530 "virtual methods with non-empty bodies shouldn't be "
531 "declared inline.");
514 } 532 }
515 } 533 }
516 } 534 }
517 } 535 }
518 536
519 void FindBadConstructsConsumer::CountType(const Type* type, 537 void FindBadConstructsConsumer::CountType(const Type* type,
520 int* trivial_member, 538 int* trivial_member,
521 int* non_trivial_member, 539 int* non_trivial_member,
522 int* templated_non_trivial_member) { 540 int* templated_non_trivial_member) {
523 switch (type->getTypeClass()) { 541 switch (type->getTypeClass()) {
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 // one of those, it means there is at least one member after a factory. 842 // one of those, it means there is at least one member after a factory.
825 if (weak_ptr_factory_location.isValid() && 843 if (weak_ptr_factory_location.isValid() &&
826 !param_is_weak_ptr_factory_to_self) { 844 !param_is_weak_ptr_factory_to_self) {
827 diagnostic().Report(weak_ptr_factory_location, 845 diagnostic().Report(weak_ptr_factory_location,
828 diag_weak_ptr_factory_order_); 846 diag_weak_ptr_factory_order_);
829 } 847 }
830 } 848 }
831 } 849 }
832 850
833 } // namespace chrome_checker 851 } // namespace chrome_checker
OLDNEW
« no previous file with comments | « no previous file | tools/clang/plugins/tests/system/windows.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698