r221765 - Mark TypeDecls used in member initializers as referenced.
Nico Weber
nicolasweber at gmx.de
Tue Nov 11 19:52:25 PST 2014
Author: nico
Date: Tue Nov 11 21:52:25 2014
New Revision: 221765
URL: http://llvm.org/viewvc/llvm-project?rev=221765&view=rev
Log:
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() {}
};
}
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/SemaCXX/warn-unused-local-typedef.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=221765&r1=221764&r2=221765&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Nov 11 21:52:25 2014
@@ -2914,6 +2914,7 @@ Sema::BuildMemInitializer(Decl *Construc
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(),
Modified: cfe/trunk/test/SemaCXX/warn-unused-local-typedef.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unused-local-typedef.cpp?rev=221765&r1=221764&r2=221765&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-unused-local-typedef.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unused-local-typedef.cpp Tue Nov 11 21:52:25 2014
@@ -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"
More information about the cfe-commits
mailing list