Commit Graph

461 Commits

Author SHA1 Message Date
Stephan Bergmann
7529dbcb24 Make loplugin:cppunitassetequals diagnostic more informative
...which will come in handy for a later improvement of that plugin

Change-Id: I548b9388bee60b381c0a2c820f20f596aa0072f4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110453
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2021-02-05 21:58:41 +01:00
Stephan Bergmann
dec14c4a07 Avoid --disable-assert-always-abort loplugin:stringviewparam false positives
...like

> l10ntools/source/helper.cxx:19:69: error: replace function parameter of type 'const rtl::OString &' with 'std::string_view' [loplugin:stringviewparam]
>     const OString& rText, const OString& rUnEscaped, const OString& rEscaped )
>                                                      ~~~~~~~~~~~~~~~^~~~~~~~

where the call to rEscaped.getLength(), which would otherwise suppress the
warning, is hidden inside an assert.

(Similar to aab0322580 "Disable
loplugin:casttovoid when --disable-assert-always-abort".)

Change-Id: Ie054f75317707757b1c6243c593f539d445a9fee
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110331
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2021-02-02 20:45:24 +01:00
Noel
068d4108e5 loplugin:redundantcast catch more dynamic_cast
Change-Id: Ia28e58217cefa306567b53688d851fa210b7821c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110287
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2021-02-02 12:24:00 +01:00
Noel
1250aecd71 loplugin:stringviewparam extend to new..
O[U]StringBuffer methods

Change-Id: I0ffbc33d54ae7c98b5652434f3370ee4f819f6f4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110090
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2021-01-29 09:25:12 +01:00
Noel
1da6908173 add string_view variants of methods to O[U]StringBuffer
and update the stringview loplugin to detect cases where we can
use these new methods.

Change-Id: I998efe02e35c8efcb3abfb4d7186165bbe6dfb2c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110046
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2021-01-28 11:11:28 +01:00
Stephan Bergmann
aa2064c5c5 Improve loplugin:stringliteralvar
...to also consider O[U]String ctors taking pointer and length

Change-Id: Iea5041634bfbf5054a1317701e30b56f72e940fb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110025
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2021-01-27 23:24:42 +01:00
Stephan Bergmann
2682feb036 Adapt loplugin:stringconstant to many functions taking string_view args now
So look through (implicit) O[U]String to string_view conversions for those
arguments.

Change-Id: I1101d3f681d227ad0a76a4477bf52a1a3898cfdc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109926
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2021-01-26 08:42:09 +01:00
Noel
6907cbb897 improve loplugin:pointerbool
to look through template instantiations involving std::forward

motivated by
    commit b1617acde1
    drop RadioButton arg defaults
    the nBits arg in builder.cxx was in the wrong place

Change-Id: I222ea2aeea6f44ae54839e824a247a8105392c2d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109789
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2021-01-22 17:46:01 +01:00
Stephan Bergmann
af34108d90 Use C++20 consteval for the Color(sal_uInt32) ctor
...to make it more obvious that, since 63a68064bb
"make the Color constructors explicitly specify transparency", it should only be
called when the argument is known at compile-time to have no transparency/alpha
channel.

(This revealed a GCC bug causing bogus

> xmloff/source/chart/ColorPropertySet.cxx: In constructor ‘xmloff:💹:ColorPropertySet::ColorPropertySet(Color)’:
> xmloff/source/chart/ColorPropertySet.cxx:81:9: error: ‘this’ is not a constant expression
>    81 |         m_nDefaultColor( 0x0099ccff )  // blue 8
>       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

so in configure.ac suppress HAVE_CPP_CONSTEVAL when the compiler is found
broken.)

Change-Id: I68df7bd5fbd9b2dcf2243b5a4bde4064d3d665fd
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109697
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2021-01-21 07:58:02 +01:00
Stephan Bergmann
4b55847b81 Improve loplugin:doubleconvert
(The use of isa_and_nonnull<> instead of isa<> is necessary for cases like

  return (i_styleSettings.*i_getDefaultColor)();

in lcl_getEffectiveColor, svtools/source/table/gridtablerenderer.cxx.)

Change-Id: Iffc59b1146dd4ce13bbd3c8a6f46bd3c78a39344
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109663
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2021-01-20 11:27:33 +01:00
Stephan Bergmann
94f6765d6e Avoid loplugin:stringviewparam when there already is a string_view overload
This avoids clang-cl

> In file included from core/connectivity/source/drivers/ado/Aolevariant.cxx:20:
> connectivity/source/inc\ado/Aolevariant.hxx(72,40): error: replace function parameter of type 'const rtl::OUString &' with 'std::u16string_view' [loplugin:stringviewparam]
>             OLEVariant(const OUString& us)
>                        ~~~~~~~~~~~~~~~~^~

which would make that OLEVariant ctor overload redundant with the existing

  OLEVariant(std::u16string_view us);

overload, but with the OUString overload gone, implicit conversions from
OUString to OLEVariant would no longer work, e.g.,

> connectivity/source/drivers/ado/AColumn.cxx(184,76): error: no viable conversion from 'rtl::OUString' to 'const connectivity::ado::OLEVariant'
>             OTools::putValue(m_aColumn.get_Properties(), sAdoPropertyName, getString(rValue));
>                                                                            ^~~~~~~~~~~~~~~~~

Change-Id: I92a5cc29d9fd2a5ff1a951f79df64879d0f71743
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109180
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2021-01-12 22:28:18 +01:00
Stephan Bergmann
a3d0091d18 New loplugin:stringliteralvar
See the comment at the top of compilerplugins/clang/stringliteralvar.cxx for
details.

(Turned some affected variables in included files into inline variables, to
avoid GCC warnings about unused variables.)

Change-Id: Ie77219e6adfdaaceaa8b4e590b08971f2f04c83a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108239
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-12-26 14:51:15 +01:00
Stephan Bergmann
68a3c364f7 Don't call isIntegerConstantExpr on value dependent Expr
...as it causes Clang to fail with

> Assertion failed: (!isValueDependent() && "Expression evaluator can't be called on a dependent expression."), function isIntegerConstantExpr, file .../llvm/llvm-project/clang/lib/AST/ExprConstant.cpp, line 15487.

Change-Id: I335f7610955c30a5c102bfb3b8aa6441a30dd247
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108241
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-12-23 20:47:47 +01:00
Stephan Bergmann
df810a8205 Fix loplugin:stringviewparam handling of comparison operators
Change-Id: I58456efb9588b544d998ac6a4c27d55457280742
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107510
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-12-09 23:31:17 +01:00
Stephan Bergmann
ff8d82dc4c Improve loplugin:stringview diagnostic messages
Change-Id: If1b94de205fb9c1cc0491603f27073dfde67a485
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107511
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-12-09 23:25:00 +01:00
Stephan Bergmann
6c905fb643 Improve loplugin:stringview detection of unnecessary O[U]String construction
Change-Id: Ia45119e11377e916a1e1deb5648ed9033c417d77
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107228
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-12-04 17:54:48 +01:00
Noel
8332d6d820 loplugin:stringviewparam include comparisons with string literals
Change-Id: I8ba1214500dddaf413c506a4b82f43d63cda804b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106559
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2020-11-30 12:32:14 +01:00
Noel
bb06f51308 loplugin:stringviewparam extend to comparison operators
which means that some call sites have to change to use
unicode string literals i.e. u"foo" instead of "foo"

Change-Id: Ie51c3adf56d343dd1d1710777f9d2a43ee66221c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106125
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2020-11-24 09:45:04 +01:00
Philipp Hofer
c096ab87c8 tdf#123936 Formatting files in module compilerplugins with clang-format
Change-Id: Ie6e23d3d2a20849e47d048b439d72fd7376c53db
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105654
Tested-by: Jenkins
Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
2020-11-22 01:56:05 +01:00
Stephan Bergmann
19926ed35e loplugin:stringview: Flag empty string converted to string view
Change-Id: Idf412dc5f235230512160cb4fb7e1a00baa1cfa7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106085
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-11-19 07:09:58 +01:00
Stephan Bergmann
99076b47b7 Adapt to Clang 12 trunk cosmetic diagnostics changes
<https://github.com/llvm/llvm-project/commit/
e7f3e2103cdb567dda4fd52f81bf4bc07179f5a8> "Suppress printing template arguments
that match default template arguments of types by default" caused

> error: 'error' diagnostics seen but not expected:
>   File /home/sbergman/lo/core/compilerplugins/clang/test/makeshared.cxx Line 58: rather use make_shared than constructing from 'typename std::remove_reference<unique_ptr<int> &>::type' (aka 'std::unique_ptr<int>') [loplugin:makeshared]
>   File /home/sbergman/lo/core/compilerplugins/clang/test/makeshared.cxx Line 60: rather use make_shared than constructing from 'typename std::remove_reference<unique_ptr<int> &>::type' (aka 'std::unique_ptr<int>') [loplugin:makeshared]

in compilerplugins/clang/test/makeshared.cxx, and <https://github.com/llvm/
llvm-project/commit/5f12f4ff9078455cad9d4806da01f570553a5bf9> "Suppress printing
of inline namespace names in diagnostics by default, except where they are
necessary to disambiguate the target" caused

> error: 'note' diagnostics seen but not expected:
>   File /home/sbergman/lo/core/compilerplugins/clang/test/external.cxx Line 133: a function associating 'N::E' is declared here [loplugin:external]
>   File /home/sbergman/lo/core/compilerplugins/clang/test/external.cxx Line 140: a function associating 'N::E' is declared here [loplugin:external]
>   File /home/sbergman/lo/core/compilerplugins/clang/test/external.cxx Line 144: a function associating 'N::E' is declared here [loplugin:external]
>   File /home/sbergman/lo/core/compilerplugins/clang/test/external.cxx Line 167: a function associating 'N::E' is declared here [loplugin:external]
>   File /home/sbergman/lo/core/compilerplugins/clang/test/external.cxx Line 172: a function associating 'N::E' is declared here [loplugin:external]

Change-Id: If1ec798fd9876b5be058c63bcaca3e2a36c0dbb6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105904
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-11-16 08:36:57 +01:00
Noel
4a7e972ea2 loplugin:xmlimport
add check for passing XML_TOK* constants to a non-sal_uInt16 parameter,
which is a sign of an incomplete fastparser conversion.

Change-Id: Icad5bf9eb40fc15fd07b0d9ea79f83ed083de784
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105638
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2020-11-12 18:55:32 +01:00
Stephan Bergmann
f34ac579fa New loplugin:stringviewparam
...to "Find functions that take rtl::O[U]String parameters that can be
generalized to take std::[u16]string_view instead."  (Which in turn can avoid
costly O[U]String constructions, see e.g. loplugin:stringview and subView.)

Some of those functions' call sites, passing plain char string literals, needed
to be adapted when converting them.

Change-Id: I644ab546d7a0ce9e470ab9b3196e3e60d1e812bc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105622
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-11-12 16:53:30 +01:00
Noel
93c64a61f2 loplugin:stringview
Add new methods "subView" to O(U)String to return substring views
of the underlying data.

Add a clang plugin to warn when replacing existing calls to copy()
would be better to use subView().

Change-Id: I03a5732431ce60808946f2ce2c923b22845689ca
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105420
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2020-11-11 11:58:37 +01:00
Noel Grandin
dfb2e07e32 loplugin:xmlimport add more checks
to find places where the slowparser -> fastparser conversion
work is incomplete, fixing one bug in the process.

Change-Id: Ifd0d801d71eee0aaf25287fbac1a4237a811e7c8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105511
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2020-11-11 06:33:32 +01:00
Noel Grandin
242320d303 new loplugin:reducevarscope
Change-Id: Iefe922c2e0d605114d54673d63eccc5e4abd545d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102143
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2020-11-10 17:11:00 +01:00
Noel
8c5ffecf1d make SvXMLImport capable of mixing fast- and slow- contexts adhoc
so I can convert even *ImportContext subclasses in the middle of
a context stack, and thus break the cyclic dependency nature
of the writer import.

