summaryrefslogtreecommitdiffstats
path: root/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
diff options
context:
space:
mode:
authorJonas Toth <jonas.toth@gmail.com>2018-09-11 16:09:19 +0000
committerJonas Toth <jonas.toth@gmail.com>2018-09-11 16:09:19 +0000
commit2253878a40594751eb4d9ea3dd00d3d596836bd2 (patch)
tree3d42d75e9123e3c68a74f3e9680a206671f3e403 /clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
parente2da5c525ed05837c6e9e45c58738a9e8794d084 (diff)
downloadbcm5719-llvm-2253878a40594751eb4d9ea3dd00d3d596836bd2.tar.gz
bcm5719-llvm-2253878a40594751eb4d9ea3dd00d3d596836bd2.zip
[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
Diffstat (limited to 'clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp')
-rw-r--r--clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp42
1 files changed, 42 insertions, 0 deletions
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<typename T> void f() { (void) sizeof(sizeof(T() + T())); }",
+ expr(isInstantiationDependent())));
+}
+
+TEST(IsInstantiationDependent, MatchesValueDependent) {
+ EXPECT_TRUE(matches("template<int T> int f() { return T; }",
+ expr(isInstantiationDependent())));
+}
+
+TEST(IsInstantiationDependent, MatchesTypeDependent) {
+ EXPECT_TRUE(matches("template<typename T> T f() { return T(); }",
+ expr(isInstantiationDependent())));
+}
+
+TEST(IsTypeDependent, MatchesTypeDependent) {
+ EXPECT_TRUE(matches("template<typename T> T f() { return T(); }",
+ expr(isTypeDependent())));
+}
+
+TEST(IsTypeDependent, NotMatchesValueDependent) {
+ EXPECT_TRUE(notMatches("template<int T> int f() { return T; }",
+ expr(isTypeDependent())));
+}
+
+TEST(IsValueDependent, MatchesValueDependent) {
+ EXPECT_TRUE(matches("template<int T> int f() { return T; }",
+ expr(isValueDependent())));
+}
+
+TEST(IsValueDependent, MatchesTypeDependent) {
+ EXPECT_TRUE(matches("template<typename T> T f() { return T(); }",
+ expr(isValueDependent())));
+}
+
+TEST(IsValueDependent, MatchesInstantiationDependent) {
+ EXPECT_TRUE(matches(
+ "template<typename T> void f() { (void) sizeof(sizeof(T() + T())); }",
+ expr(isValueDependent())));
+}
+
TEST(IsExplicitTemplateSpecialization,
DoesNotMatchPrimaryTemplate) {
EXPECT_TRUE(notMatches(
OpenPOWER on IntegriCloud