summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid L. Jones <dlj@google.com>2018-06-18 08:59:16 +0000
committerDavid L. Jones <dlj@google.com>2018-06-18 08:59:16 +0000
commit8f7adcd7fb1fd1a01a0de79eca954c49e7e3dabb (patch)
tree39d86c8ac2c3291dabd19ebf6e04c2338c3fef2a
parent068246886a78a3fcfd7237f2dfae1b21c80a4480 (diff)
downloadbcm5719-llvm-8f7adcd7fb1fd1a01a0de79eca954c49e7e3dabb.tar.gz
bcm5719-llvm-8f7adcd7fb1fd1a01a0de79eca954c49e7e3dabb.zip
[ASTMatchers] Don't assert-fail in specifiesTypeLoc().
The specifiesTypeLoc() matcher narrows a nestedNameSpecifier matcher based on a typeloc within the NNS. However, the matcher does not guard against NNS which are a namespace, and cause getTypeLoc to assert-fail. llvm-svn: 334929
-rw-r--r--clang/include/clang/ASTMatchers/ASTMatchers.h3
-rw-r--r--clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp4
2 files changed, 6 insertions, 1 deletions
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index c9e182172cf..d8a40a9af6d 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -5536,7 +5536,8 @@ AST_MATCHER_P(NestedNameSpecifier, specifiesType,
/// matches "A::"
AST_MATCHER_P(NestedNameSpecifierLoc, specifiesTypeLoc,
internal::Matcher<TypeLoc>, InnerMatcher) {
- return Node && InnerMatcher.matches(Node.getTypeLoc(), Finder, Builder);
+ return Node && Node.getNestedNameSpecifier()->getAsType() &&
+ InnerMatcher.matches(Node.getTypeLoc(), Finder, Builder);
}
/// Matches on the prefix of a \c NestedNameSpecifier.
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index 6298e8759dd..6b701bfb7bb 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1450,6 +1450,10 @@ TEST(NNS, MatchesNestedNameSpecifierPrefixes) {
"struct A { struct B { struct C {}; }; }; A::B::C c;",
nestedNameSpecifierLoc(hasPrefix(
specifiesTypeLoc(loc(qualType(asString("struct A"))))))));
+ EXPECT_TRUE(matches(
+ "namespace N { struct A { struct B { struct C {}; }; }; } N::A::B::C c;",
+ nestedNameSpecifierLoc(hasPrefix(
+ specifiesTypeLoc(loc(qualType(asString("struct N::A"))))))));
}
OpenPOWER on IntegriCloud