readability-redundant-declaration: Fix crash
authorDaniel Marjamaki <daniel.marjamaki@evidente.se>
Mon, 21 Nov 2016 14:29:53 +0000 (14:29 +0000)
committerDaniel Marjamaki <daniel.marjamaki@evidente.se>
Mon, 21 Nov 2016 14:29:53 +0000 (14:29 +0000)
Differential Revision: https://reviews.llvm.org/D26911

llvm-svn: 287540

clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp
clang-tools-extra/test/clang-tidy/readability-redundant-declaration.cpp

index ea7d816..10ba122 100644 (file)
@@ -28,6 +28,8 @@ void RedundantDeclarationCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *Prev = D->getPreviousDecl();
   if (!Prev)
     return;
+  if (!Prev->getLocation().isValid())
+    return;
   if (Prev->getLocation() == D->getLocation())
     return;
 
index 7c58596..adb7c4d 100644 (file)
@@ -21,3 +21,10 @@ static int f();
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant 'f' declaration
 // CHECK-FIXES: {{^}}{{$}}
 static int f() {}
+
+// Original check crashed for the code below.
+namespace std {
+  typedef long unsigned int size_t;
+}
+void* operator new(std::size_t) __attribute__((__externally_visible__));
+void* operator new[](std::size_t) __attribute__((__externally_visible__));