2018-06-22 11:56:37 +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/.
*/
# include <memory>
# include <rtl/ref.hxx>
2019-06-21 12:14:08 +02:00
# include <tools/gen.hxx>
2018-06-22 11:56:37 +02:00
2019-04-12 18:39:22 +02:00
namespace test1
{
2018-06-22 11:56:37 +02:00
struct Foo
{
void acquire ( ) ;
void release ( ) ;
} ;
2018-09-13 13:31:41 +02:00
class Foo1
2018-06-22 11:56:37 +02:00
{
std : : unique_ptr < int > m_pbar1 ;
rtl : : Reference < Foo > m_pbar2 ;
2018-09-13 13:31:41 +02:00
Foo1 ( )
2018-06-22 11:56:37 +02:00
: m_pbar1 ( nullptr )
2018-09-13 21:21:20 +02:00
// expected-error@-1 {{no need to explicitly init an instance of 'std::unique_ptr<int>' with nullptr, just use default constructor [loplugin:simplifyconstruct]}}
2018-06-22 11:56:37 +02:00
, m_pbar2 ( nullptr )
2018-09-13 21:21:20 +02:00
// expected-error@-1 {{no need to explicitly init an instance of 'rtl::Reference<Foo>' with nullptr, just use default constructor [loplugin:simplifyconstruct]}}
2018-06-22 11:56:37 +02:00
{
}
} ;
2019-04-12 18:39:22 +02:00
}
2018-09-13 13:31:41 +02:00
// no warning expected when using std::unique_ptr constructor with a custom deleter
2019-04-12 18:39:22 +02:00
namespace test2
{
2018-09-13 13:31:41 +02:00
struct ITypeLib
{
} ;
struct IUnknown
{
void Release ( ) ;
} ;
void func2 ( )
{
std : : unique_ptr < IUnknown , void ( * ) ( IUnknown * p ) > aITypeLibGuard ( nullptr , [ ] ( IUnknown * p ) {
if ( p )
p - > Release ( ) ;
} ) ;
}
2019-04-12 18:39:22 +02:00
}
namespace test3
{
struct Foo
{
void acquire ( ) ;
void release ( ) ;
} ;
void f ( Foo * f )
{
// expected-error@+1 {{simplify [loplugin:simplifyconstruct]}}
rtl : : Reference < Foo > x = rtl : : Reference ( f ) ;
}
}
// no warning expected
namespace test4
{
struct Foo
{
void acquire ( ) ;
void release ( ) ;
} ;
void f ( Foo * f ) { auto x = rtl : : Reference ( f ) ; }
}
2018-09-13 13:31:41 +02:00
2019-06-21 12:14:08 +02:00
namespace test5
{
void f ( )
{
// expected-error@+1 {{simplify [loplugin:simplifyconstruct]}}
tools : : Rectangle x = tools : : Rectangle ( 10 , 10 , 10 , 10 ) ;
( void ) x ;
}
}
2018-06-22 11:56:37 +02:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */