]> granicus.if.org Git - clang/commitdiff
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() {}
  };
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@221765 91177308-0d34-0410-b5e6-96231b3b80d8

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

index f9f9d3ff94e1894927832648b531d668fce58f23..d4cb2fe35044a0c4562a49154ebd266a5a512e62 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 e4434276721f5cec2bfd70a821b82d0bab80270a..1ef0ebfe1acd6ef8c39a4c86cb40036c2914d2fe 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"