2017-11-22 09:33:32 +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-02-14 13:01:42 +02:00
# include <rtl/ustring.hxx>
2019-10-22 12:18:34 +02:00
// expected-note@rtl/ustring.hxx:* 2 {{the presumed corresponding negated operator for 'rtl::OUString' and 'rtl::OUString' is declared here [loplugin:simplifybool]}}
2019-02-26 12:07:24 +02:00
# include <rtl/string.hxx>
2019-10-22 12:18:34 +02:00
// expected-note@rtl/string.hxx:* {{the presumed corresponding negated operator for 'rtl::OString' and 'rtl::OString' is declared here [loplugin:simplifybool]}}
2019-02-26 12:07:24 +02:00
# include <basegfx/vector/b3dvector.hxx>
2019-10-22 12:18:34 +02:00
// expected-note@basegfx/tuple/b3dtuple.hxx:* {{the presumed corresponding negated operator for 'basegfx::B3DVector' and 'basegfx::B3DVector' is declared here [loplugin:simplifybool]}}
2019-02-26 12:07:24 +02:00
# include <map>
2019-02-14 13:01:42 +02:00
2019-02-15 12:56:52 +02:00
namespace group1
{
2017-11-22 09:33:32 +02:00
void f1 ( int a , int b )
{
if ( ! ( a < b ) )
{ // expected-error@-1 {{logical negation of comparison operator, can be simplified by inverting operator [loplugin:simplifybool]}}
a = b ;
}
} ;
2017-11-23 10:39:41 +02:00
void f2 ( float a , float b )
{
// no warning expected
if ( ! ( a < b ) )
{
a = b ;
}
} ;
2019-02-15 12:56:52 +02:00
} ;
2017-11-23 10:39:41 +02:00
// Consistently either warn about all or none of the below occurrences of "!!":
2019-02-15 12:56:52 +02:00
namespace group2
{
2017-11-22 13:13:09 +01:00
enum E1
{
E1_1 = 1
} ;
enum E2
{
E2_1 = 1
} ;
E2 operator & ( E2 e1 , E2 e2 ) ;
bool operator ! ( E2 e ) ;
enum class E3
{
E1 = 1
} ;
struct W
{
operator bool ( ) ;
} ;
W operator & ( E3 e1 , E3 e2 ) ;
bool f0 ( int n ) { return ! ! ( n & 1 ) ; }
bool f1 ( E1 e ) { return ! ! ( e & E1_1 ) ; }
bool f2 ( E2 e ) { return ! ! ( e & E2_1 ) ; }
bool f3 ( E3 e ) { return ! ! ( e & E3 : : E1 ) ; }
2019-02-15 12:56:52 +02:00
} ;
2017-11-22 13:13:09 +01:00
2019-02-14 13:01:42 +02:00
// record types
2019-02-15 12:56:52 +02:00
namespace group3
{
2019-02-14 13:01:42 +02:00
struct Record1
{
bool operator = = ( const Record1 & ) const ;
} ;
struct Record2
{
bool operator = = ( const Record2 & ) const ;
bool operator ! = ( const Record2 & ) const ;
2019-10-22 12:18:34 +02:00
// expected-note@-1 {{the presumed corresponding negated operator for 'group3::Record2' and 'group3::Record2' is declared here [loplugin:simplifybool]}}
2019-02-14 13:01:42 +02:00
} ;
struct Record3
{
} ;
bool operator = = ( const Record3 & , const Record3 & ) ;
bool operator ! = ( const Record3 & , const Record3 & ) ;
2019-10-22 12:18:34 +02:00
// expected-note@-1 {{the presumed corresponding negated operator for 'group3::Record3' and 'group3::Record3' is declared here [loplugin:simplifybool]}}
2019-02-14 13:01:42 +02:00
void testRecord ( )
{
Record1 a1 ;
Record1 a2 ;
// no warning expected, because a negated operator does not exist
bool v = ! ( a1 = = a2 ) ;
Record2 b1 ;
Record2 b2 ;
v = ! ( b1 = = b2 ) ;
// expected-error@-1 {{logical negation of comparison operator, can be simplified by inverting operator [loplugin:simplifybool]}}
Record3 c1 ;
Record3 c2 ;
v = ! ( c1 = = c2 ) ;
// expected-error@-1 {{logical negation of comparison operator, can be simplified by inverting operator [loplugin:simplifybool]}}
OUString d1 ;
OUString d2 ;
v = ! ( d1 = = d2 ) ;
// expected-error@-1 {{logical negation of comparison operator, can be simplified by inverting operator [loplugin:simplifybool]}}
2019-02-26 12:07:24 +02:00
OString e1 ;
OString e2 ;
v = ! ( e1 = = e2 ) ;
// expected-error@-1 {{logical negation of comparison operator, can be simplified by inverting operator [loplugin:simplifybool]}}
// the operator != is in a base-class, and the param is a base-type
basegfx : : B3DVector f1 ;
basegfx : : B3DVector f2 ;
v = ! ( f1 = = f2 ) ;
// expected-error@-1 {{logical negation of comparison operator, can be simplified by inverting operator [loplugin:simplifybool]}}
2019-02-14 13:01:42 +02:00
}
struct Record4
{
bool operator = = ( Record4 const & ) const ;
bool operator ! = ( Record4 const & other ) const
{
// no warning expected
bool v = ! operator = = ( other ) ;
v = ! ( * this = = other ) ;
OUString c1 ;
OUString c2 ;
v = ! ( c1 = = c2 ) ;
// expected-error@-1 {{logical negation of comparison operator, can be simplified by inverting operator [loplugin:simplifybool]}}
return v ;
}
} ;
2019-02-15 12:56:52 +02:00
} ;
namespace group4
{
bool foo1 ( bool a , bool b )
{
return ! ( ! a & & ! b ) ;
// expected-error@-1 {{logical negation of logical op containing negation, can be simplified [loplugin:simplifybool]}}
}
bool foo2 ( int a , bool b )
{
return ! ( a ! = 1 & & ! b ) ;
// expected-error@-1 {{logical negation of logical op containing negation, can be simplified [loplugin:simplifybool]}}
}
bool foo3 ( int a , bool b )
{
// no warning expected
return ! ( a ! = 1 & & b ) ;
}
} ;
2019-02-14 13:01:42 +02:00
2019-02-26 12:07:24 +02:00
namespace group5
{
bool foo1 ( std : : map < int , int > * pActions , int aKey )
{
auto aIter = pActions - > find ( aKey ) ;
//TODO this doesn't work yet because I'd need to implement conversion operators during method/func lookup
return ! ( aIter = = pActions - > end ( ) ) ;
// expected-error@-1 {{logical negation of comparison operator, can be simplified by inverting operator [loplugin:simplifybool]}}
}
} ;
2017-11-22 09:33:32 +02:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */