@@ -5998,6 +5998,77 @@ TEST_P(ImportFunctions, CTADUserDefinedExplicit) {
5998
5998
EXPECT_TRUE (ToD->isExplicit ());
5999
5999
}
6000
6000
6001
+ // FIXME Move these tests out of ASTImporterTest. For that we need to factor
6002
+ // out the ASTImporter specific pars from ASTImporterOptionSpecificTestBase
6003
+ // into a new test Fixture. Then we should lift up this Fixture to its own
6004
+ // implementation file and only then could we reuse the Fixture in other AST
6005
+ // unitttests.
6006
+ struct CTAD : ASTImporterOptionSpecificTestBase {};
6007
+
6008
+ TEST_P (CTAD, DeductionGuideShouldReferToANonLocalTypedef) {
6009
+ Decl *TU = getTuDecl (
6010
+ R"(
6011
+ typedef int U;
6012
+ template <typename T> struct A {
6013
+ A(U, T);
6014
+ };
6015
+ A a{(int)0, (int)0};
6016
+ )" ,
6017
+ Lang_CXX17, " input.cc" );
6018
+ auto *Guide = FirstDeclMatcher<CXXDeductionGuideDecl>().match (
6019
+ TU, cxxDeductionGuideDecl ());
6020
+ auto *Typedef = FirstDeclMatcher<TypedefNameDecl>().match (
6021
+ TU, typedefNameDecl (hasName (" U" )));
6022
+ ParmVarDecl *Param = Guide->getParamDecl (0 );
6023
+ // The type of the first param (which is a typedef) should match the typedef
6024
+ // in the global scope.
6025
+ EXPECT_EQ (Param->getType ()->getAs <TypedefType>()->getDecl (), Typedef);
6026
+ }
6027
+
6028
+ TEST_P (CTAD, DeductionGuideShouldReferToANonLocalTypedefInParamPtr) {
6029
+ Decl *TU = getTuDecl (
6030
+ R"(
6031
+ typedef int U;
6032
+ template <typename T> struct A {
6033
+ A(U*, T);
6034
+ };
6035
+ A a{(int*)0, (int)0};
6036
+ )" ,
6037
+ Lang_CXX17, " input.cc" );
6038
+ auto *Guide = FirstDeclMatcher<CXXDeductionGuideDecl>().match (
6039
+ TU, cxxDeductionGuideDecl ());
6040
+ auto *Typedef = FirstDeclMatcher<TypedefNameDecl>().match (
6041
+ TU, typedefNameDecl (hasName (" U" )));
6042
+ ParmVarDecl *Param = Guide->getParamDecl (0 );
6043
+ EXPECT_EQ (Param->getType ()
6044
+ ->getAs <PointerType>()
6045
+ ->getPointeeType ()
6046
+ ->getAs <TypedefType>()
6047
+ ->getDecl (),
6048
+ Typedef);
6049
+ }
6050
+
6051
+ TEST_P (CTAD, DeductionGuideShouldCopyALocalTypedef) {
6052
+ Decl *TU = getTuDecl (
6053
+ R"(
6054
+ template <typename T> struct A {
6055
+ typedef T U;
6056
+ A(U, T);
6057
+ };
6058
+ A a{(int)0, (int)0};
6059
+ )" ,
6060
+ Lang_CXX17, " input.cc" );
6061
+ auto *Guide = FirstDeclMatcher<CXXDeductionGuideDecl>().match (
6062
+ TU, cxxDeductionGuideDecl ());
6063
+ auto *Typedef = FirstDeclMatcher<TypedefNameDecl>().match (
6064
+ TU, typedefNameDecl (hasName (" U" )));
6065
+ ParmVarDecl *Param = Guide->getParamDecl (0 );
6066
+ EXPECT_NE (Param->getType ()->getAs <TypedefType>()->getDecl (), Typedef);
6067
+ }
6068
+
6069
+ INSTANTIATE_TEST_CASE_P (ParameterizedTests, CTAD,
6070
+ DefaultTestValuesForRunOptions, );
6071
+
6001
6072
INSTANTIATE_TEST_CASE_P (ParameterizedTests, ASTImporterLookupTableTest,
6002
6073
DefaultTestValuesForRunOptions, );
6003
6074
0 commit comments