[PATCH] D20054: Fix spurious warnings about unused private field
Olivier Goffart via cfe-commits
cfe-commits at lists.llvm.org
Sun May 8 04:08:12 PDT 2016
ogoffart created this revision.
ogoffart added reviewers: cfe-commits, djasper.
If the address of a field is taken as a pointer to member, we should
not warn that the field is not used.
Normaly, yse of fields are done from MemberExpr, but in case of pointer to
member, it is in a DeclRefExpr
http://reviews.llvm.org/D20054
Files:
lib/Sema/SemaExpr.cpp
test/SemaCXX/warn-unused-private-field.cpp
Index: test/SemaCXX/warn-unused-private-field.cpp
===================================================================
--- test/SemaCXX/warn-unused-private-field.cpp
+++ test/SemaCXX/warn-unused-private-field.cpp
@@ -128,6 +128,7 @@
int *use = &by_reference_;
int test[2];
test[as_array_index_] = 42;
+ int EverythingUsed::*ptr = &EverythingUsed::by_pointer_to_member_;
}
template<class T>
@@ -142,6 +143,7 @@
int by_template_function_;
int as_array_index_;
int by_initializer_;
+ int by_pointer_to_member_;
};
class HasFeatureTest {
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -1736,10 +1736,12 @@
!Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, E->getLocStart()))
recordUseOfEvaluatedWeak(E);
- // Just in case we're building an illegal pointer-to-member.
- FieldDecl *FD = dyn_cast<FieldDecl>(D);
- if (FD && FD->isBitField())
- E->setObjectKind(OK_BitField);
+ if (FieldDecl *FD = dyn_cast<FieldDecl>(D)) {
+ UnusedPrivateFields.remove(FD);
+ // Just in case we're building an illegal pointer-to-member.
+ if (FD->isBitField())
+ E->setObjectKind(OK_BitField);
+ }
return E;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20054.56514.patch
Type: text/x-patch
Size: 1278 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160508/8738b86b/attachment.bin>
More information about the cfe-commits
mailing list