@@ -397,6 +397,52 @@ TEST_F(AnalyzeTest, SpellingIncludesWithSymlinks) {
397397 }
398398}
399399
400+ // Make sure that the references to implicit operator new/delete are reported as
401+ // ambigious.
402+ TEST_F (AnalyzeTest, ImplicitOperatorNewDelete) {
403+ ExtraFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>();
404+ ExtraFS->addFile (" header.h" ,
405+ /* ModificationTime=*/ {},
406+ llvm::MemoryBuffer::getMemBufferCopy (guard (R"cpp(
407+ void* operator new(decltype(sizeof(int)));
408+ )cpp" )));
409+ ExtraFS->addFile (" wrapper.h" ,
410+ /* ModificationTime=*/ {},
411+ llvm::MemoryBuffer::getMemBufferCopy (guard (R"cpp(
412+ #include "header.h"
413+ )cpp" )));
414+
415+ // Check that header.h is not reported as missing.
416+ {
417+ Inputs.Code = R"cpp(
418+ #include "wrapper.h"
419+ void bar() {
420+ operator new(3);
421+ })cpp" ;
422+ TestAST AST (Inputs);
423+ std::vector<Decl *> DeclsInTU;
424+ for (auto *D : AST.context ().getTranslationUnitDecl ()->decls ())
425+ DeclsInTU.push_back (D);
426+ auto Results = analyze (DeclsInTU, {}, PP.Includes , &PI, AST.preprocessor ());
427+ EXPECT_THAT (Results.Missing , testing::IsEmpty ());
428+ }
429+
430+ // Check that header.h is not reported as unused.
431+ {
432+ Inputs.Code = R"cpp(
433+ #include "header.h"
434+ void bar() {
435+ operator new(3);
436+ })cpp" ;
437+ TestAST AST (Inputs);
438+ std::vector<Decl *> DeclsInTU;
439+ for (auto *D : AST.context ().getTranslationUnitDecl ()->decls ())
440+ DeclsInTU.push_back (D);
441+ auto Results = analyze (DeclsInTU, {}, PP.Includes , &PI, AST.preprocessor ());
442+ EXPECT_THAT (Results.Unused , Not (testing::IsEmpty ()));
443+ }
444+ }
445+
400446TEST (FixIncludes, Basic) {
401447 llvm::StringRef Code = R"cpp( #include "d.h"
402448#include "a.h"
0 commit comments