@@ -4540,6 +4540,162 @@ TEST_P(ImportFriendClasses, ImportOfClassDefinitionAndFwdFriendShouldBeLinked) {
4540
4540
EXPECT_EQ (ImportedFwd, ImportedDef->getPreviousDecl ());
4541
4541
}
4542
4542
4543
+ TEST_P (ImportFriendClasses,
4544
+ ImportFriendTemplatesInDependentContext_DefToFriend) {
4545
+ Decl *ToTU = getToTuDecl (
4546
+ R"(
4547
+ template<class T1>
4548
+ struct X {
4549
+ template<class T2>
4550
+ friend struct Y;
4551
+ };
4552
+ )" ,
4553
+ Lang_CXX03);
4554
+ auto *ToYFriend = FirstDeclMatcher<ClassTemplateDecl>().match (
4555
+ ToTU, classTemplateDecl (hasName (" Y" )));
4556
+ Decl *FromTU = getTuDecl (
4557
+ R"(
4558
+ template<class T1>
4559
+ struct Y {};
4560
+ )" ,
4561
+ Lang_CXX03, " input0.cc" );
4562
+ auto *FromYDef = FirstDeclMatcher<ClassTemplateDecl>().match (
4563
+ FromTU, classTemplateDecl (hasName (" Y" )));
4564
+ auto *ImportedYDef = Import (FromYDef, Lang_CXX03);
4565
+ EXPECT_TRUE (ImportedYDef);
4566
+ EXPECT_FALSE (ImportedYDef->getPreviousDecl ());
4567
+ EXPECT_NE (ImportedYDef, ToYFriend);
4568
+ }
4569
+
4570
+ TEST_P (ImportFriendClasses,
4571
+ ImportFriendTemplatesInDependentContext_DefToFriend_NE) {
4572
+ getToTuDecl (
4573
+ R"(
4574
+ template<class T1>
4575
+ struct X {
4576
+ template<class T2>
4577
+ friend struct Y;
4578
+ };
4579
+ )" ,
4580
+ Lang_CXX03);
4581
+ Decl *FromTU = getTuDecl (
4582
+ R"(
4583
+ template<class T1, class T2>
4584
+ struct Y {};
4585
+ )" ,
4586
+ Lang_CXX03, " input0.cc" );
4587
+ auto *FromYDef = FirstDeclMatcher<ClassTemplateDecl>().match (
4588
+ FromTU, classTemplateDecl (hasName (" Y" )));
4589
+ auto *ImportedYDef = Import (FromYDef, Lang_CXX03);
4590
+ EXPECT_FALSE (ImportedYDef);
4591
+ }
4592
+
4593
+ TEST_P (ImportFriendClasses,
4594
+ ImportFriendTemplatesInDependentContext_FriendToFriend) {
4595
+ Decl *ToTU = getToTuDecl (
4596
+ R"(
4597
+ template<class T1>
4598
+ struct X {
4599
+ template<class T2>
4600
+ friend struct Y;
4601
+ };
4602
+ )" ,
4603
+ Lang_CXX03);
4604
+ auto *ToYFriend = FirstDeclMatcher<ClassTemplateDecl>().match (
4605
+ ToTU, classTemplateDecl (hasName (" Y" )));
4606
+ Decl *FromTU = getTuDecl (
4607
+ R"(
4608
+ template<class T1>
4609
+ struct X {
4610
+ template<class T2>
4611
+ friend struct Y;
4612
+ };
4613
+ )" ,
4614
+ Lang_CXX03, " input0.cc" );
4615
+ auto *FromYFriend = FirstDeclMatcher<ClassTemplateDecl>().match (
4616
+ FromTU, classTemplateDecl (hasName (" Y" )));
4617
+ auto *ImportedYFriend = Import (FromYFriend, Lang_CXX03);
4618
+ EXPECT_TRUE (ImportedYFriend);
4619
+ EXPECT_FALSE (ImportedYFriend->getPreviousDecl ());
4620
+ EXPECT_NE (ImportedYFriend, ToYFriend);
4621
+ }
4622
+
4623
+ TEST_P (ImportFriendClasses,
4624
+ ImportFriendTemplatesInDependentContext_FriendToFriend_NE) {
4625
+ getToTuDecl (
4626
+ R"(
4627
+ template<class T1>
4628
+ struct X {
4629
+ template<class T2>
4630
+ friend struct Y;
4631
+ };
4632
+ )" ,
4633
+ Lang_CXX03);
4634
+ Decl *FromTU = getTuDecl (
4635
+ R"(
4636
+ template<class T1>
4637
+ struct X {
4638
+ template<class T2, class T3>
4639
+ friend struct Y;
4640
+ };
4641
+ )" ,
4642
+ Lang_CXX03, " input0.cc" );
4643
+ auto *FromYFriend = FirstDeclMatcher<ClassTemplateDecl>().match (
4644
+ FromTU, classTemplateDecl (hasName (" Y" )));
4645
+ auto *ImportedYFriend = Import (FromYFriend, Lang_CXX03);
4646
+ EXPECT_FALSE (ImportedYFriend);
4647
+ }
4648
+
4649
+ TEST_P (ImportFriendClasses,
4650
+ ImportFriendTemplatesInDependentContext_FriendToDef) {
4651
+ Decl *ToTU = getToTuDecl (
4652
+ R"(
4653
+ template<class T1>
4654
+ struct Y {};
4655
+ )" ,
4656
+ Lang_CXX03);
4657
+ auto *ToYDef = FirstDeclMatcher<ClassTemplateDecl>().match (
4658
+ ToTU, classTemplateDecl (hasName (" Y" )));
4659
+ Decl *FromTU = getTuDecl (
4660
+ R"(
4661
+ template<class T1>
4662
+ struct X {
4663
+ template<class T2>
4664
+ friend struct Y;
4665
+ };
4666
+ )" ,
4667
+ Lang_CXX03, " input0.cc" );
4668
+ auto *FromYFriend = FirstDeclMatcher<ClassTemplateDecl>().match (
4669
+ FromTU, classTemplateDecl (hasName (" Y" )));
4670
+ auto *ImportedYFriend = Import (FromYFriend, Lang_CXX03);
4671
+ EXPECT_TRUE (ImportedYFriend);
4672
+ EXPECT_FALSE (ImportedYFriend->getPreviousDecl ());
4673
+ EXPECT_NE (ImportedYFriend, ToYDef);
4674
+ }
4675
+
4676
+ TEST_P (ImportFriendClasses,
4677
+ ImportFriendTemplatesInDependentContext_FriendToDef_NE) {
4678
+ getToTuDecl (
4679
+ R"(
4680
+ template<class T1>
4681
+ struct Y {};
4682
+ )" ,
4683
+ Lang_CXX03);
4684
+ Decl *FromTU = getTuDecl (
4685
+ R"(
4686
+ template<class T1>
4687
+ struct X {
4688
+ template<class T2, class T3>
4689
+ friend struct Y;
4690
+ };
4691
+ )" ,
4692
+ Lang_CXX03, " input0.cc" );
4693
+ auto *FromYFriend = FirstDeclMatcher<ClassTemplateDecl>().match (
4694
+ FromTU, classTemplateDecl (hasName (" Y" )));
4695
+ auto *ImportedYFriend = Import (FromYFriend, Lang_CXX03);
4696
+ EXPECT_FALSE (ImportedYFriend);
4697
+ }
4698
+
4543
4699
TEST_P (ImportFriendClasses, ImportOfRepeatedFriendType) {
4544
4700
const char *Code =
4545
4701
R"(
0 commit comments