]> granicus.if.org Git - clang/commitdiff
[ASTMatchers] Don't assert-fail in specifiesTypeLoc().
authorDavid L. Jones <dlj@google.com>
Mon, 18 Jun 2018 08:59:16 +0000 (08:59 +0000)
committerDavid L. Jones <dlj@google.com>
Mon, 18 Jun 2018 08:59:16 +0000 (08:59 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@334929 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/ASTMatchers/ASTMatchers.h
unittests/ASTMatchers/ASTMatchersNodeTest.cpp

index c9e182172cf32279460b02c0a243f47b22073f56..d8a40a9af6d70765d255235cd1b0d7a93f706d36 100644 (file)
@@ -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.
index 6298e8759dd546dd1247e4c62637b50c83f52ab3..6b701bfb7bb397567c63bde9bbf11d32bad68156 100644 (file)
@@ -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"))))))));
 }