From a4bdcdadc6ffab250b218bbdae9a0ced05bebfc9 Mon Sep 17 00:00:00 2001 From: Sam McCall Date: Mon, 19 Oct 2020 23:36:50 +0200 Subject: Support Attr in DynTypedNode and ASTMatchers. Differential Revision: https://reviews.llvm.org/D89743 --- .../unittests/ASTMatchers/ASTMatchersNodeTest.cpp | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp') diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp index c24598d..6fb4372 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp @@ -1885,6 +1885,29 @@ TEST_P(ASTMatchersTest, NestedNameSpecifier) { nestedNameSpecifier())); } +TEST_P(ASTMatchersTest, Attr) { + // Windows adds some implicit attributes. + bool AutomaticAttributes = StringRef(GetParam().Target).contains("win32"); + if (GetParam().isCXX11OrLater()) { + EXPECT_TRUE(matches("struct [[clang::warn_unused_result]] F{};", attr())); + + // Unknown attributes are not parsed into an AST node. + if (!AutomaticAttributes) + EXPECT_TRUE(notMatches("int x [[unknownattr]];", attr())); + } + } + if (GetParam().isCXX17OrLater()) { + EXPECT_TRUE(matches("struct [[nodiscard]] F{};", attr())); + } + EXPECT_TRUE(matches("int x(int * __attribute__((nonnull)) );", attr())); + if (!AutomaticAttributes) { + EXPECT_TRUE(notMatches("struct F{}; int x(int *);", attr())); + // Some known attributes are not parsed into an AST node. + EXPECT_TRUE(notMatches("typedef int x __attribute__((ext_vector_type(1)));", + attr())); + } +} + TEST_P(ASTMatchersTest, NullStmt) { EXPECT_TRUE(matches("void f() {int i;;}", nullStmt())); EXPECT_TRUE(notMatches("void f() {int i;}", nullStmt())); -- cgit v1.1