2017-02-16 17:36:21 +01: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/.
*/
void f1 ( char * ) { }
void f2 ( char const * ) { }
2017-03-20 09:01:33 +02:00
enum Enum1 { X } ;
2017-05-31 18:04:22 +02:00
struct S {
void f1 ( ) { ( void ) * this ; } ;
void f2 ( ) const { ( void ) * this ; } ;
void f3 ( ) { ( void ) * this ; }
void f3 ( ) const { ( void ) * this ; } ;
} ;
2017-02-16 17:36:21 +01:00
int main ( ) {
char * p1 ;
char const * p2 ;
p1 = nullptr ;
p2 = " " ;
f1 ( const_cast < char * > ( p1 ) ) ; // expected-error {{redundant const_cast from 'char *' to 'char *' [loplugin:redundantcast]}}
f1 ( const_cast < char * const > ( p1 ) ) ; // expected-error {{redundant const_cast from 'char *' to 'char *const' [loplugin:redundantcast]}}
f1 ( const_cast < char * > ( p2 ) ) ;
f1 ( const_cast < char * const > ( p2 ) ) ;
2017-02-16 17:42:53 +01:00
f2 ( const_cast < char * > ( p1 ) ) ; // expected-error {{redundant const_cast from 'char *' to 'char *' [loplugin:redundantcast]}}
f2 ( const_cast < char * const > ( p1 ) ) ; // expected-error {{redundant const_cast from 'char *' to 'char *const' [loplugin:redundantcast]}}
2017-02-16 17:36:21 +01:00
f2 ( const_cast < char const * > ( p1 ) ) ;
f2 ( const_cast < char const * const > ( p1 ) ) ;
2017-05-03 11:14:14 +02:00
f2 ( const_cast < char * > ( p2 ) ) ; // expected-error {{redundant const_cast from 'const char *' to 'char *', result is implicitly cast to 'const char *' [loplugin:redundantcast]}}
f2 ( const_cast < char * const > ( p2 ) ) ; // expected-error {{redundant const_cast from 'const char *' to 'char *', result is implicitly cast to 'const char *' [loplugin:redundantcast]}}
2017-02-16 17:36:21 +01:00
f2 ( const_cast < char const * > ( p2 ) ) ; // expected-error {{redundant const_cast from 'const char *' to 'const char *' [loplugin:redundantcast]}}
f2 ( const_cast < char const * const > ( p2 ) ) ; // expected-error {{redundant const_cast from 'const char *' to 'const char *const' [loplugin:redundantcast]}}
2017-03-20 09:01:33 +02:00
2017-04-07 09:08:35 +02:00
Enum1 e = ( Enum1 ) Enum1 : : X ; // expected-error {{redundant cstyle cast from 'Enum1' to 'Enum1' [loplugin:redundantcast]}}
2017-03-20 09:01:33 +02:00
( void ) e ;
2017-05-31 18:04:22 +02:00
S const s ;
const_cast < S & > ( s ) . f1 ( ) ;
const_cast < S & > ( s ) . f2 ( ) ; // expected-error {{redundant const_cast from 'const S' to 'S', result is implicitly cast to 'const S' [loplugin:redundantcast]}}
const_cast < S & > ( s ) . f3 ( ) ;
s . f3 ( ) ;
2017-02-16 17:36:21 +01:00
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */