summaryrefslogtreecommitdiffstats
path: root/clang/unittests/AST
diff options
context:
space:
mode:
authorBalazs Keri <1.int32@gmail.com>2019-08-07 12:40:17 +0000
committerBalazs Keri <1.int32@gmail.com>2019-08-07 12:40:17 +0000
commite9719f9e9e96c8822acdefc3dfaf73a6b8fe5a15 (patch)
treee81d00048fb6fe5584789a4b149e38b0c29eb823 /clang/unittests/AST
parente5fa049efaf331cb3175703da59c2875bb652cca (diff)
downloadbcm5719-llvm-e9719f9e9e96c8822acdefc3dfaf73a6b8fe5a15.tar.gz
bcm5719-llvm-e9719f9e9e96c8822acdefc3dfaf73a6b8fe5a15.zip
[ASTImporter] Do not import FunctionTemplateDecl in record twice.
Summary: For functions there is a check to not duplicate the declaration if it is in a record (class). For function templates there was no similar check, if a template (in the same class) was imported multiple times the FunctionTemplateDecl was created multiple times with the same templated FunctionDecl. This can result in problems with the declaration chain. Reviewers: martong, a.sidorin, shafik, a_sidorin Reviewed By: a_sidorin Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65203 llvm-svn: 368163
Diffstat (limited to 'clang/unittests/AST')
-rw-r--r--clang/unittests/AST/ASTImporterTest.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp
index 07beccefbc3..151b279b9b5 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -2389,6 +2389,49 @@ TEST_P(ImportFunctions,
functionDecl(hasName("f"), hasDescendant(declRefExpr()))))));
}
+struct ImportFunctionTemplates : ASTImporterOptionSpecificTestBase {};
+
+TEST_P(ImportFunctionTemplates, ImportFunctionTemplateInRecordDeclTwice) {
+ auto Code =
+ R"(
+ class X {
+ template <class T>
+ void f(T t);
+ };
+ )";
+ Decl *FromTU1 = getTuDecl(Code, Lang_CXX, "input1.cc");
+ auto *FromD1 = FirstDeclMatcher<FunctionTemplateDecl>().match(
+ FromTU1, functionTemplateDecl(hasName("f")));
+ auto *ToD1 = Import(FromD1, Lang_CXX);
+ Decl *FromTU2 = getTuDecl(Code, Lang_CXX, "input2.cc");
+ auto *FromD2 = FirstDeclMatcher<FunctionTemplateDecl>().match(
+ FromTU2, functionTemplateDecl(hasName("f")));
+ auto *ToD2 = Import(FromD2, Lang_CXX);
+ EXPECT_EQ(ToD1, ToD2);
+}
+
+TEST_P(ImportFunctionTemplates,
+ ImportFunctionTemplateWithDefInRecordDeclTwice) {
+ auto Code =
+ R"(
+ class X {
+ template <class T>
+ void f(T t);
+ };
+ template <class T>
+ void X::f(T t) {};
+ )";
+ Decl *FromTU1 = getTuDecl(Code, Lang_CXX, "input1.cc");
+ auto *FromD1 = FirstDeclMatcher<FunctionTemplateDecl>().match(
+ FromTU1, functionTemplateDecl(hasName("f")));
+ auto *ToD1 = Import(FromD1, Lang_CXX);
+ Decl *FromTU2 = getTuDecl(Code, Lang_CXX, "input2.cc");
+ auto *FromD2 = FirstDeclMatcher<FunctionTemplateDecl>().match(
+ FromTU2, functionTemplateDecl(hasName("f")));
+ auto *ToD2 = Import(FromD2, Lang_CXX);
+ EXPECT_EQ(ToD1, ToD2);
+}
+
struct ImportFriendFunctions : ImportFunctions {};
TEST_P(ImportFriendFunctions, ImportFriendFunctionRedeclChainProto) {
@@ -5223,6 +5266,9 @@ INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportFriendFunctionTemplates,
INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportClasses,
DefaultTestValuesForRunOptions, );
+INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportFunctionTemplates,
+ DefaultTestValuesForRunOptions, );
+
INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportFriendFunctions,
DefaultTestValuesForRunOptions, );
OpenPOWER on IntegriCloud