Index: docs/LibASTMatchersReference.html =================================================================== --- docs/LibASTMatchersReference.html +++ docs/LibASTMatchersReference.html @@ -1872,6 +1872,11 @@ integerLiteral(equals(42)) matches 42 +Note that you cannot directly match negative integers, as clang does +not have that notion. To match -3, use: + unaryOperator(hasOperatorName("-"), + hasUnaryOperand(integerLiteral(equals(13)))) + Usable as: Matcher<CharacterLiteral>, Matcher<CXXBoolLiteralExpr>, Matcher<FloatingLiteral>, Matcher<IntegerLiteral> @@ -2327,6 +2332,11 @@ integerLiteral(equals(42)) matches 42 +Note that you cannot directly match negative integers, as clang does +not have that notion. To match -3, use: + unaryOperator(hasOperatorName("-"), + hasUnaryOperand(integerLiteral(equals(13)))) + Usable as: Matcher<CharacterLiteral>, Matcher<CXXBoolLiteralExpr>, Matcher<FloatingLiteral>, Matcher<IntegerLiteral> @@ -2583,6 +2593,11 @@ integerLiteral(equals(42)) matches 42 +Note that you cannot directly match negative integers, as clang does +not have that notion. To match -3, use: + unaryOperator(hasOperatorName("-"), + hasUnaryOperand(integerLiteral(equals(13)))) + Usable as: Matcher<CharacterLiteral>, Matcher<CXXBoolLiteralExpr>, Matcher<FloatingLiteral>, Matcher<IntegerLiteral> @@ -2866,6 +2881,11 @@ integerLiteral(equals(42)) matches 42 +Note that you cannot directly match negative integers, as clang does +not have that notion. To match -3, use: + unaryOperator(hasOperatorName("-"), + hasUnaryOperand(integerLiteral(equals(13)))) + Usable as: Matcher<CharacterLiteral>, Matcher<CXXBoolLiteralExpr>, Matcher<FloatingLiteral>, Matcher<IntegerLiteral> Index: include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- include/clang/ASTMatchers/ASTMatchers.h +++ include/clang/ASTMatchers/ASTMatchers.h @@ -3821,6 +3821,11 @@ /// integerLiteral(equals(42)) /// matches 42 /// +/// Note that you cannot directly match negative integers, as clang does +/// not have that notion. To match -3, use: +/// unaryOperator(hasOperatorName("-"), +/// hasUnaryOperand(integerLiteral(equals(13)))) +/// /// Usable as: Matcher, Matcher, /// Matcher, Matcher template Index: unittests/ASTMatchers/ASTMatchersNodeTest.cpp =================================================================== --- unittests/ASTMatchers/ASTMatchersNodeTest.cpp +++ unittests/ASTMatchers/ASTMatchersNodeTest.cpp @@ -666,6 +666,12 @@ EXPECT_TRUE(notMatches("int i = 'a';", HasIntLiteral)); EXPECT_TRUE(notMatches("int i = 1e10;", HasIntLiteral)); EXPECT_TRUE(notMatches("int i = 10.0;", HasIntLiteral)); + + // Negative integers. + EXPECT_TRUE(matches("int i = -10;", + unaryOperator( + hasOperatorName("-"), + hasUnaryOperand(integerLiteral(equals(10)))))); } TEST(Matcher, FloatLiterals) {