diff options
author | Angel Garcia Gomez <angelgarcia@google.com> | 2015-11-02 15:28:06 +0000 |
---|---|---|
committer | Angel Garcia Gomez <angelgarcia@google.com> | 2015-11-02 15:28:06 +0000 |
commit | dc39f313e2a14900f0d0e6cc156f35cef47f282d (patch) | |
tree | 01ad7e9cd8d7d685c3f6fcde4e498995ab0cf5ed | |
parent | 8eb1d544f89e6015743ddacfc86bbf06fffdb935 (diff) | |
download | llvm-dc39f313e2a14900f0d0e6cc156f35cef47f282d.zip llvm-dc39f313e2a14900f0d0e6cc156f35cef47f282d.tar.gz llvm-dc39f313e2a14900f0d0e6cc156f35cef47f282d.tar.bz2 |
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
llvm-svn: 251803
-rw-r--r-- | clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp | 12 | ||||
-rw-r--r-- | clang-tools-extra/test/clang-tidy/modernize-use-nullptr.cpp | 11 |
2 files changed, 18 insertions, 5 deletions
diff --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp index 665b645..99e4406 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp @@ -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; } diff --git a/clang-tools-extra/test/clang-tidy/modernize-use-nullptr.cpp b/clang-tools-extra/test/clang-tidy/modernize-use-nullptr.cpp index ca655f5..6b41cfb 100644 --- a/clang-tools-extra/test/clang-tidy/modernize-use-nullptr.cpp +++ b/clang-tools-extra/test/clang-tidy/modernize-use-nullptr.cpp @@ -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 |