diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2023-03-17 09:58:21 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2023-03-17 10:27:01 +0000 |
commit | f0ff4243d45b11f372a2ed824fbb8806de9cb595 (patch) | |
tree | eca1607c6c861c212eebd204fc529013f1c3d308 | |
parent | f5bfc127ddabf5f94d0cd1c1e4e6727b4dd3f73a (diff) |
Avoid loplugin:unusedmember crash for templated offsetof
Change-Id: I6cbac308d2911a502381067398d72136ca2b5ae3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149045
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
-rw-r--r-- | compilerplugins/clang/test/unusedmember.cxx | 29 | ||||
-rw-r--r-- | compilerplugins/clang/unusedmember.cxx | 4 |
2 files changed, 33 insertions, 0 deletions
diff --git a/compilerplugins/clang/test/unusedmember.cxx b/compilerplugins/clang/test/unusedmember.cxx index a495b786919e..90f3051b98ee 100644 --- a/compilerplugins/clang/test/unusedmember.cxx +++ b/compilerplugins/clang/test/unusedmember.cxx @@ -7,6 +7,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include <cstddef> + namespace Enum { namespace @@ -223,6 +225,31 @@ void f() } } +namespace Offsetof +{ +namespace +{ +struct S +{ + int i; +}; +} +void f() { (void)offsetof(S, i); } +} + +namespace OffsetofTemplate +{ +namespace +{ +template <typename> struct S +{ + int i; +}; +template <typename T> void f1() { (void)offsetof(T, i); } +} +void f() { f1<S<void>>(); } +} + int main() { (void)&Enum::f; @@ -233,6 +260,8 @@ int main() (void)&Aligned::f; (void)&Bases::f; (void)&Unnamed::f; + (void)&Offsetof::f; + (void)&OffsetofTemplate::f; } /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/compilerplugins/clang/unusedmember.cxx b/compilerplugins/clang/unusedmember.cxx index 7ee433ca2387..9cf40d721259 100644 --- a/compilerplugins/clang/unusedmember.cxx +++ b/compilerplugins/clang/unusedmember.cxx @@ -220,6 +220,10 @@ public: return true; } auto const t1 = expr->getTypeSourceInfo()->getType(); + if (t1->isTemplateTypeParmType()) + { + return true; + } RecordDecl const* d; if (auto const t2 = t1->getAs<InjectedClassNameType>()) { |