/// matches "auto n" and "auto i"
extern const AstTypeMatcher<AutoType> autoType;
+/// Matches types nodes representing C++11 decltype(<expr>) types.
+///
+/// Given:
+/// \code
+/// short i = 1;
+/// int j = 42;
+/// decltype(i + j) result = i + j;
+/// \endcode
+/// decltypeType()
+/// matches "decltype(i + j)"
+extern const AstTypeMatcher<DecltypeType> decltypeType;
+
/// Matches \c AutoType nodes where the deduced type is a specific type.
///
/// Note: There is no \c TypeLoc for the deduced type and thus no
AST_TYPE_TRAVERSE_MATCHER(hasDeducedType, getDeducedType,
AST_POLYMORPHIC_SUPPORTED_TYPES(AutoType));
+/// Matches \c DecltypeType nodes to find out the underlying type.
+///
+/// Given
+/// \code
+/// decltype(1) a = 1;
+/// decltype(2.0) b = 2.0;
+/// \endcode
+/// decltypeType(hasUnderlyingType(isInteger()))
+/// matches "auto a"
+///
+/// Usable as: Matcher<DecltypeType>
+AST_TYPE_TRAVERSE_MATCHER(hasUnderlyingType, getUnderlyingType,
+ AST_POLYMORPHIC_SUPPORTED_TYPES(DecltypeType));
+
/// Matches \c FunctionType nodes.
///
/// Given
const AstTypeMatcher<VariableArrayType> variableArrayType;
const AstTypeMatcher<AtomicType> atomicType;
const AstTypeMatcher<AutoType> autoType;
+const AstTypeMatcher<DecltypeType> decltypeType;
const AstTypeMatcher<FunctionType> functionType;
const AstTypeMatcher<FunctionProtoType> functionProtoType;
const AstTypeMatcher<ParenType> parenType;
REGISTER_MATCHER(decayedType);
REGISTER_MATCHER(decl);
REGISTER_MATCHER(declaratorDecl);
+ REGISTER_MATCHER(decltypeType);
REGISTER_MATCHER(declCountIs);
REGISTER_MATCHER(declRefExpr);
REGISTER_MATCHER(declStmt);
// autoType(hasDeducedType(isInteger()))));
}
+TEST(TypeMatching, MatchesDeclTypes) {
+ EXPECT_TRUE(matches("decltype(1 + 1) sum = 1 + 1;", decltypeType()));
+ EXPECT_TRUE(matches("decltype(1 + 1) sum = 1 + 1;",
+ decltypeType(hasUnderlyingType(isInteger()))));
+}
+
TEST(TypeMatching, MatchesFunctionTypes) {
EXPECT_TRUE(matches("int (*f)(int);", functionType()));
EXPECT_TRUE(matches("void f(int i) {}", functionType()));