[PATCH] D48269: [ASTMatchers] Don't assert-fail in specifiesTypeLoc().

2018-06-18 Thread Manuel Klimek via Phabricator via cfe-commits
klimek accepted this revision.
klimek added a comment.
This revision is now accepted and ready to land.

lg, thanks!


Repository:
  rC Clang

https://reviews.llvm.org/D48269



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48269: [ASTMatchers] Don't assert-fail in specifiesTypeLoc().

2018-06-18 Thread David L. Jones via Phabricator via cfe-commits
dlj created this revision.
dlj added a reviewer: klimek.
dlj added a project: clang.
Herald added a subscriber: cfe-commits.

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.


Repository:
  rC Clang

https://reviews.llvm.org/D48269

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


Index: unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1450,6 +1450,10 @@
 "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";
 }
 
 
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -5536,7 +5536,8 @@
 ///   matches "A::"
 AST_MATCHER_P(NestedNameSpecifierLoc, specifiesTypeLoc,
   internal::Matcher, 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: unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1450,6 +1450,10 @@
 "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";
 }
 
 
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -5536,7 +5536,8 @@
 ///   matches "A::"
 AST_MATCHER_P(NestedNameSpecifierLoc, specifiesTypeLoc,
   internal::Matcher, 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.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits