2015-10-22 19:31:44 +08:00
// RUN: %check_clang_tidy %s readability-container-size-empty %t
2015-01-15 23:46:58 +08:00
namespace std {
template < typename T > struct vector {
vector ( ) { }
2015-12-12 19:31:25 +08:00
unsigned long size ( ) const { }
2015-01-15 23:46:58 +08:00
bool empty ( ) const { }
} ;
}
int main ( ) {
std : : vector < int > vect ;
if ( vect . size ( ) = = 0 )
;
2015-11-09 23:53:28 +08:00
// CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty]
2015-01-15 23:46:58 +08:00
// CHECK-FIXES: {{^ }}if (vect.empty()){{$}}
if ( vect . size ( ) ! = 0 )
;
2015-11-09 23:53:28 +08:00
// CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
2015-01-15 23:46:58 +08:00
// CHECK-FIXES: {{^ }}if (!vect.empty()){{$}}
if ( 0 = = vect . size ( ) )
;
2015-11-09 23:53:28 +08:00
// CHECK-MESSAGES: :[[@LINE-2]]:12: warning: the 'empty' method should be used
2015-01-15 23:46:58 +08:00
// CHECK-FIXES: {{^ }}if (vect.empty()){{$}}
if ( 0 ! = vect . size ( ) )
;
2015-11-09 23:53:28 +08:00
// CHECK-MESSAGES: :[[@LINE-2]]:12: warning: the 'empty' method should be used
2015-01-15 23:46:58 +08:00
// CHECK-FIXES: {{^ }}if (!vect.empty()){{$}}
if ( vect . size ( ) > 0 )
;
2015-11-09 23:53:28 +08:00
// CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
2015-01-15 23:46:58 +08:00
// CHECK-FIXES: {{^ }}if (!vect.empty()){{$}}
if ( 0 < vect . size ( ) )
;
2015-11-09 23:53:28 +08:00
// CHECK-MESSAGES: :[[@LINE-2]]:11: warning: the 'empty' method should be used
2015-01-15 23:46:58 +08:00
// CHECK-FIXES: {{^ }}if (!vect.empty()){{$}}
if ( vect . size ( ) < 1 )
;
2015-11-09 23:53:28 +08:00
// CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
2015-01-15 23:46:58 +08:00
// CHECK-FIXES: {{^ }}if (vect.empty()){{$}}
if ( 1 > vect . size ( ) )
;
2015-11-09 23:53:28 +08:00
// CHECK-MESSAGES: :[[@LINE-2]]:11: warning: the 'empty' method should be used
2015-01-15 23:46:58 +08:00
// CHECK-FIXES: {{^ }}if (vect.empty()){{$}}
if ( vect . size ( ) > = 1 )
;
2015-11-09 23:53:28 +08:00
// CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
2015-01-15 23:46:58 +08:00
// CHECK-FIXES: {{^ }}if (!vect.empty()){{$}}
if ( 1 < = vect . size ( ) )
;
2015-11-09 23:53:28 +08:00
// CHECK-MESSAGES: :[[@LINE-2]]:12: warning: the 'empty' method should be used
2015-01-15 23:46:58 +08:00
// CHECK-FIXES: {{^ }}if (!vect.empty()){{$}}
2015-12-21 17:43:52 +08:00
if ( vect . size ( ) > 1 ) // no warning
;
if ( 1 < vect . size ( ) ) // no warning
;
2015-01-15 23:46:58 +08:00
if ( ! vect . size ( ) )
;
2015-11-09 23:53:28 +08:00
// CHECK-MESSAGES: :[[@LINE-2]]:8: warning: the 'empty' method should be used
2015-01-15 23:46:58 +08:00
// CHECK-FIXES: {{^ }}if (vect.empty()){{$}}
if ( vect . size ( ) )
;
2015-11-09 23:53:28 +08:00
// CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
2015-01-15 23:46:58 +08:00
// CHECK-FIXES: {{^ }}if (!vect.empty()){{$}}
if ( vect . empty ( ) )
;
const std : : vector < int > vect2 ;
if ( vect2 . size ( ) ! = 0 )
;
2015-11-09 23:53:28 +08:00
// CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
2015-01-15 23:46:58 +08:00
// CHECK-FIXES: {{^ }}if (!vect2.empty()){{$}}
std : : vector < int > * vect3 = new std : : vector < int > ( ) ;
if ( vect3 - > size ( ) = = 0 )
;
2015-11-09 23:53:28 +08:00
// CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
2015-01-15 23:46:58 +08:00
// CHECK-FIXES: {{^ }}if (vect3->empty()){{$}}
delete vect3 ;
const std : : vector < int > & vect4 = vect2 ;
if ( vect4 . size ( ) = = 0 )
;
2015-11-09 23:53:28 +08:00
// CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
2015-01-15 23:46:58 +08:00
// CHECK-FIXES: {{^ }}if (vect4.empty()){{$}}
}
# define CHECKSIZE(x) if (x.size())
// CHECK-FIXES: #define CHECKSIZE(x) if (x.size())
template < typename T > void f ( ) {
std : : vector < T > v ;
if ( v . size ( ) )
;
2015-11-09 23:53:28 +08:00
// CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
2015-01-15 23:46:58 +08:00
// CHECK-FIXES: {{^ }}if (!v.empty()){{$}}
// CHECK-FIXES-NEXT: ;
CHECKSIZE ( v ) ;
2015-11-09 23:53:28 +08:00
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: the 'empty' method should be used
2015-01-15 23:46:58 +08:00
// CHECK-MESSAGES: CHECKSIZE(v);
}
void g ( ) {
f < int > ( ) ;
f < double > ( ) ;
f < char * > ( ) ;
}