compilerplugins/clang/test/unusedmember.cxx | 15 +++++++++++++++ compilerplugins/clang/unusedmember.cxx | 7 +++++++ sal/rtl/math.cxx | 2 -- 3 files changed, 22 insertions(+), 2 deletions(-)
New commits: commit c5c8e28959cc379452b15aa250ca7151a9e3d370 Author: Stephan Bergmann <[email protected]> AuthorDate: Mon Sep 22 11:33:09 2025 +0200 Commit: Stephan Bergmann <[email protected]> CommitDate: Mon Sep 22 16:53:44 2025 +0200 Avoid some lopluign:unusedmember false positives Change-Id: Iad8ff67ed9df8d242ff996b8a1082ad85b2e6dea Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191322 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <[email protected]> diff --git a/compilerplugins/clang/test/unusedmember.cxx b/compilerplugins/clang/test/unusedmember.cxx index 90f3051b98ee..47179db7b859 100644 --- a/compilerplugins/clang/test/unusedmember.cxx +++ b/compilerplugins/clang/test/unusedmember.cxx @@ -250,6 +250,21 @@ template <typename T> void f1() { (void)offsetof(T, i); } void f() { f1<S<void>>(); } } +namespace TemplatedBlockScope +{ +template <typename T> void f() +{ + T t; + struct S + { + S() {} + void f() {} + }; + S s; + s.f(); +} +} + int main() { (void)&Enum::f; diff --git a/compilerplugins/clang/unusedmember.cxx b/compilerplugins/clang/unusedmember.cxx index 45007b1f752b..1ad2326fba9c 100644 --- a/compilerplugins/clang/unusedmember.cxx +++ b/compilerplugins/clang/unusedmember.cxx @@ -128,6 +128,13 @@ public: { continue; } + // Members of classes defined at block scope in a function template seem to not be + // marked as referenced, so filter them out here: + auto const d1 = cast_or_null<FunctionDecl>(d->getParentFunctionOrMethod()); + if (d1 != nullptr && d1->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate) + { + continue; + } if (d->hasAttr<UnusedAttr>()) { continue; diff --git a/sal/rtl/math.cxx b/sal/rtl/math.cxx index 60e438a2db22..dfcc924745ec 100644 --- a/sal/rtl/math.cxx +++ b/sal/rtl/math.cxx @@ -231,7 +231,6 @@ double stringToDouble(CharT const* pBegin, CharT const* pEnd, CharT cDecSeparato char* string = stringOnStack; const CharT** map = mapOnStack; size_t pos = 0; - // [-loplugin:unusedmember] false positive Buf_t(size_t bufsize) { if (bufsize > 256) @@ -243,7 +242,6 @@ double stringToDouble(CharT const* pBegin, CharT const* pEnd, CharT cDecSeparato } // coverity[uninit_member] - mapOnStack contents intentionally not initialized } - // [-loplugin:unusedmember] false positive void insert(char c, const CharT* ptr) { string[pos] = c;
