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() {}
  };
}

llvm-svn: 221765
This commit is contained in:
Nico Weber 2014-11-12 03:52:25 +00:00
parent aa0117c628
commit 28309185b2
2 changed files with 13 additions and 0 deletions

View File

@ -2914,6 +2914,7 @@ Sema::BuildMemInitializer(Decl *ConstructorD,
if (BaseType.isNull()) { if (BaseType.isNull()) {
BaseType = Context.getTypeDeclType(TyD); BaseType = Context.getTypeDeclType(TyD);
MarkAnyDeclReferenced(TyD->getLocation(), TyD, /*OdrUse=*/false);
if (SS.isSet()) if (SS.isSet())
// FIXME: preserve source range information // FIXME: preserve source range information
BaseType = Context.getElaboratedType(ETK_None, SS.getScopeRep(), BaseType = Context.getElaboratedType(ETK_None, SS.getScopeRep(),

View File

@ -213,5 +213,17 @@ void sneaky_memfun_h() {
sneaky_memfun_g(sneaky_memfun()); 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: // This should not disable any warnings:
#pragma clang diagnostic ignored "-Wunused-local-typedef" #pragma clang diagnostic ignored "-Wunused-local-typedef"