Please find attached a patch (with testcase) to correctly load the source range of parentheses in UnaryTransformTypeLoc nodes.
This also fixes the computation of the source range for the whole node.

OK to commit?

Enea.
Index: include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchers.h	(revision 185665)
+++ include/clang/ASTMatchers/ASTMatchers.h	(working copy)
@@ -3186,6 +3186,16 @@
 /// instantiation in \c A and the type of the variable declaration in \c B.
 AST_TYPE_MATCHER(TemplateSpecializationType, templateSpecializationType);
 
+/// \brief Matches types nodes representing unary type transformations.
+///
+/// Given:
+/// \code
+///   typedef __underlying_type(T) type;
+/// \endcode
+/// unaryTransformType()
+///   matches "__underlying_type(T)"
+AST_TYPE_MATCHER(UnaryTransformType, unaryTransformType);
+
 /// \brief Matches record types (e.g. structs, classes).
 ///
 /// Given
Index: unittests/AST/SourceLocationTest.cpp
===================================================================
--- unittests/AST/SourceLocationTest.cpp	(revision 185665)
+++ unittests/AST/SourceLocationTest.cpp	(working copy)
@@ -180,5 +180,26 @@
   EXPECT_TRUE(Verifier.match("int* a = new (int);", newExpr()));
 }
 
+class UnaryTransformTypeLocParensRangeVerifier : public RangeVerifier<TypeLoc> {
+protected:
+  virtual SourceRange getRange(const TypeLoc &Node) {
+    UnaryTransformTypeLoc T =
+        Node.getUnqualifiedLoc().castAs<UnaryTransformTypeLoc>();
+    assert(!T.isNull());
+    return SourceRange(T.getLParenLoc(), T.getRParenLoc());
+  }
+};
+
+TEST(UnaryTransformTypeLoc, ParensRange) {
+  UnaryTransformTypeLocParensRangeVerifier Verifier;
+  Verifier.expectRange(3, 26, 3, 28);
+  EXPECT_TRUE(Verifier.match(
+      "template <typename T>\n"
+      "struct S {\n"
+      "typedef __underlying_type(T) type;\n"
+      "};",
+      loc(unaryTransformType())));
+}
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: lib/Parse/ParseDeclCXX.cpp
===================================================================
--- lib/Parse/ParseDeclCXX.cpp	(revision 185665)
+++ lib/Parse/ParseDeclCXX.cpp	(working copy)
@@ -827,6 +828,7 @@
   if (DS.SetTypeSpecType(DeclSpec::TST_underlyingType, StartLoc, PrevSpec,
                          DiagID, Result.release()))
     Diag(StartLoc, DiagID) << PrevSpec;
+  DS.setTypeofParensRange(T.getRange());
 }
 
 /// ParseBaseTypeSpecifier - Parse a C++ base-type-specifier which is either a
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to