2019-09-27 21:41:42 +02:00
/* -*- 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/.
*/
2019-10-13 08:47:47 +02:00
# include <rtl/strbuf.hxx>
2019-09-27 21:41:42 +02:00
# include <rtl/string.hxx>
2019-10-13 08:47:47 +02:00
# include <rtl/ustrbuf.hxx>
# include <rtl/ustring.hxx>
2021-06-03 13:44:39 +02:00
# pragma clang diagnostic ignored "-Wunknown-warning-option" // for Clang < 13
# pragma clang diagnostic ignored "-Wunused-but-set-parameter"
# pragma clang diagnostic ignored "-Wunused-but-set-variable"
2019-10-13 08:47:47 +02:00
// ---------------------------------------------------------------
// += tests
2019-09-27 21:41:42 +02:00
namespace test1
{
static const char XXX1 [ ] = " xxx " ;
Turn OUStringLiteral into a consteval'ed, static-refcound rtl_uString
...from which an OUString can cheaply be instantiated. This is the OUString
equivalent of 4b9e440c51be3e40326bc90c33ae69885bfb51e4 "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-08 09:48:17 +02:00
static constexpr char16_t XXX1u [ ] = u " xxx " ;
2019-09-27 21:41:42 +02:00
static const char XXX2 [ ] = " xxx " ;
2019-10-15 20:24:10 +02:00
void f1 ( OUString s1 , int i , OString o )
2019-09-27 21:41:42 +02:00
{
OUString s2 = s1 ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-09-27 21:41:42 +02:00
s2 + = " xxx " ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-09-27 21:41:42 +02:00
s2 + = " xxx " ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-09-27 21:41:42 +02:00
s2 + = s1 ;
s2 = s1 + " xxx " ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-09-27 21:41:42 +02:00
s2 + = s1 ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-09-27 21:41:42 +02:00
s2 + = OUString : : number ( i ) ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-09-27 21:41:42 +02:00
s2 + = XXX1 ;
Adapt to Clang 15 trunk increase in ElabortatedType sugar
...<https://github.com/llvm/llvm-project/commit/bdc6974f92304f4ed542241b9b89ba58ba6b20aa>
"[clang] Implement ElaboratedType sugaring for types written bare".
For one, it caused diagnostics to now emit 'OString' instead of 'rtl::OUString'
etc., which required adapting a number of tests.
For another, some tests started to fail because the relevant plugins didn't
expect ElaboratedType sugar in places where it now occurs:
> error: 'error' diagnostics expected but not seen:
> File compilerplugins/clang/test/redundantcast.cxx Line 297: redundant cstyle cast from 'Enum1' to 'Enum1' [loplugin:redundantcast]
> File compilerplugins/clang/test/redundantcast.cxx Line 308: redundant cstyle cast from 'Enum1' to 'Enum1' [loplugin:redundantcast]
> error: 'error' diagnostics expected but not seen:
> File compilerplugins/clang/test/referencecasting.cxx Line 25 (directive at compilerplugins/clang/test/referencecasting.cxx:24): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 37 (directive at compilerplugins/clang/test/referencecasting.cxx:36): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 48 (directive at compilerplugins/clang/test/referencecasting.cxx:47): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 100 (directive at compilerplugins/clang/test/referencecasting.cxx:99): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 120 (directive at compilerplugins/clang/test/referencecasting.cxx:119): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 188 (directive at compilerplugins/clang/test/referencecasting.cxx:187): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 200 (directive at compilerplugins/clang/test/referencecasting.cxx:199): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 206 (directive at compilerplugins/clang/test/referencecasting.cxx:205): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> error: 'error' diagnostics seen but not expected:
> File compilerplugins/clang/test/typedefparam.cxx Line 42: function param 1 at definition site does not match function param at declaration site, 'FooT *' (aka 'test2::Foo *') vs 'struct Foo *' [loplugin:typedefparam]
> File compilerplugins/clang/test/typedefparam.cxx Line 55: function param 1 at definition site does not match function param at declaration site, 'FooT *' (aka 'test3::Foo *') vs 'Foo *' [loplugin:typedefparam]
> error: 'note' diagnostics seen but not expected:
> File compilerplugins/clang/test/typedefparam.cxx Line 40: declaration site here [loplugin:typedefparam]
> File compilerplugins/clang/test/typedefparam.cxx Line 53: declaration site here [loplugin:typedefparam]
Hopefully, there are not too many places in our plugins left that similarly
don't expect ElaboratedType sugar in certain places, but which are not covered
by tests. At least, a full build didn't turn up any further false positives,
but there may of course be false negatives now that would go undetected.
Change-Id: I9bfb1cfb57df5f6e228b512c19c664d48285b675
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137049
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2022-07-14 10:13:49 +02:00
// expected-error-re@+2 {{rather use O[U]String::Concat than constructing '{{(rtl::)?}}OUStringLiteral<4>'{{( \(aka 'rtl::OUStringLiteral<4>'\))?}} from 'const char16_t{{ ?}}[4]' on LHS of + (where RHS is of type 'const char{{ ?}}[4]') [loplugin:stringadd]}}
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2020-08-27 11:40:59 +02:00
s2 + = OUStringLiteral ( XXX1u ) + XXX2 ;
2019-09-27 21:41:42 +02:00
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-09-27 21:41:42 +02:00
s2 + = OStringToOUString ( o , RTL_TEXTENCODING_UTF8 ) ;
}
2019-10-15 20:24:10 +02:00
void f2 ( OString s1 , int i , OUString u )
2019-09-27 21:41:42 +02:00
{
OString s2 = s1 ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-09-27 21:41:42 +02:00
s2 + = " xxx " ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-09-27 21:41:42 +02:00
s2 + = " xxx " ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-09-27 21:41:42 +02:00
s2 + = s1 ;
s2 = s1 + " xxx " ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-09-27 21:41:42 +02:00
s2 + = s1 ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-09-27 21:41:42 +02:00
s2 + = OString : : number ( i ) ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-09-27 21:41:42 +02:00
s2 + = OUStringToOString ( u , RTL_TEXTENCODING_ASCII_US ) ;
}
2019-10-15 20:24:10 +02:00
void f3 ( OUString aStr , int nFirstContent )
{
OUString aFirstStr = aStr . copy ( 0 , nFirstContent ) ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-10-15 20:24:10 +02:00
aFirstStr + = " ... " ;
}
2019-10-30 20:27:26 +01:00
OUString side_effect ( ) ;
2019-10-30 11:26:16 +01:00
void f4 ( int i )
{
2019-10-30 20:27:26 +01:00
OUString s1 ;
OUString s2 ( " xxx " ) ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-10-30 20:27:26 +01:00
s2 + = " xxx " ;
2019-10-30 11:26:16 +01:00
+ + i ;
// any other kind of statement breaks the chain (at least for now)
2019-10-30 20:27:26 +01:00
s2 + = " xxx " ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-10-30 20:27:26 +01:00
s2 + = side_effect ( ) ;
s1 + = " yyy " ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-10-30 20:27:26 +01:00
s1 + = " yyy " ;
2019-10-30 11:26:16 +01:00
}
2019-09-27 21:41:42 +02:00
}
namespace test2
{
void f ( OUString s3 )
{
s3 + = " xxx " ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-09-27 21:41:42 +02:00
s3 + = " xxx " ;
}
void g ( OString s3 )
{
s3 + = " xxx " ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-09-27 21:41:42 +02:00
s3 + = " xxx " ;
}
}
namespace test3
{
struct Bar
{
OUString m_field ;
} ;
void f ( Bar b1 , Bar & b2 , Bar * b3 )
{
OUString s3 = " xxx " ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-09-27 21:41:42 +02:00
s3 + = b1 . m_field ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-09-27 21:41:42 +02:00
s3 + = b2 . m_field ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-09-27 21:41:42 +02:00
s3 + = b3 - > m_field ;
}
2019-10-28 10:35:49 +02:00
OUString side_effect ( ) ;
2019-10-30 20:27:26 +01:00
void f2 ( OUString s )
2019-10-28 10:35:49 +02:00
{
OUString sRet = " xxx " ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-10-28 10:35:49 +02:00
sRet + = side_effect ( ) ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-10-30 20:27:26 +01:00
sRet + = " xxx " ;
sRet + = side_effect ( ) ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-10-30 20:27:26 +01:00
sRet + = " xxx " ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-10-30 20:27:26 +01:00
sRet + = " xxx " ;
sRet + = s ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-10-30 20:27:26 +01:00
sRet + = " xxx " ;
2019-10-28 10:35:49 +02:00
}
2019-09-27 21:41:42 +02:00
}
// no warning expected
namespace test4
{
2019-10-30 20:27:26 +01:00
OUString side_effect ( ) ;
2019-09-27 21:41:42 +02:00
void f ( )
{
OUString sRet = " xxx " ;
# if OSL_DEBUG_LEVEL > 0
sRet + = " ; " ;
# endif
2019-10-30 20:27:26 +01:00
sRet + = " " ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-10-30 20:27:26 +01:00
sRet + = side_effect ( ) ;
2019-09-27 21:41:42 +02:00
}
}
// no warning expected
namespace test5
{
OUString side_effect ( ) ;
void f ( )
{
OUString sRet = side_effect ( ) ;
2019-10-28 10:35:49 +02:00
sRet + = side_effect ( ) ;
2019-09-27 21:41:42 +02:00
}
}
namespace test6
{
void f ( OUString sComma , OUString maExtension , int mnDocumentIconID )
{
OUString sValue ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-09-27 21:41:42 +02:00
sValue + = sComma + sComma + maExtension + sComma ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-09-27 21:41:42 +02:00
sValue + = OUString : : number ( mnDocumentIconID ) + sComma ;
}
struct Foo
{
OUString sFormula1 ;
} ;
void g ( int x , const Foo & aValidation )
{
OUString sCondition ;
switch ( x )
{
case 1 :
sCondition + = " cell-content-is-in-list( " ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2019-09-27 21:41:42 +02:00
sCondition + = aValidation . sFormula1 + " ) " ;
}
}
}
2019-10-13 08:47:47 +02:00
// ---------------------------------------------------------------
// detecting OUString temporary construction in +
namespace test9
{
OUString getByValue ( ) ;
const OUString & getByRef ( ) ;
void f1 ( OUString s , OUString t , int i , const char * pChar )
{
// no warning expected
t = t + " xxx " ;
Adapt to Clang 15 trunk increase in ElabortatedType sugar
...<https://github.com/llvm/llvm-project/commit/bdc6974f92304f4ed542241b9b89ba58ba6b20aa>
"[clang] Implement ElaboratedType sugaring for types written bare".
For one, it caused diagnostics to now emit 'OString' instead of 'rtl::OUString'
etc., which required adapting a number of tests.
For another, some tests started to fail because the relevant plugins didn't
expect ElaboratedType sugar in places where it now occurs:
> error: 'error' diagnostics expected but not seen:
> File compilerplugins/clang/test/redundantcast.cxx Line 297: redundant cstyle cast from 'Enum1' to 'Enum1' [loplugin:redundantcast]
> File compilerplugins/clang/test/redundantcast.cxx Line 308: redundant cstyle cast from 'Enum1' to 'Enum1' [loplugin:redundantcast]
> error: 'error' diagnostics expected but not seen:
> File compilerplugins/clang/test/referencecasting.cxx Line 25 (directive at compilerplugins/clang/test/referencecasting.cxx:24): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 37 (directive at compilerplugins/clang/test/referencecasting.cxx:36): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 48 (directive at compilerplugins/clang/test/referencecasting.cxx:47): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 100 (directive at compilerplugins/clang/test/referencecasting.cxx:99): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 120 (directive at compilerplugins/clang/test/referencecasting.cxx:119): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 188 (directive at compilerplugins/clang/test/referencecasting.cxx:187): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 200 (directive at compilerplugins/clang/test/referencecasting.cxx:199): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 206 (directive at compilerplugins/clang/test/referencecasting.cxx:205): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> error: 'error' diagnostics seen but not expected:
> File compilerplugins/clang/test/typedefparam.cxx Line 42: function param 1 at definition site does not match function param at declaration site, 'FooT *' (aka 'test2::Foo *') vs 'struct Foo *' [loplugin:typedefparam]
> File compilerplugins/clang/test/typedefparam.cxx Line 55: function param 1 at definition site does not match function param at declaration site, 'FooT *' (aka 'test3::Foo *') vs 'Foo *' [loplugin:typedefparam]
> error: 'note' diagnostics seen but not expected:
> File compilerplugins/clang/test/typedefparam.cxx Line 40: declaration site here [loplugin:typedefparam]
> File compilerplugins/clang/test/typedefparam.cxx Line 53: declaration site here [loplugin:typedefparam]
Hopefully, there are not too many places in our plugins left that similarly
don't expect ElaboratedType sugar in certain places, but which are not covered
by tests. At least, a full build didn't turn up any further false positives,
but there may of course be false negatives now that would go undetected.
Change-Id: I9bfb1cfb57df5f6e228b512c19c664d48285b675
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137049
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2022-07-14 10:13:49 +02:00
// expected-error-re@+1 {{rather use O[U]String::Concat than constructing '{{(rtl::)?}}OUString' from 'const char{{ ?}}[4]' on RHS of + (where LHS is of type '{{(rtl::)?}}OUString') [loplugin:stringadd]}}
2019-10-13 08:47:47 +02:00
s = s + OUString ( " xxx " ) ;
Adapt to Clang 15 trunk increase in ElabortatedType sugar
...<https://github.com/llvm/llvm-project/commit/bdc6974f92304f4ed542241b9b89ba58ba6b20aa>
"[clang] Implement ElaboratedType sugaring for types written bare".
For one, it caused diagnostics to now emit 'OString' instead of 'rtl::OUString'
etc., which required adapting a number of tests.
For another, some tests started to fail because the relevant plugins didn't
expect ElaboratedType sugar in places where it now occurs:
> error: 'error' diagnostics expected but not seen:
> File compilerplugins/clang/test/redundantcast.cxx Line 297: redundant cstyle cast from 'Enum1' to 'Enum1' [loplugin:redundantcast]
> File compilerplugins/clang/test/redundantcast.cxx Line 308: redundant cstyle cast from 'Enum1' to 'Enum1' [loplugin:redundantcast]
> error: 'error' diagnostics expected but not seen:
> File compilerplugins/clang/test/referencecasting.cxx Line 25 (directive at compilerplugins/clang/test/referencecasting.cxx:24): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 37 (directive at compilerplugins/clang/test/referencecasting.cxx:36): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 48 (directive at compilerplugins/clang/test/referencecasting.cxx:47): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 100 (directive at compilerplugins/clang/test/referencecasting.cxx:99): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 120 (directive at compilerplugins/clang/test/referencecasting.cxx:119): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 188 (directive at compilerplugins/clang/test/referencecasting.cxx:187): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 200 (directive at compilerplugins/clang/test/referencecasting.cxx:199): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 206 (directive at compilerplugins/clang/test/referencecasting.cxx:205): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> error: 'error' diagnostics seen but not expected:
> File compilerplugins/clang/test/typedefparam.cxx Line 42: function param 1 at definition site does not match function param at declaration site, 'FooT *' (aka 'test2::Foo *') vs 'struct Foo *' [loplugin:typedefparam]
> File compilerplugins/clang/test/typedefparam.cxx Line 55: function param 1 at definition site does not match function param at declaration site, 'FooT *' (aka 'test3::Foo *') vs 'Foo *' [loplugin:typedefparam]
> error: 'note' diagnostics seen but not expected:
> File compilerplugins/clang/test/typedefparam.cxx Line 40: declaration site here [loplugin:typedefparam]
> File compilerplugins/clang/test/typedefparam.cxx Line 53: declaration site here [loplugin:typedefparam]
Hopefully, there are not too many places in our plugins left that similarly
don't expect ElaboratedType sugar in certain places, but which are not covered
by tests. At least, a full build didn't turn up any further false positives,
but there may of course be false negatives now that would go undetected.
Change-Id: I9bfb1cfb57df5f6e228b512c19c664d48285b675
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137049
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2022-07-14 10:13:49 +02:00
// expected-error-re@+1 {{rather use O[U]String::Concat than constructing '{{(rtl::)?}}OUString' from 'const {{(rtl::)?}}OUString' on RHS of + (where LHS is of type '{{(rtl::)?}}OUString') [loplugin:stringadd]}}
2019-10-13 08:47:47 +02:00
s = s + OUString ( getByRef ( ) ) ;
// no warning expected
OUString a ;
a = a + getByValue ( ) ;
// no warning expected
OUString b ;
b = b + ( i = = 1 ? " aaa " : " bbb " ) ;
// no warning expected
OUString c ;
c = c + OUString ( pChar , strlen ( pChar ) , RTL_TEXTENCODING_UTF8 ) ;
2021-04-23 16:07:32 +02:00
OUStringBuffer buf ;
// expected-error@+1 {{chained append, rather use single append call and + operator [loplugin:stringadd]}}
buf . append ( " " ) . append ( b ) ;
2019-10-13 08:47:47 +02:00
}
void f2 ( char ch )
{
OString s ;
Adapt to Clang 15 trunk increase in ElabortatedType sugar
...<https://github.com/llvm/llvm-project/commit/bdc6974f92304f4ed542241b9b89ba58ba6b20aa>
"[clang] Implement ElaboratedType sugaring for types written bare".
For one, it caused diagnostics to now emit 'OString' instead of 'rtl::OUString'
etc., which required adapting a number of tests.
For another, some tests started to fail because the relevant plugins didn't
expect ElaboratedType sugar in places where it now occurs:
> error: 'error' diagnostics expected but not seen:
> File compilerplugins/clang/test/redundantcast.cxx Line 297: redundant cstyle cast from 'Enum1' to 'Enum1' [loplugin:redundantcast]
> File compilerplugins/clang/test/redundantcast.cxx Line 308: redundant cstyle cast from 'Enum1' to 'Enum1' [loplugin:redundantcast]
> error: 'error' diagnostics expected but not seen:
> File compilerplugins/clang/test/referencecasting.cxx Line 25 (directive at compilerplugins/clang/test/referencecasting.cxx:24): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 37 (directive at compilerplugins/clang/test/referencecasting.cxx:36): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 48 (directive at compilerplugins/clang/test/referencecasting.cxx:47): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 100 (directive at compilerplugins/clang/test/referencecasting.cxx:99): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 120 (directive at compilerplugins/clang/test/referencecasting.cxx:119): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 188 (directive at compilerplugins/clang/test/referencecasting.cxx:187): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 200 (directive at compilerplugins/clang/test/referencecasting.cxx:199): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 206 (directive at compilerplugins/clang/test/referencecasting.cxx:205): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> error: 'error' diagnostics seen but not expected:
> File compilerplugins/clang/test/typedefparam.cxx Line 42: function param 1 at definition site does not match function param at declaration site, 'FooT *' (aka 'test2::Foo *') vs 'struct Foo *' [loplugin:typedefparam]
> File compilerplugins/clang/test/typedefparam.cxx Line 55: function param 1 at definition site does not match function param at declaration site, 'FooT *' (aka 'test3::Foo *') vs 'Foo *' [loplugin:typedefparam]
> error: 'note' diagnostics seen but not expected:
> File compilerplugins/clang/test/typedefparam.cxx Line 40: declaration site here [loplugin:typedefparam]
> File compilerplugins/clang/test/typedefparam.cxx Line 53: declaration site here [loplugin:typedefparam]
Hopefully, there are not too many places in our plugins left that similarly
don't expect ElaboratedType sugar in certain places, but which are not covered
by tests. At least, a full build didn't turn up any further false positives,
but there may of course be false negatives now that would go undetected.
Change-Id: I9bfb1cfb57df5f6e228b512c19c664d48285b675
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137049
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2022-07-14 10:13:49 +02:00
// expected-error-re@+1 {{rather use O[U]String::Concat than constructing '{{(rtl::)?}}OString' from 'const char{{ ?}}[4]' on RHS of + (where LHS is of type '{{(rtl::)?}}OString') [loplugin:stringadd]}}
2019-10-13 08:47:47 +02:00
s = s + OString ( " xxx " ) ;
Adapt to Clang 15 trunk increase in ElabortatedType sugar
...<https://github.com/llvm/llvm-project/commit/bdc6974f92304f4ed542241b9b89ba58ba6b20aa>
"[clang] Implement ElaboratedType sugaring for types written bare".
For one, it caused diagnostics to now emit 'OString' instead of 'rtl::OUString'
etc., which required adapting a number of tests.
For another, some tests started to fail because the relevant plugins didn't
expect ElaboratedType sugar in places where it now occurs:
> error: 'error' diagnostics expected but not seen:
> File compilerplugins/clang/test/redundantcast.cxx Line 297: redundant cstyle cast from 'Enum1' to 'Enum1' [loplugin:redundantcast]
> File compilerplugins/clang/test/redundantcast.cxx Line 308: redundant cstyle cast from 'Enum1' to 'Enum1' [loplugin:redundantcast]
> error: 'error' diagnostics expected but not seen:
> File compilerplugins/clang/test/referencecasting.cxx Line 25 (directive at compilerplugins/clang/test/referencecasting.cxx:24): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 37 (directive at compilerplugins/clang/test/referencecasting.cxx:36): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 48 (directive at compilerplugins/clang/test/referencecasting.cxx:47): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 100 (directive at compilerplugins/clang/test/referencecasting.cxx:99): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 120 (directive at compilerplugins/clang/test/referencecasting.cxx:119): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 188 (directive at compilerplugins/clang/test/referencecasting.cxx:187): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 200 (directive at compilerplugins/clang/test/referencecasting.cxx:199): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> File compilerplugins/clang/test/referencecasting.cxx Line 206 (directive at compilerplugins/clang/test/referencecasting.cxx:205): the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]
> error: 'error' diagnostics seen but not expected:
> File compilerplugins/clang/test/typedefparam.cxx Line 42: function param 1 at definition site does not match function param at declaration site, 'FooT *' (aka 'test2::Foo *') vs 'struct Foo *' [loplugin:typedefparam]
> File compilerplugins/clang/test/typedefparam.cxx Line 55: function param 1 at definition site does not match function param at declaration site, 'FooT *' (aka 'test3::Foo *') vs 'Foo *' [loplugin:typedefparam]
> error: 'note' diagnostics seen but not expected:
> File compilerplugins/clang/test/typedefparam.cxx Line 40: declaration site here [loplugin:typedefparam]
> File compilerplugins/clang/test/typedefparam.cxx Line 53: declaration site here [loplugin:typedefparam]
Hopefully, there are not too many places in our plugins left that similarly
don't expect ElaboratedType sugar in certain places, but which are not covered
by tests. At least, a full build didn't turn up any further false positives,
but there may of course be false negatives now that would go undetected.
Change-Id: I9bfb1cfb57df5f6e228b512c19c664d48285b675
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137049
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2022-07-14 10:13:49 +02:00
// expected-error-re@+1 {{rather use O[U]String::Concat than constructing '{{(rtl::)?}}OString' from 'char' on RHS of + (where LHS is of type '{{(rtl::)?}}OString') [loplugin:stringadd]}}
2019-10-13 08:47:47 +02:00
s = s + OString ( ch ) ;
}
}
2021-07-09 13:04:19 +02:00
namespace test10
{
struct C
{
OString constStringFunction ( int ) const ;
OString nonConstStringFunction ( ) ;
int constIntFunction ( ) const ;
int nonConstIntFunction ( ) ;
} ;
C getC ( ) ;
void f1 ( C c )
{
OString s ;
2023-03-14 08:50:39 +02:00
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
2021-07-09 13:04:19 +02:00
s + = c . constStringFunction ( c . constIntFunction ( ) ) ;
s + = c . constStringFunction ( c . nonConstIntFunction ( ) ) ;
s + = c . nonConstStringFunction ( ) ;
s + = getC ( ) . constStringFunction ( c . constIntFunction ( ) ) ;
}
}
2023-03-14 08:50:39 +02:00
namespace test11
{
void f1 ( )
{
OUStringBuffer aFirstStr1 ( " aaa " ) ;
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
aFirstStr1 . append ( " ... " ) ;
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
aFirstStr1 . append ( " ... " ) ;
}
}
namespace test12
{
void f1 ( int j )
{
OUStringBuffer aFirstStr1 ( 12 ) ;
// no warning expected
aFirstStr1 . append ( " ... " ) ;
// expected-error@+1 {{simplify by merging with the preceding assign/append [loplugin:stringadd]}}
aFirstStr1 . append ( " ... " ) ;
// no warning expected
aFirstStr1 . append ( ( ( j + 1 ) % 15 ) ? " " : " \n " ) ;
}
}
namespace test13
{
void f1 ( )
{
OUStringBuffer aFirstStr1 ( 12 ) ;
// no warning expected
aFirstStr1 . append ( " ... " ) ;
// because we have a comment between them
aFirstStr1 . append ( " ... " ) ;
}
}
2023-04-17 09:09:14 +02:00
namespace test14
{
void f1 ( )
{
OUStringBuffer b ( 16 ) ;
b . append ( " ... " ) ;
}
void f2 ( long long n )
{
OUStringBuffer b ( n ) ;
b . append ( " ... " ) ;
}
}
2019-09-27 21:41:42 +02:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */