[clang-tools-extra] r321762 - [clang-tidy] Update fuchsia-overloaded-operator to check for valid loc

Julie Hockett via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 3 14:10:11 PST 2018


Author: juliehockett
Date: Wed Jan  3 14:10:11 2018
New Revision: 321762

URL: http://llvm.org/viewvc/llvm-project?rev=321762&view=rev
Log:
[clang-tidy] Update fuchsia-overloaded-operator to check for valid loc

Updating fuchsia-overloaded-operator check to not issue warnings for
invalid locations.

Fixes PR35803.

Differential Revision: https://reviews.llvm.org/D41708

Modified:
    clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
    clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-operator.cpp

Modified: clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp?rev=321762&r1=321761&r2=321762&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp Wed Jan  3 14:10:11 2018
@@ -30,8 +30,12 @@ void OverloadedOperatorCheck::registerMa
 }
 
 void OverloadedOperatorCheck::check(const MatchFinder::MatchResult &Result) {
-  if (const auto *D = Result.Nodes.getNodeAs<FunctionDecl>("decl"))
-    diag(D->getLocStart(), "cannot overload %0") << D;
+  const auto *D = Result.Nodes.getNodeAs<FunctionDecl>("decl");
+  assert(D && "No FunctionDecl captured!");
+  
+  SourceLocation Loc = D->getLocStart();
+  if (Loc.isValid())
+    diag(Loc, "cannot overload %0") << D;
 }
 
 } // namespace fuchsia

Modified: clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-operator.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-operator.cpp?rev=321762&r1=321761&r2=321762&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-operator.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-operator.cpp Wed Jan  3 14:10:11 2018
@@ -16,3 +16,6 @@ public:
 
 A operator-(const A &A1, const A &A2);
 // CHECK-MESSAGES: [[@LINE-1]]:1: warning: cannot overload 'operator-' [fuchsia-overloaded-operator]
+
+void operator delete(void*, void*) throw();
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: cannot overload 'operator delete' [fuchsia-overloaded-operator]




More information about the cfe-commits mailing list