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

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

Issue 1129093002: plugin: Do not warn on virtual/override stuff coming from macros in system headers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: actual change 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 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 if (IsMethodInBannedOrTestingNamespace(method)) 410 if (IsMethodInBannedOrTestingNamespace(method))
411 return; 411 return;
412 412
413 SourceManager& manager = instance().getSourceManager(); 413 SourceManager& manager = instance().getSourceManager();
414 414
415 // Complain if a method is annotated virtual && (override || final). 415 // Complain if a method is annotated virtual && (override || final).
416 if (has_virtual && (override_attr || final_attr)) { 416 if (has_virtual && (override_attr || final_attr)) {
417 // ... but only if virtual does not originate in a macro from a banned file. 417 // ... but only if virtual does not originate in a macro from a banned file.
418 // Note this is just an educated guess: the assumption here is that any 418 // Note this is just an educated guess: the assumption here is that any
419 // macro for declaring methods will probably be at the start of the method's 419 // macro for declaring methods will probably be at the start of the method's
420 // source range. 420 // source range.
Nico 2015/05/06 22:49:24 to this
421 if (!InBannedDirectory(manager.getSpellingLoc(method->getLocStart()))) { 421 if (!InBannedDirectory(manager.getSpellingLoc(method->getLocStart()))) {
422 diagnostic().Report(method->getLocStart(), 422 diagnostic().Report(method->getLocStart(),
423 diag_redundant_virtual_specifier_) 423 diag_redundant_virtual_specifier_)
424 << "'virtual'" 424 << "'virtual'"
425 << (override_attr ? static_cast<Attr*>(override_attr) : final_attr) 425 << (override_attr ? static_cast<Attr*>(override_attr) : final_attr)
426 << FixItRemovalForVirtual(manager, method); 426 << FixItRemovalForVirtual(manager, method);
427 } 427 }
428 } 428 }
429 429
430 // Complain if a method is an override and is not annotated with override or 430 // Complain if a method is an override and is not annotated with override or
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 break; 464 break;
465 } 465 }
466 if (token.is(tok::r_paren)) { 466 if (token.is(tok::r_paren)) {
467 break; 467 break;
468 } else if (token.is(tok::equal)) { 468 } else if (token.is(tok::equal)) {
469 loc = l; 469 loc = l;
470 break; 470 break;
471 } 471 }
472 } 472 }
473 } 473 }
474 // Again, only emit the warning if it doesn't originate from a macro in
hans 2015/05/06 22:47:42 Silly question: what does "Again" refer to here?
475 // a system header.
474 if (loc.isValid()) { 476 if (loc.isValid()) {
475 diagnostic().Report(loc, diag_method_requires_override_) 477 if (!InBannedDirectory(manager.getSpellingLoc(loc))) {
dcheng 2015/05/06 22:44:26 It almost feels like this should be a helper. rep
Nico 2015/05/06 22:49:24 I considered that, but it's really only this funct
476 << FixItHint::CreateInsertion(loc, " override"); 478 diagnostic().Report(loc, diag_method_requires_override_)
479 << FixItHint::CreateInsertion(loc, " override");
480 }
477 } else { 481 } else {
478 diagnostic().Report(range.getBegin(), diag_method_requires_override_); 482 if (!InBannedDirectory(manager.getSpellingLoc(range.getBegin())))
483 diagnostic().Report(range.getBegin(), diag_method_requires_override_);
479 } 484 }
480 } 485 }
481 486
482 if (final_attr && override_attr) { 487 if (final_attr && override_attr &&
488 !InBannedDirectory(
489 manager.getSpellingLoc(override_attr->getLocation()))) {
483 diagnostic().Report(override_attr->getLocation(), 490 diagnostic().Report(override_attr->getLocation(),
484 diag_redundant_virtual_specifier_) 491 diag_redundant_virtual_specifier_)
485 << override_attr << final_attr 492 << override_attr << final_attr
486 << FixItHint::CreateRemoval(override_attr->getRange()); 493 << FixItHint::CreateRemoval(override_attr->getRange());
487 } 494 }
488 495
489 if (final_attr && !is_override) { 496 if (final_attr && !is_override &&
497 !InBannedDirectory(manager.getSpellingLoc(method->getLocStart()))) {
490 diagnostic().Report(method->getLocStart(), 498 diagnostic().Report(method->getLocStart(),
491 diag_base_method_virtual_and_final_) 499 diag_base_method_virtual_and_final_)
492 << FixItRemovalForVirtual(manager, method) 500 << FixItRemovalForVirtual(manager, method)
493 << FixItHint::CreateRemoval(final_attr->getRange()); 501 << FixItHint::CreateRemoval(final_attr->getRange());
494 } 502 }
495 } 503 }
496 504
497 void FindBadConstructsConsumer::CheckVirtualBodies( 505 void FindBadConstructsConsumer::CheckVirtualBodies(
498 const CXXMethodDecl* method) { 506 const CXXMethodDecl* method) {
499 // Virtual methods should not have inline definitions beyond "{}". This 507 // Virtual methods should not have inline definitions beyond "{}". This
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 // one of those, it means there is at least one member after a factory. 825 // one of those, it means there is at least one member after a factory.
818 if (weak_ptr_factory_location.isValid() && 826 if (weak_ptr_factory_location.isValid() &&
819 !param_is_weak_ptr_factory_to_self) { 827 !param_is_weak_ptr_factory_to_self) {
820 diagnostic().Report(weak_ptr_factory_location, 828 diagnostic().Report(weak_ptr_factory_location,
821 diag_weak_ptr_factory_order_); 829 diag_weak_ptr_factory_order_);
822 } 830 }
823 } 831 }
824 } 832 }
825 833
826 } // namespace chrome_checker 834 } // 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