[clang-tools-extra] r251803 - Remove unreachable that was reached in modernize-use-nullptr.

Angel Garcia Gomez via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 2 07:28:06 PST 2015


Author: angelgarcia
Date: Mon Nov  2 09:28:06 2015
New Revision: 251803

URL: http://llvm.org/viewvc/llvm-project?rev=251803&view=rev
Log:
Remove unreachable that was reached in modernize-use-nullptr.

Summary: When traversing the parent map, the check assumed that all the nodes would be either Stmt or Decl. After r251101, this is no longer true: there can be TypeLoc and NestedNameSpecifierLoc nodes.

Reviewers: alexfh

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D14229

Modified:
    clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
    clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp?rev=251803&r1=251802&r2=251803&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp Mon Nov  2 09:28:06 2015
@@ -435,12 +435,14 @@ private:
         Loc = D->getLocStart();
       else if (const auto *S = Parent.get<Stmt>())
         Loc = S->getLocStart();
-      else
-        llvm_unreachable("Expected to find Decl or Stmt containing ancestor");
 
-      if (!expandsFrom(Loc, MacroLoc)) {
-        Result = Parent;
-        return true;
+      // TypeLoc and NestedNameSpecifierLoc are members of the parent map. Skip
+      // them and keep going up.
+      if (Loc.isValid()) {
+        if (!expandsFrom(Loc, MacroLoc)) {
+          Result = Parent;
+          return true;
+        }
       }
       Start = Parent;
     }

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp?rev=251803&r1=251802&r2=251803&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp Mon Nov  2 09:28:06 2015
@@ -184,3 +184,14 @@ void test_macro_args() {
   // CHECK-FIXES: a[2] = {ENTRY(nullptr), {nullptr}};
 #undef ENTRY
 }
+
+// One of the ancestor of the cast is a NestedNameSpecifierLoc.
+class NoDef;
+char function(NoDef *p);
+#define F(x) (sizeof(function(x)) == 1)
+template<class T, T t>
+class C {};
+C<bool, F(0)> c;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use nullptr
+// CHECK-FIXES: C<bool, F(nullptr)> c;
+#undef F




More information about the cfe-commits mailing list