From 6ac83797e033dd0b799455d552c61abd202160b4 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 16 May 2018 09:28:54 +0200 Subject: improve unusedfields loplugin to find constructor-only fields ie. fields that are only touched in the constructor Change-Id: Ia714cbfed9710e47e69ca9f0eb0eac4f7e8b8a86 Reviewed-on: https://gerrit.libreoffice.org/54412 Tested-by: Jenkins Reviewed-by: Noel Grandin --- compilerplugins/clang/unusedfields.cxx | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'compilerplugins/clang/unusedfields.cxx') diff --git a/compilerplugins/clang/unusedfields.cxx b/compilerplugins/clang/unusedfields.cxx index 4095b23324c0..159d8544b635 100644 --- a/compilerplugins/clang/unusedfields.cxx +++ b/compilerplugins/clang/unusedfields.cxx @@ -67,6 +67,7 @@ bool operator < (const MyFieldInfo &lhs, const MyFieldInfo &rhs) // try to limit the voluminous output a little static std::set touchedFromInsideSet; static std::set touchedFromOutsideSet; +static std::set touchedFromOutsideConstructorSet; static std::set readFromSet; static std::set writeToSet; static std::set definitionSet; @@ -186,6 +187,8 @@ void UnusedFields::run() output += "inside:\t" + s.parentClass + "\t" + s.fieldName + "\n"; for (const MyFieldInfo & s : touchedFromOutsideSet) output += "outside:\t" + s.parentClass + "\t" + s.fieldName + "\n"; + for (const MyFieldInfo & s : touchedFromOutsideConstructorSet) + output += "outside-constructor:\t" + s.parentClass + "\t" + s.fieldName + "\n"; for (const MyFieldInfo & s : readFromSet) output += "read:\t" + s.parentClass + "\t" + s.fieldName + "\n"; for (const MyFieldInfo & s : writeToSet) @@ -989,6 +992,8 @@ void UnusedFields::checkTouchedFromOutside(const FieldDecl* fieldDecl, const Exp } else { if (memberExprParentFunction->getParent() == fieldDecl->getParent()) { touchedFromInsideSet.insert(fieldInfo); + if (!constructorDecl) + touchedFromOutsideConstructorSet.insert(fieldInfo); } else { touchedFromOutsideSet.insert(fieldInfo); } -- cgit