and adjust the xmlimport loplugin for the new rules.

As a consequence of the loplugin:xmlimport's checking, we remove
a bunch of now unnecessary overrides of startFastElement.

Change-Id: I97464522ede8ec5e345e928cdafa4b18364b1b80
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104730
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2020-11-02 08:17:00 +01:00
Stephan Bergmann
40fa3a61ac Extend loplugin:elidestringvar to OString
(In VisitVarDecl, filtering out AbstractConditionalOperator avoids an unhelpful

> ~/lo/core/vcl/source/pdf/XmpMetadata.cxx:63:32: error: replace single use of literal 'rtl::OString' variable with a literal [loplugin:elidestringvar]
>             aXmlWriter.content(sPdfConformance);
>                                ^~~~~~~~~~~~~~~
> ~/lo/core/vcl/source/pdf/XmpMetadata.cxx:52:21: note: literal 'rtl::OString' variable defined here [loplugin:elidestringvar]
>             OString sPdfConformance = (mnPDF_A == 1) ? "A" : "B";
>             ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

)

Change-Id: I7d0410f04827d79b4b526752917c37d33cad2671
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104911
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-10-28 08:03:52 +01:00
Stephan Bergmann
24e7fe2035 Fix loplugin:salcall
For one, the addressOfSet filtering was only done for member functions, not for
free functions, which caused false positives in the wild like the one discussed
in the comments at <https://gerrit.libreoffice.org/c/core/+/102024/
4#message-36ec6ee09ed5badae93c552b82a90068e65d19e2> "call xDesktop->terminate()
when catching SIGTERM/SIGINT" regarding a free function
`terminationHandlerFunction` passed to `osl_createThread`.

