summaryrefslogtreecommitdiffstats
path: root/clang/unittests/AST
diff options
context:
space:
mode:
authorGabor Marton <gabor.marton@ericsson.com>2019-07-02 07:36:39 +0000
committerGabor Marton <gabor.marton@ericsson.com>2019-07-02 07:36:39 +0000
commit4f883f1c39f99bda828a67fc3a18d5fd52a43998 (patch)
treea12e9cd8806e03a7f3c9e43a70b5bde94f8ddc1f /clang/unittests/AST
parent000ef2c2ae0752ae97a99db8dabada7ca2f480f3 (diff)
downloadbcm5719-llvm-4f883f1c39f99bda828a67fc3a18d5fd52a43998.tar.gz
bcm5719-llvm-4f883f1c39f99bda828a67fc3a18d5fd52a43998.zip
[ASTImporter] Structural eq: handle DependentScopeDeclRefExpr
Summary: Structural equivalence did not handle dependent template args properly when the arg contained a DependentScopeDeclRefExpr. Reviewers: a_sidorin, a.sidorin Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62329 llvm-svn: 364889
Diffstat (limited to 'clang/unittests/AST')
-rw-r--r--clang/unittests/AST/StructuralEquivalenceTest.cpp138
1 files changed, 138 insertions, 0 deletions
diff --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp b/clang/unittests/AST/StructuralEquivalenceTest.cpp
index 414cd8d56b3..63757987e11 100644
--- a/clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -892,5 +892,143 @@ TEST_F(StructuralEquivalenceTemplateTest, ExplicitBoolDifference) {
EXPECT_FALSE(testStructuralMatch(First, Second));
}
+struct StructuralEquivalenceDependentTemplateArgsTest
+ : StructuralEquivalenceTemplateTest {};
+
+TEST_F(StructuralEquivalenceDependentTemplateArgsTest,
+ SameStructsInDependentArgs) {
+ std::string Code =
+ R"(
+ template <typename>
+ struct S1;
+
+ template <typename>
+ struct enable_if;
+
+ struct S
+ {
+ template <typename T, typename enable_if<S1<T>>::type>
+ void f();
+ };
+ )";
+ auto t = makeDecls<FunctionTemplateDecl>(Code, Code, Lang_CXX11,
+ functionTemplateDecl(hasName("f")));
+ EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceDependentTemplateArgsTest,
+ DifferentStructsInDependentArgs) {
+ std::string Code =
+ R"(
+ template <typename>
+ struct S1;
+
+ template <typename>
+ struct S2;
+
+ template <typename>
+ struct enable_if;
+ )";
+ auto t = makeDecls<FunctionTemplateDecl>(Code + R"(
+ struct S
+ {
+ template <typename T, typename enable_if<S1<T>>::type>
+ void f();
+ };
+ )",
+ Code + R"(
+ struct S
+ {
+ template <typename T, typename enable_if<S2<T>>::type>
+ void f();
+ };
+ )",
+ Lang_CXX11,
+ functionTemplateDecl(hasName("f")));
+ EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceDependentTemplateArgsTest,
+ SameStructsInDependentScopeDeclRefExpr) {
+ std::string Code =
+ R"(
+ template <typename>
+ struct S1;
+
+ template <bool>
+ struct enable_if;
+
+ struct S
+ {
+ template <typename T, typename enable_if<S1<T>::value>::type>
+ void f(); // DependentScopeDeclRefExpr:^^^^^^^^^^^^
+ };
+ )";
+ auto t = makeDecls<FunctionTemplateDecl>(Code, Code, Lang_CXX11,
+ functionTemplateDecl(hasName("f")));
+ EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceDependentTemplateArgsTest,
+ DifferentStructsInDependentScopeDeclRefExpr) {
+ std::string Code =
+ R"(
+ template <typename>
+ struct S1;
+
+ template <typename>
+ struct S2;
+
+ template <bool>
+ struct enable_if;
+ )";
+ auto t = makeDecls<FunctionTemplateDecl>(Code + R"(
+ struct S
+ {
+ template <typename T, typename enable_if<S1<T>::value>::type>
+ void f(); // DependentScopeDeclRefExpr:^^^^^^^^^^^^
+ };
+ )",
+ Code + R"(
+ struct S
+ {
+ template <typename T, typename enable_if<S2<T>::value>::type>
+ void f();
+ };
+ )",
+ Lang_CXX,
+ functionTemplateDecl(hasName("f")));
+ EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceDependentTemplateArgsTest,
+ DifferentValueInDependentScopeDeclRefExpr) {
+ std::string Code =
+ R"(
+ template <typename>
+ struct S1;
+
+ template <bool>
+ struct enable_if;
+ )";
+ auto t = makeDecls<FunctionTemplateDecl>(Code + R"(
+ struct S
+ {
+ template <typename T, typename enable_if<S1<T>::value1>::type>
+ void f(); // DependentScopeDeclRefExpr:^^^^^^^^^^^^
+ };
+ )",
+ Code + R"(
+ struct S
+ {
+ template <typename T, typename enable_if<S1<T>::value2>::type>
+ void f();
+ };
+ )",
+ Lang_CXX,
+ functionTemplateDecl(hasName("f")));
+ EXPECT_FALSE(testStructuralMatch(t));
+}
+
} // end namespace ast_matchers
} // end namespace clang
OpenPOWER on IntegriCloud