From: Nico Weber Date: Wed, 12 Nov 2014 03:52:25 +0000 (+0000) Subject: Mark TypeDecls used in member initializers as referenced. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=09a479e2eb4e2ee5ef9fcc206ad072dbea2aeab7;p=clang Mark TypeDecls used in member initializers as referenced. Without this, -Wunused-local-typedef would incorrectly warn on the two typedefs in this program: void foo() { struct A {}; struct B : public A { typedef A INHERITED; B() : INHERITED() {} typedef B SELF; B(int) : SELF() {} }; } git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@221765 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index f9f9d3ff94..d4cb2fe350 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -2914,6 +2914,7 @@ Sema::BuildMemInitializer(Decl *ConstructorD, if (BaseType.isNull()) { BaseType = Context.getTypeDeclType(TyD); + MarkAnyDeclReferenced(TyD->getLocation(), TyD, /*OdrUse=*/false); if (SS.isSet()) // FIXME: preserve source range information BaseType = Context.getElaboratedType(ETK_None, SS.getScopeRep(), diff --git a/test/SemaCXX/warn-unused-local-typedef.cpp b/test/SemaCXX/warn-unused-local-typedef.cpp index e443427672..1ef0ebfe1a 100644 --- a/test/SemaCXX/warn-unused-local-typedef.cpp +++ b/test/SemaCXX/warn-unused-local-typedef.cpp @@ -213,5 +213,17 @@ void sneaky_memfun_h() { sneaky_memfun_g(sneaky_memfun()); } +void typedefs_in_constructors() { + struct A {}; + struct B : public A { + // Neither of these two should warn: + typedef A INHERITED; + B() : INHERITED() {} + + typedef B SELF; + B(int) : SELF() {} + }; +} + // This should not disable any warnings: #pragma clang diagnostic ignored "-Wunused-local-typedef"