For another, it failed to identify some cases where the address of a function is
taken implicitly, like for `f3` in compilerplugins/clang/test/salcall.cxx.  So
make this plugin reuse the existing `loplugin::FunctionAddress` functionality
(which also meant to get rid of this plugin's two-phase design).

Change-Id: Ie290c63b03825d5288d982bc8701cfb886fc84b4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104585
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-10-21 15:02:42 +02:00
Stephan Bergmann
c4cec8647f clang-cl: Adapt Windows-specific code to extended loplugin:cstylecast
...after 1ebeacb20a "Extend loplugin:cstylecast to
certain function-style casts"

Change-Id: I99bd383f5b3bee861d442d2e1be6ecd356b78315
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104523
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-10-19 22:01:31 +02:00
Noel Grandin
4487a14e7c loplugin:xmlimport check for bad conversions to fastparser
add a check for classes which have been partly converted to fastparser,
but not completedly.
This is to help me when I convert stuff.

and it uncovers a bug introduced with
    commit 998308c363
    use more FastParser in SvXMLStylesContext

Change-Id: Ib50e7136da10a1a7a346102aa47efef2f543e2ac
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102669
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2020-09-20 17:00:04 +02:00
Stephan Bergmann
ccd073e044 Adapt compilerplugins/clang/test/unusedvarsglobal.cxx
...to e6dfaf9f44 "Turn OUStringLiteral into a
consteval'ed, static-refcound rtl_uString".  (The original code would have
started to fail with

> error: 'error' diagnostics seen but not expected:
>   File compilerplugins/clang/test/unusedvarsglobal.cxx Line 22: declaration of variable 'literal1' with deduced type 'const OUStringLiteral' requires an initializer

when built with Clang >= 11.)

