hasQualifer() matcher should return false if there's no qualifier
authorEdwin Vane <edwin.vane@intel.com>
Mon, 4 Mar 2013 17:51:00 +0000 (17:51 +0000)
committerEdwin Vane <edwin.vane@intel.com>
Mon, 4 Mar 2013 17:51:00 +0000 (17:51 +0000)
Instead of passing NULL on to sub-matcher, just return false. Updated tests and
regenerated docs.

Author: Tareq A Siraj <tareq.a.siraj@intel.com>
llvm-svn: 176441

clang/docs/LibASTMatchersReference.html
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/unittests/ASTMatchers/ASTMatchersTest.cpp

index 3179900..617d194 100644 (file)
@@ -2509,7 +2509,7 @@ Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
 
 <tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ElaboratedType.html">ElaboratedType</a>&gt;</td><td class="name" onclick="toggle('hasQualifier0')"><a name="hasQualifier0Anchor">hasQualifier</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html">NestedNameSpecifier</a>&gt; InnerMatcher</td></tr>
 <tr><td colspan="4" class="doc" id="hasQualifier0"><pre>Matches ElaboratedTypes whose qualifier, a NestedNameSpecifier,
-matches InnerMatcher.
+matches InnerMatcher if the qualifier exists.
 
 Given
   namespace N {
index b663770..4e36952 100644 (file)
@@ -2965,7 +2965,7 @@ AST_TYPE_MATCHER(RecordType, recordType);
 AST_TYPE_MATCHER(ElaboratedType, elaboratedType);
 
 /// \brief Matches ElaboratedTypes whose qualifier, a NestedNameSpecifier,
-/// matches \c InnerMatcher.
+/// matches \c InnerMatcher if the qualifier exists.
 ///
 /// Given
 /// \code
@@ -2981,7 +2981,10 @@ AST_TYPE_MATCHER(ElaboratedType, elaboratedType);
 /// matches the type of the variable declaration of \c d.
 AST_MATCHER_P(ElaboratedType, hasQualifier,
               internal::Matcher<NestedNameSpecifier>, InnerMatcher) {
-  return InnerMatcher.matches(*Node.getQualifier(), Finder, Builder);
+  if (const NestedNameSpecifier *Qualifier = Node.getQualifier())
+    return InnerMatcher.matches(*Qualifier, Finder, Builder);
+
+  return false;
 }
 
 /// \brief Matches ElaboratedTypes whose named type matches \c InnerMatcher.
index 53620a0..4d369e5 100644 (file)
@@ -3469,6 +3469,10 @@ TEST(ElaboratedTypeNarrowing, hasQualifier) {
     "}"
     "M::D d;",
     elaboratedType(hasQualifier(hasPrefix(specifiesNamespace(hasName("N")))))));
+  EXPECT_TRUE(notMatches(
+    "struct D {"
+    "} d;",
+    elaboratedType(hasQualifier(nestedNameSpecifier()))));
 }
 
 TEST(ElaboratedTypeNarrowing, namesType) {