@@ -397,6 +397,55 @@ TEST_F(AnalyzeTest, SpellingIncludesWithSymlinks) {
397
397
}
398
398
}
399
399
400
+ // Make sure that the references to implicit operator new/delete are reported as
401
+ // ambigious.
402
+ TEST_F (AnalyzeTest, ImplicitOperatorNewDeleteNotMissing) {
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
+ Inputs.Code = R"cpp(
416
+ #include "wrapper.h"
417
+ void bar() {
418
+ operator new(3);
419
+ })cpp" ;
420
+ TestAST AST (Inputs);
421
+ std::vector<Decl *> DeclsInTU;
422
+ for (auto *D : AST.context ().getTranslationUnitDecl ()->decls ())
423
+ DeclsInTU.push_back (D);
424
+ auto Results = analyze (DeclsInTU, {}, PP.Includes , &PI, AST.preprocessor ());
425
+ EXPECT_THAT (Results.Missing , testing::IsEmpty ());
426
+ }
427
+
428
+ TEST_F (AnalyzeTest, ImplicitOperatorNewDeleteNotUnused) {
429
+ ExtraFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>();
430
+ ExtraFS->addFile (" header.h" ,
431
+ /* ModificationTime=*/ {},
432
+ llvm::MemoryBuffer::getMemBufferCopy (guard (R"cpp(
433
+ void* operator new(decltype(sizeof(int)));
434
+ )cpp" )));
435
+
436
+ Inputs.Code = R"cpp(
437
+ #include "header.h"
438
+ void bar() {
439
+ operator new(3);
440
+ })cpp" ;
441
+ TestAST AST (Inputs);
442
+ std::vector<Decl *> DeclsInTU;
443
+ for (auto *D : AST.context ().getTranslationUnitDecl ()->decls ())
444
+ DeclsInTU.push_back (D);
445
+ auto Results = analyze (DeclsInTU, {}, PP.Includes , &PI, AST.preprocessor ());
446
+ EXPECT_THAT (Results.Unused , testing::IsEmpty ());
447
+ }
448
+
400
449
TEST (FixIncludes, Basic) {
401
450
llvm::StringRef Code = R"cpp( #include "d.h"
402
451
#include "a.h"
0 commit comments