Change-Id: If51a39c8fb42200f064d62f472e8cddcc6e4c434
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102898
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Tested-by: Jenkins
2020-09-17 15:15:32 +02:00
Stephan Bergmann
e6dfaf9f44 Turn OUStringLiteral into a consteval'ed, static-refcound rtl_uString
...from which an OUString can cheaply be instantiated.  This is the OUString
equivalent of 4b9e440c51 "Turn OStringLiteral into
a consteval'ed, static-refcound rtl_String".  Most remarks about that commit
apply here too (this commit is just substantially bigger and a bit more
complicated because there were so much more uses of OUStringLiteral than of
OStringLiteral):

The one downside is that OUStringLiteral now needs to be a template abstracting
over the string length.  But any uses for which that is a problem (e.g., as the
element type of a container that would no longer be homogeneous, or in the
signature of a function that shall not be turned into a template for one reason
or another) can be replaced with std::u16string_view, without loss of efficiency
compared to the original OUStringLiteral, and without loss of expressivity.

The new OUStringLiteral ctor code would probably not be very efficient if it
were ever executed at runtime, but it is intended to be only executed at compile
time.  Where available, C++20 "consteval" is used to statically ensure that.

The intended use of the new OUStringLiteral is in all cases where an
object that shall itself not be an OUString (e.g., because it shall be a
global static variable for which the OUString ctor/dtor would be detrimental at
library load/unload) must be converted to an OUString instance in at least one
place.  Other string literal abstractions could use std::u16string_view (or just
plain char16_t const[N]), but interestingly OUStringLiteral might be more
efficient than constexpr std::u16string_view even for such cases, as it should
not need any relocations at library load time.  For now, no existing uses of
OUStringLiteral have been changed to some other abstraction (unless technically
necessary as discussed above), and no additional places that would benefit from
OUStringLiteral have been changed to use it.

Global constexpr OUStringLiteral variables defined in an included file would be
somewhat suboptimal, as each translation unit that uses them would create its
own, unshared instance.  The envisioned solution is to turn them into static
data members of some class (and there may be a loplugin coming to find and fix
affected places).  Another approach that has been taken here in a few cases
where such variables were only used in one .cxx anyway is to move their
definitions from the .hxx into that one .cxx (in turn causing some files to
become empty and get removed completely)---which also silenced some GCC
-Werror=unused-variable if a variable from a .hxx was not used in some .cxx
including it.

To keep individual commits reasonably manageable, some consumers of
OUStringLiteral in rtl/ustrbuf.hxx and rtl/ustring.hxx are left in a somewhat
odd state for now, where they don't take advantage of OUStringLiteral's
equivalence to rtl_uString, but just keep extracting its contents and copy it
elsewhere.  In follow-up commits, those consumers should be changed
appropriately, making them treat OUStringLiteral like an rtl_uString or
dropping the OUStringLiteral overload in favor of an existing (and cheap to use
now) OUString overload, etc.

In a similar vein, comparison operators between OUString and std::u16string_view
have been added to the existing plethora of comparison operator overloads.  It
would be nice to eventually consolidate them, esp. with the overloads taking
OUStringLiteral and/or char16_t const[N] string literals, but that appears
tricky to get right without introducing new ambiguities.  Also, a handful of
places across the code base use comparisons between OUString and OUStringNumber,
which are now ambiguous (converting the OUStringNumber to either OUString or
std::u16string_view).  For simplicity, those few places have manually been fixed
for now by adding explicit conversion to std::u16string_view.

Also some compilerplugins code needed to be adapted, and some of the
compilerplugins/test cases have become irrelevant (and have been removed), as
the tested code would no longer compile in the first place.

