Files
libreoffice/compilerplugins/clang/test/getstr.cxx
Stephan Bergmann 77d083f2cb New loplugin:getstr
...to find matches of

  ... << s.getStr()

(for the rtl string classes) that can be written as just

  ... << s

Some notes:

* The OUStringToOString(..., RTL_TEXTENCODING_UTF8) is left explicit in
  desktop/source/app/crashreport.cxx (even though that would also be done
  internally by the "<< OUString" operator) to clarify that these values are
  written out as UTF-8 (and not as what that operator << happens to use, which
  just also happens to be UTF-8).

* OUSTRING_TO_CSTR (include/oox/helper/helper.hxx) is no longer used now.

* Just don't bother to use osl_getThreadTextEncoding() in the SAL_WARN in
  lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx.

* The toUtf8() in the SAL_DEBUG in pyuno/source/module/pyuno_module.cxx can just
  go, too.

Change-Id: I4602f0379ef816bff310f1e51b57c56b7e3f0136
Reviewed-on: https://gerrit.libreoffice.org/80762
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-10-14 15:48:38 +02:00

42 lines
2.6 KiB
C++

/* -*- 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 <ostream>
#include <rtl/strbuf.hxx>
#include <rtl/string.hxx>
#include <rtl/ustrbuf.hxx>
#include <rtl/ustring.hxx>
#include <sal/log.hxx>
using S = OString;
void f(std::ostream& st, OString const& s1, OStringBuffer const& s2, OUString const& s3,
OUStringBuffer const& s4, S const& s5, OString* p1, OStringBuffer* p2, OUString* p3,
OUStringBuffer* p4, S* p5, char const* (OString::*pf)() const)
{
st << s1.getStr() // expected-error {{directly use object of type 'rtl::OString' in a call of 'operator <<', instead of calling 'getStr' first [loplugin:getstr]}}
<< s2.getStr()
<< s3.getStr() // expected-error {{suspicious use of 'getStr' on an object of type 'rtl::OUString'; the result is implicitly cast to a void pointer in a call of 'operator <<' [loplugin:getstr]}}
<< s4.getStr() // expected-error {{suspicious use of 'getStr' on an object of type 'rtl::OUStringBuffer'; the result is implicitly cast to a void pointer in a call of 'operator <<' [loplugin:getstr]}}
<< s5.getStr() // expected-error {{directly use object of type 'S' (aka 'rtl::OString') in a call of 'operator <<', instead of calling 'getStr' first [loplugin:getstr]}}
<< p1->getStr() // expected-error {{directly use object of type 'rtl::OString' in a call of 'operator <<', instead of calling 'getStr' first [loplugin:getstr]}}
<< p2->getStr()
<< p3->getStr() // expected-error {{suspicious use of 'getStr' on an object of type 'rtl::OUString'; the result is implicitly cast to a void pointer in a call of 'operator <<' [loplugin:getstr]}}
<< p4->getStr() // expected-error {{suspicious use of 'getStr' on an object of type 'rtl::OUStringBuffer'; the result is implicitly cast to a void pointer in a call of 'operator <<' [loplugin:getstr]}}
<< p5->getStr() // expected-error {{directly use object of type 'rtl::OString' in a call of 'operator <<', instead of calling 'getStr' first [loplugin:getstr]}}
<< (s1.*pf)();
SAL_INFO( // expected-error 1+ {{directly use object of type 'rtl::OString' in a call of 'operator <<', instead of calling 'getStr' first [loplugin:getstr]}}
"test", s1.getStr());
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */