From 2253878a40594751eb4d9ea3dd00d3d596836bd2 Mon Sep 17 00:00:00 2001 From: Jonas Toth Date: Tue, 11 Sep 2018 16:09:19 +0000 Subject: [ASTMatchers] add three matchers for dependent expressions Summary: The new matchers can be used to check if an expression is type-, value- or instantiation-dependent in a templated context. These matchers are used in a clang-tidy check and generally useful as the problem of unresolved templates occurs more often in clang-tidy and they provide an easy way to check for this issue. Reviewers: aaron.ballman, alexfh, klimek Reviewed By: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D51880 llvm-svn: 341958 --- .../ASTMatchers/ASTMatchersNarrowingTest.cpp | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp') diff --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp index ac73fdfa605..537ffbb8964 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -1768,6 +1768,48 @@ TEST(IsInTemplateInstantiation, Sharing) { Matcher)); } +TEST(IsInstantiationDependent, MatchesNonValueTypeDependent) { + EXPECT_TRUE(matches( + "template void f() { (void) sizeof(sizeof(T() + T())); }", + expr(isInstantiationDependent()))); +} + +TEST(IsInstantiationDependent, MatchesValueDependent) { + EXPECT_TRUE(matches("template int f() { return T; }", + expr(isInstantiationDependent()))); +} + +TEST(IsInstantiationDependent, MatchesTypeDependent) { + EXPECT_TRUE(matches("template T f() { return T(); }", + expr(isInstantiationDependent()))); +} + +TEST(IsTypeDependent, MatchesTypeDependent) { + EXPECT_TRUE(matches("template T f() { return T(); }", + expr(isTypeDependent()))); +} + +TEST(IsTypeDependent, NotMatchesValueDependent) { + EXPECT_TRUE(notMatches("template int f() { return T; }", + expr(isTypeDependent()))); +} + +TEST(IsValueDependent, MatchesValueDependent) { + EXPECT_TRUE(matches("template int f() { return T; }", + expr(isValueDependent()))); +} + +TEST(IsValueDependent, MatchesTypeDependent) { + EXPECT_TRUE(matches("template T f() { return T(); }", + expr(isValueDependent()))); +} + +TEST(IsValueDependent, MatchesInstantiationDependent) { + EXPECT_TRUE(matches( + "template void f() { (void) sizeof(sizeof(T() + T())); }", + expr(isValueDependent()))); +} + TEST(IsExplicitTemplateSpecialization, DoesNotMatchPrimaryTemplate) { EXPECT_TRUE(notMatches( -- cgit v1.2.3