sal/qa/rtl/strings/test_oustring_concat.cxx documents a workaround for GCC bug
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96878> "Failed class template
argument deduction in unevaluated, parenthesized context".  That place, as well
as uses of OUStringLiteral in extensions/source/abpilot/fieldmappingimpl.cxx and
i18npool/source/localedata/localedata.cxx, which have been replaced with
OUString::Concat (and which is arguably a better choice, anyway), also caused
failures with at least Clang 5.0.2 (but would not have caused failures with at
least recent Clang 12 trunk, so appear to be bugs in Clang that have meanwhile
been fixed).

Change-Id: I34174462a28f2000cfeb2d219ffd533a767920b8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102222
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-09-16 23:02:09 +02:00
Noel Grandin
f2517e8290 improve loplugin:unusedvarsglobal
to find any global variable, was checking the wrong property of
VarDecl

Change-Id: I454b4e0c1701bb0771768a1ee10cd738c4ab0726
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102278
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2020-09-09 08:25:30 +02:00
George Bateman
7021dae811 tdf#124176 Use #pragma once in compilerplugins
This commit was carried out by a Python script, source of which
is at https://bugs.documentfoundation.org/show_bug.cgi?id=124176#c97.

Change-Id: Id60579406a5aa16c3dc05a1bb5f1c1c828d39c50
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100251
Tested-by: Jenkins
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
2020-09-04 11:13:17 +02:00
Stephan Bergmann
4b9e440c51 Turn OStringLiteral into a consteval'ed, static-refcound rtl_String
...from which an OString can cheaply be instantiated.

The one downside is that OStringLiteral now needs to be a template abstracting
over the string length.  But any uses for which that is a problem (e.g., as the
element type of a containers that would no longer be homogeneous, or in the
signature of a function that shall not be turned into a template for one reason
or another) can be replaced with std::string_view, without loss of efficiency
compared to the original OStringLiteral, and without loss of expressivity (esp.
with the newly introduced OString(std::string_view) ctor).

The new OStringLiteral ctor code would probably not be very efficient if it were
ever executed at runtime, but it is intended to be only executed at compile
time.  Where available, C++20 "consteval" is used to statically ensure that.

The intended use of the new OStringLiteral is in all cases where an
object that shall itself not be an OString (e.g., because it shall be a
global static variable for which the OString ctor/dtor would be detrimental at
library load/unload) must be converted to an OString instance in at least one
place.  Other string literal abstractions could use std::string_view (or just
plain char const[N]), but interestingly OStringLiteral might be more efficient
than constexpr std::string_view even for such cases, as it should not need any
relocations at library load time.  For now, no existing uses of OUStringLiteral
have been changed to some other abstraction (unless technically necessary as
discussed above), and no additional places that would benefit from
OUStringLiteral have been changed to use it.

sal/qa/rtl/strings/test_ostring_concat.cxx documents some workarounds for GCC
bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96878> "Failed class template
argument deduction in unevaluated, parenthesized context".  Those places, as
well as uses of OStringLiteral in incodemaker/source/javamaker/javaoptions.cxx
and i18npool/source/breakiterator/breakiterator_unicode.cxx, which have been
replaced with OString::Concat (and which is arguably a better choice, anyway),
also caused failures with at least Clang 5.0.2 (but would not have caused
failures with at least recent Clang 12 trunk, so appear to be bugs in Clang that
have meanwhile been fixed).

This change also revealed a bug in at least recent Clang 12 trunk
CastExpr::getSubExprAsWritten (still to be reported to LLVM), triggered at least
in some calls from loplugin code (for which it can be fixed for now in the
existing compat::getSubStringAsWritten).

A similar commit for OUStringLiteral is planned, too.

Change-Id: Ib192f4ed4c44769512a16364cb55c25627bae6f4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101814
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-09-02 08:12:04 +02:00
Stephan Bergmann
33ecd0d5c4 Change OUStringLiteral from char[] to char16_t[]
This is a prerequisite for making conversion from OUStringLiteral to OUString
more efficient at least for C++20 (by replacing its internals with a constexpr-
generated sal_uString-compatible layout with a SAL_STRING_STATIC_FLAG refCount,
conditionally for C++20 for now).

For a configure-wise bare-bones build on Linux, size reported by `du -bs
instdir` grew by 118792 bytes from 1155636636 to 1155755428.

In most places just a u"..." string literal prefix had to be added.  In some
places

  char const a[] = "...";

variables have been changed to char16_t, and a few places required even further
changes to code (which prompted the addition of include/o3tl/string_view.hxx
helper function o3tl::equalsIgnoreAsciiCase and the additional
OUString::createFromAscii overload).

For all uses of macros expanding to string literals, the relevant uses have been
rewritten as

  u"" MACRO

instead of changing the macro definitions.  It should be possible to change at
least some of those macro definitions (and drop the u"" from their call sites)
in follow-up commits.

Change-Id: Iec4ef1a057d412d22443312d40c6a8a290dc6144
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101483
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-08-28 08:07:09 +02:00
Stephan Bergmann
a8ab80c58a Silence some clang-cl loplugin:stringstatic
For one, do not warn about global declarations in included files, as generally
not all uses of the variable are seen to decided whether it would be good to
replace.  That covers cases like

> In file included from dtrans/source/win32/dtobj/DataFmtTransl.cxx:26:
> dtrans/source/win32/dtobj/MimeAttrib.hxx(29,16): error: rather declare this using OUStringLiteral/OStringLiteral/char[] [loplugin:stringstatic]
> const OUString CHARSET_UTF16        ("utf-16");
> ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

For another, do not warn about variables whose pData member is used. That covers
cases like

> sal/osl/w32/procimpl.cxx(347,20): error: rather declare this using OUStringLiteral/OStringLiteral/char[] [loplugin:stringstatic]
>     const OUString ENV_COMSPEC ("COMSPEC");
>     ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~

Change-Id: I75c1048098b63164bdb583695951f73964cb24f8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101134
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-08-21 12:07:30 +02:00
Stephan Bergmann
3e37f3db69 Remove unused include
Change-Id: I019148e0823e68ccbb1cf60f6eac9e69b634515b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100973
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-08-19 11:08:21 +02:00
Noel Grandin
3457da6abe loplugin:stringstatic also look for local statics
Add some API to O*StringLiteral, to make it easier
to use in some places that were using O*String

Change-Id: I1fb93bd47ac2065c9220d509aad3f4320326d99e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100270
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2020-08-13 08:16:03 +02:00
Stephan Bergmann
8324dfb50b Adapt to --disable-assert-always-abort
Change-Id: Ib578c5d8c82ca763770d316384c6753534dbfee3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100141
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-08-05 10:25:26 +02:00
Stephan Bergmann
30ededbd00 Adapt compilerplugins/clang/test/makeshared.cxx to MSVC standard library
> error: 'error' diagnostics seen but not expected:
>   File compilerplugins/clang/test/makeshared.cxx Line 47: rather use make_shared than constructing from 'unique_ptr<int>' [loplugin:makeshared]
>   File compilerplugins/clang/test/makeshared.cxx Line 49: rather use make_shared than constructing from 'unique_ptr<int>' [loplugin:makeshared]
>   File compilerplugins/clang/test/makeshared.cxx Line 53: rather use make_shared than constructing from 'unique_ptr<int>' [loplugin:makeshared]

Change-Id: I5d2d1b129c9d0fee496eceb4e2cf14f5853ba00b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100074
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-08-04 14:24:47 +02:00
Stephan Bergmann
5a8edae67c Adapt compilerplugins/clang/test/getstr.cxx to latest MSVC standard library
...that now defines the wide-character-to-narrow-stream inserters as deleted
too, at least in C++20 mode.

Change-Id: I554f2530d5905e46343bf0d8bf12a6feb3d63075
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100073
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-08-04 14:24:10 +02:00
Stephan Bergmann
5d546de67b Adapt to Clang 12 trunk RecursiveASTVisitor change
<https://github.com/llvm/llvm-project/commit/
5689b38c6a4220cc5f6ba68a56486229b10071bf> "Removed a RecursiveASTVisitor feature
to visit operator kinds with different methods".

That change is incompatible in that before the change individual TraverseUnary*
and TraverseBin* functions were called, while now TraverseUnaryOperator and
TraverseBinaryOperator/TraverseCompoundAssignOperator are called for all the
different operators.  Fixed that with a few #if for the non-shared plugins, but
that doesn't work for the shared plugin.  So made the two affected plugins non-
shared for now and left a better fix as a TODO.

Change-Id: I5b87d329ae2c4c93bf605bb1ecc9641039f014a3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99000
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-07-19 23:05:57 +02:00
Thorsten Behrens
abb6c01519 replace usage of whitelist with allowlist
Background and motivation:
  https://tools.ietf.org/html/draft-knodel-terminology-02

[API CHANGE] officecfg::Office::Common::Misc::OpenCLWhiteList -> OpenCLAllowList

Change-Id: I65636b19b13e4af1e4851f70e78053f3443d6bb1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98181
Tested-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
2020-07-10 01:36:07 +02:00
Stephan Bergmann
631cec87e2 loplugin:externvar is covered by loplugin:external
...so drop the former.  But keep the relevant externvar tests by moving them
into compilerplugins/clang/test/external.cxx.  (Which revealed one difference
between the two plugins, regarding certain extern "C" variables in unnamed
namespaces, where Clang (and for that matter also e.g. GCC, it appears)
deliberately deviates from the Standard and considers them to have external
linkage.  Add clarifying comments that loplugin:external keeps considering these
as having internal linkage, following the Standard.)

Change-Id: I344fcd0135fdaf6bf08a4b396af2ed2299389a7d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97639
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-07-01 19:50:42 +02:00
Stephan Bergmann
311fe58df8 Improve loplugin:elidestringvar
...by addressing the follow-up TODO mentioned in the commit message of
7a3736f908 "New loplugin:elidestringvar"
(extending it not only to uses with a constant sal_Unicode, but also to uses
with OUStringLiteral).

(All necessary changes have been made in preceding "Upcoming improved
loplugin:elidestringvar" commits.)

Change-Id: Ib0000ef9c4a1dad52124dfd039dd936cf7e3ba3f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97226
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-06-26 17:31:53 +02:00
Stephan Bergmann
8296303dc5 typo in comment
Change-Id: I60bcfa3182ce67ab50195ae6e7436839afe62c87
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96028
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-06-11 08:21:11 +02:00
Noel Grandin
474a9171e7 loplugin:buriedassign in sw
limited this only fixing assignments inside "if" statements, since other
things are harder to change

Change-Id: If3188a3e3d5fcd94123211c97fee097ece5e2797
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95990
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2020-06-10 20:43:38 +02:00
Stephan Bergmann
2a82ea5c04 Adapt to new Clang trunk -Wuninitialized-const-reference
> error: 'error' diagnostics seen but not expected:
>   File compilerplugins/clang/test/unusedfields.cxx Line 143: variable 'x' is uninitialized when passed as a const reference argument here

and

> error: 'error' diagnostics seen but not expected:
>   File compilerplugins/clang/test/writeonlyvars.cxx Line 93: variable 'm_bar10' is uninitialized when passed as a const reference argument here

since <https://github.com/llvm/llvm-project/commit/
170b6869b563dd3393d99f3e03d389b9058d5f24> " [Clang] Add a new warning to warn
when passing uninitialized variables as const reference parameters to a
function"

Change-Id: I27136e387f7a14fd24a3639187b668d6ed283070
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95994
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-06-10 15:42:19 +02:00