Files
odfstudio/compilerplugins/clang/test/smartpointerderefaddress.cxx
T
Neil Roberts 32e937ae2d Expand the smartpointerderefaddress compiler plugin to more ptr types
Instead of having a hard-coded list of smart pointer types, the plugin
now checks if the called type has a method called “get” which returns a
pointer with the same type as the overall expression. The intention is
that this should be general enough to catch all smart pointers.

Change-Id: I8c6f21f34a9debb81765155c544d0564c0f8ec58
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/211848
Reviewed-by: Neil Roberts <nroberts@libreoffice.org>
Tested-by: Jenkins
2026-10-07 19:16:39 +02:00

44 lines
1.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <sal/config.h>
#include <memory>
namespace sw
{
// Mockup of UnoCursorPointer because it’s probably difficult to include the header
class UnoCursorPointer
{
public:
int& operator*() { return *m_pInteger; };
int* get() { return m_pInteger; };
private:
int* m_pInteger;
};
}
int* function1(std::unique_ptr<int>& x)
{
return &*x; // expected-error-re {{'*' followed by '&' operating on '{{.*}}unique_ptr{{.*}}', rather use '.get()' [loplugin:smartpointerderefaddress]}}
}
int* function2(std::shared_ptr<int>& x)
{
return &*x; // expected-error-re {{'*' followed by '&' operating on '{{.*}}shared_ptr{{.*}}', rather use '.get()' [loplugin:smartpointerderefaddress]}}
}
int* function3(sw::UnoCursorPointer& x)
{
return &*x; // expected-error-re {{'*' followed by '&' operating on '{{.*}}UnoCursorPointer{{.*}}', rather use '.get()' [loplugin:smartpointerderefaddress]}}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */