@@ -9797,6 +9797,128 @@ TEST_P(ASTImporterOptionSpecificTestBase, ImportMultipleAnonymousEnumDecls) {
9797
9797
ASSERT_NE (ToEnumDeclA, ToEnumDeclB);
9798
9798
}
9799
9799
9800
+ struct ImportTemplateParmDeclDefaultValue
9801
+ : public ASTImporterOptionSpecificTestBase {
9802
+ protected:
9803
+ void checkTemplateParams (RedeclarableTemplateDecl *D) {
9804
+ auto *CanD = cast<RedeclarableTemplateDecl>(D->getCanonicalDecl ());
9805
+ auto *CanNonTypeP = cast<NonTypeTemplateParmDecl>(
9806
+ CanD->getTemplateParameters ()->getParam (0 ));
9807
+ auto *CanTypeP =
9808
+ cast<TemplateTypeParmDecl>(CanD->getTemplateParameters ()->getParam (1 ));
9809
+ auto *CanTemplateP = cast<TemplateTemplateParmDecl>(
9810
+ CanD->getTemplateParameters ()->getParam (2 ));
9811
+ EXPECT_FALSE (CanNonTypeP->getDefaultArgStorage ().isInherited ());
9812
+ EXPECT_FALSE (CanTypeP->getDefaultArgStorage ().isInherited ());
9813
+ EXPECT_FALSE (CanTemplateP->getDefaultArgStorage ().isInherited ());
9814
+ for (Decl *Redecl : D->redecls ()) {
9815
+ auto *ReD = cast<RedeclarableTemplateDecl>(Redecl);
9816
+ if (ReD != CanD) {
9817
+ auto *NonTypeP = cast<NonTypeTemplateParmDecl>(
9818
+ ReD->getTemplateParameters ()->getParam (0 ));
9819
+ auto *TypeP = cast<TemplateTypeParmDecl>(
9820
+ ReD->getTemplateParameters ()->getParam (1 ));
9821
+ auto *TemplateP = cast<TemplateTemplateParmDecl>(
9822
+ ReD->getTemplateParameters ()->getParam (2 ));
9823
+ EXPECT_TRUE (NonTypeP->getDefaultArgStorage ().isInherited ());
9824
+ EXPECT_TRUE (TypeP->getDefaultArgStorage ().isInherited ());
9825
+ EXPECT_TRUE (TemplateP->getDefaultArgStorage ().isInherited ());
9826
+ EXPECT_EQ (NonTypeP->getDefaultArgStorage ().getInheritedFrom (),
9827
+ CanNonTypeP);
9828
+ EXPECT_EQ (TypeP->getDefaultArgStorage ().getInheritedFrom (), CanTypeP);
9829
+ EXPECT_EQ (TemplateP->getDefaultArgStorage ().getInheritedFrom (),
9830
+ CanTemplateP);
9831
+ }
9832
+ }
9833
+ }
9834
+
9835
+ void testImport (RedeclarableTemplateDecl *FromD) {
9836
+ RedeclarableTemplateDecl *ToD = Import (FromD, Lang_CXX14);
9837
+ checkTemplateParams (ToD);
9838
+ }
9839
+
9840
+ const char *CodeFunction =
9841
+ R"(
9842
+ template <class> struct X;
9843
+
9844
+ template <int A = 2, typename B = int, template<class> class C = X>
9845
+ void f();
9846
+ template <int A, typename B, template<class> class C>
9847
+ void f();
9848
+ template <int A, typename B, template<class> class C>
9849
+ void f() {}
9850
+ )" ;
9851
+
9852
+ const char *CodeClass =
9853
+ R"(
9854
+ template <class> struct X;
9855
+
9856
+ template <int A = 2, typename B = int, template<class> class C = X>
9857
+ struct S;
9858
+ template <int A, typename B, template<class> class C>
9859
+ struct S;
9860
+ template <int A, typename B, template<class> class C>
9861
+ struct S {};
9862
+ )" ;
9863
+
9864
+ const char *CodeVar =
9865
+ R"(
9866
+ template <class> struct X;
9867
+
9868
+ template <int A = 2, typename B = int, template<class> class C = X>
9869
+ extern int V;
9870
+ template <int A, typename B, template<class> class C>
9871
+ extern int V;
9872
+ template <int A, typename B, template<class> class C>
9873
+ int V = A;
9874
+ )" ;
9875
+ };
9876
+
9877
+ TEST_P (ImportTemplateParmDeclDefaultValue, ImportFunctionTemplate) {
9878
+ Decl *FromTU = getTuDecl (CodeFunction, Lang_CXX14);
9879
+ auto *FromLastD = LastDeclMatcher<FunctionTemplateDecl>().match (
9880
+ FromTU, functionTemplateDecl (hasName (" f" )));
9881
+ testImport (FromLastD);
9882
+ }
9883
+
9884
+ TEST_P (ImportTemplateParmDeclDefaultValue, ImportExistingFunctionTemplate) {
9885
+ getToTuDecl (CodeFunction, Lang_CXX14);
9886
+ Decl *FromTU = getTuDecl (CodeFunction, Lang_CXX14);
9887
+ auto *FromLastD = LastDeclMatcher<FunctionTemplateDecl>().match (
9888
+ FromTU, functionTemplateDecl (hasName (" f" )));
9889
+ testImport (FromLastD);
9890
+ }
9891
+
9892
+ TEST_P (ImportTemplateParmDeclDefaultValue, ImportClassTemplate) {
9893
+ Decl *FromTU = getTuDecl (CodeClass, Lang_CXX14);
9894
+ auto *FromLastD = LastDeclMatcher<ClassTemplateDecl>().match (
9895
+ FromTU, classTemplateDecl (hasName (" S" )));
9896
+ testImport (FromLastD);
9897
+ }
9898
+
9899
+ TEST_P (ImportTemplateParmDeclDefaultValue, ImportExistingClassTemplate) {
9900
+ getToTuDecl (CodeClass, Lang_CXX14);
9901
+ Decl *FromTU = getTuDecl (CodeClass, Lang_CXX14);
9902
+ auto *FromLastD = LastDeclMatcher<ClassTemplateDecl>().match (
9903
+ FromTU, classTemplateDecl (hasName (" S" )));
9904
+ testImport (FromLastD);
9905
+ }
9906
+
9907
+ TEST_P (ImportTemplateParmDeclDefaultValue, ImportVarTemplate) {
9908
+ Decl *FromTU = getTuDecl (CodeVar, Lang_CXX14);
9909
+ auto *FromLastD = LastDeclMatcher<VarTemplateDecl>().match (
9910
+ FromTU, varTemplateDecl (hasName (" V" )));
9911
+ testImport (FromLastD);
9912
+ }
9913
+
9914
+ TEST_P (ImportTemplateParmDeclDefaultValue, ImportExistingVarTemplate) {
9915
+ getToTuDecl (CodeVar, Lang_CXX14);
9916
+ Decl *FromTU = getTuDecl (CodeVar, Lang_CXX14);
9917
+ auto *FromLastD = LastDeclMatcher<VarTemplateDecl>().match (
9918
+ FromTU, varTemplateDecl (hasName (" V" )));
9919
+ testImport (FromLastD);
9920
+ }
9921
+
9800
9922
INSTANTIATE_TEST_SUITE_P (ParameterizedTests, ASTImporterLookupTableTest,
9801
9923
DefaultTestValuesForRunOptions);
9802
9924
@@ -9880,6 +10002,9 @@ INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ImportInjectedClassNameType,
9880
10002
INSTANTIATE_TEST_SUITE_P (ParameterizedTests, ImportMatrixType,
9881
10003
DefaultTestValuesForRunOptions);
9882
10004
10005
+ INSTANTIATE_TEST_SUITE_P (ParameterizedTests, ImportTemplateParmDeclDefaultValue,
10006
+ DefaultTestValuesForRunOptions);
10007
+
9883
10008
// FIXME: Make ImportOpenCLPipe test work.
9884
10009
// INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ImportOpenCLPipe,
9885
10010
// DefaultTestValuesForRunOptions);
0 commit comments