From: Nico Weber Date: Wed, 12 Nov 2014 04:33:52 +0000 (+0000) Subject: Mark TypeDecls used in explicit destructor calls as referenced. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ff0fd44a390e15ff9eed84a74947b5beabf96caa;p=clang Mark TypeDecls used in explicit destructor calls as referenced. Fixes PR21221. Patch by Axel Naumann, test by me. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@221771 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index b035f8ff49..5b861ad545 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -200,6 +200,7 @@ ParsedType Sema::getDestructorName(SourceLocation TildeLoc, if (TypeDecl *Type = Found.getAsSingle()) { QualType T = Context.getTypeDeclType(Type); + MarkAnyDeclReferenced(Type->getLocation(), Type, /*OdrUse=*/false); if (SearchType.isNull() || SearchType->isDependentType() || Context.hasSameUnqualifiedType(T, SearchType)) { diff --git a/test/SemaCXX/warn-unused-local-typedef.cpp b/test/SemaCXX/warn-unused-local-typedef.cpp index 1ef0ebfe1a..a9406531d2 100644 --- a/test/SemaCXX/warn-unused-local-typedef.cpp +++ b/test/SemaCXX/warn-unused-local-typedef.cpp @@ -225,5 +225,18 @@ void typedefs_in_constructors() { }; } +void *operator new(__SIZE_TYPE__, void *p) throw() { return p; } +void placement_new_and_delete() { + struct MyStruct { }; + char memory[sizeof(MyStruct)]; + void *p = memory; + + typedef MyStruct A_t1; + MyStruct *a = new (p) A_t1(); + + typedef MyStruct A_t2; + a->~A_t2(); +} + // This should not disable any warnings: #pragma clang diagnostic ignored "-Wunused-local-typedef"