Mark TypeDecls used in member initializers as referenced.
authorNico Weber <nicolasweber@gmx.de>
Wed, 12 Nov 2014 03:52:25 +0000 (03:52 +0000)
committerNico Weber <nicolasweber@gmx.de>
Wed, 12 Nov 2014 03:52:25 +0000 (03:52 +0000)
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

clang/lib/Sema/SemaDeclCXX.cpp
clang/test/SemaCXX/warn-unused-local-typedef.cpp

index f9f9d3f..d4cb2fe 100644 (file)
@@ -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(),
index e443427..1ef0ebf 100644 (file)
@@ -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"