@@ -558,5 +558,35 @@ TEST_F(PragmaIncludeTest, ExportInUnnamedBuffer) {
558
558
PI.getExporters (llvm::cantFail (FM->getFileRef (" foo.h" )), *FM),
559
559
testing::ElementsAre (llvm::cantFail (FM->getFileRef (" exporter.h" ))));
560
560
}
561
+
562
+ TEST_F (PragmaIncludeTest, OutlivesFMAndSM) {
563
+ Inputs.Code = R"cpp(
564
+ #include "public.h"
565
+ )cpp" ;
566
+ Inputs.ExtraFiles [" public.h" ] = R"cpp(
567
+ #include "private.h"
568
+ #include "private2.h" // IWYU pragma: export
569
+ )cpp" ;
570
+ Inputs.ExtraFiles [" private.h" ] = R"cpp(
571
+ // IWYU pragma: private, include "public.h"
572
+ )cpp" ;
573
+ Inputs.ExtraFiles [" private2.h" ] = R"cpp(
574
+ // IWYU pragma: private
575
+ )cpp" ;
576
+ build (); // Fills up PI, file/source manager used is destroyed afterwards.
577
+ Inputs.MakeAction = nullptr ; // Don't populate PI anymore.
578
+
579
+ // Now this build gives us a new File&Source Manager.
580
+ TestAST Processed = build ();
581
+ auto &FM = Processed.fileManager ();
582
+ auto PrivateFE = FM.getFile (" private.h" );
583
+ assert (PrivateFE);
584
+ EXPECT_EQ (PI.getPublic (PrivateFE.get ()), " \" public.h\" " );
585
+
586
+ auto Private2FE = FM.getFile (" private2.h" );
587
+ assert (Private2FE);
588
+ EXPECT_THAT (PI.getExporters (Private2FE.get (), FM),
589
+ testing::ElementsAre (llvm::cantFail (FM.getFileRef (" public.h" ))));
590
+ }
561
591
} // namespace
562
592
} // namespace clang::include_cleaner
0 commit comments