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]}}
(void)const_cast<char*>(static_cast<charconst*>(nullptr));// expected-error-re {{redundant static_cast/const_cast combination from '{{(std::)?}}nullptr_t' via 'const char *' to 'char *' [loplugin:redundantcast]}}
(void)const_cast<S&>(static_cast<Sconst&>(D{}));// expected-error {{redundant static_cast/const_cast combination from 'D' via 'const S &' to 'S &' [loplugin:redundantcast]}}
const_cast<S&>(s).f2();// expected-error {{redundant const_cast from 'const S' to 'S', result is implicitly cast to 'const S' [loplugin:redundantcast]}}
(void)const_cast<int&>(ni);// expected-error {{redundant const_cast from 'int' lvalue to 'int &' lvalue [loplugin:redundantcast]}}
(void)const_cast<int&&>(ni);
// (void) const_cast<int const>(ni);
(void)const_cast<intconst&>(ni);
(void)const_cast<intconst&&>(ni);
// non-class lvalue, const:
intconstci{};
// (void) const_cast<int>(ci);
(void)const_cast<int&>(ci);
(void)const_cast<int&&>(ci);
// (void) const_cast<int const>(ci);
(void)const_cast<intconst&>(ci);// expected-error {{redundant const_cast from 'const int' lvalue to 'const int &' lvalue [loplugin:redundantcast]}}
(void)const_cast<intconst&&>(ci);
// non-class xvalue, non-const:
// (void) const_cast<int>(nix());
// (void) const_cast<int &>(nix());
(void)const_cast<int&&>(nix());// expected-error {{redundant const_cast from 'int' xvalue to 'int &&' xvalue [loplugin:redundantcast]}}
// (void) const_cast<int const>(nix());
// (void) const_cast<int const &>(nix());
(void)const_cast<intconst&&>(nix());
// non-class xvalue, const:
// (void) const_cast<int>(cix());
// (void) const_cast<int &>(cix());
(void)const_cast<int&&>(cix());
// (void) const_cast<int const>(cix());
// (void) const_cast<int const &>(cix());
(void)const_cast<intconst&&>(cix());// expected-error {{redundant const_cast from 'const int' xvalue to 'const int &&' xvalue [loplugin:redundantcast]}}
// non-class prvalue, non-const:
// (void) const_cast<int>(nir());
// (void) const_cast<int &>(nir());
// (void) const_cast<int &&>(nir());
// (void) const_cast<int const>(nir());
// (void) const_cast<int const &>(nir());
// (void) const_cast<int const &&>(nir());
// non-class prvalue, const:
// (void) const_cast<int>(cir());
// (void) const_cast<int &>(cir());
// (void) const_cast<int &&>(cir());
// (void) const_cast<int const>(cir());
// (void) const_cast<int const &>(cir());
// (void) const_cast<int const &&>(cir());
// class lvalue, non-const:
Sns{};
// (void) const_cast<S>(ns);
(void)const_cast<S&>(ns);// expected-error {{redundant const_cast from 'S' lvalue to 'S &' lvalue [loplugin:redundantcast]}}
(void)const_cast<S&&>(ns);
// (void) const_cast<S const>(ns);
(void)const_cast<Sconst&>(ns);
(void)const_cast<Sconst&&>(ns);
// class lvalue, const:
Sconstcs{};
// (void) const_cast<S>(cs);
(void)const_cast<S&>(cs);
(void)const_cast<S&&>(cs);
// (void) const_cast<S const>(cs);
(void)const_cast<Sconst&>(cs);// expected-error {{redundant const_cast from 'const S' lvalue to 'const S &' lvalue [loplugin:redundantcast]}}
(void)const_cast<Sconst&&>(cs);
// class xvalue, non-const:
// (void) const_cast<S>(nsx());
// (void) const_cast<S &>(nsx());
(void)const_cast<S&&>(nsx());// expected-error {{redundant const_cast from 'S' xvalue to 'S &&' xvalue [loplugin:redundantcast]}}
// (void) const_cast<S const>(nsx());
// (void) const_cast<S const &>(nsx());
(void)const_cast<Sconst&&>(nsx());
// class xvalue, const:
// (void) const_cast<S>(csx());
// (void) const_cast<S &>(csx());
(void)const_cast<S&&>(csx());
// (void) const_cast<S const>(csx());
// (void) const_cast<S const &>(csx());
(void)const_cast<Sconst&&>(csx());// expected-error {{redundant const_cast from 'const S' xvalue to 'const S &&' xvalue [loplugin:redundantcast]}}
(void)static_cast<int>(ni);// expected-error {{static_cast from 'int' lvalue to 'int' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
(void)static_cast<int&>(ni);// expected-error {{static_cast from 'int' lvalue to 'int &' lvalue is redundant [loplugin:redundantcast]}}
(void)static_cast<int&&>(ni);
(void)static_cast<intconst>(ni);// expected-error {{in static_cast from 'int' lvalue to 'const int' prvalue, remove redundant top-level const qualifier [loplugin:redundantcast]}}
/* => */(void)static_cast<int>(ni);// expected-error {{static_cast from 'int' lvalue to 'int' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
(void)static_cast<intconst&>(ni);// expected-error {{static_cast from 'int' lvalue to 'const int &' lvalue should be written as const_cast [loplugin:redundantcast]}}
/* => */(void)const_cast<intconst&>(ni);
(void)static_cast<intconst&&>(ni);// expected-error {{static_cast from 'int' lvalue to 'const int &&' xvalue should be written as const_cast [loplugin:redundantcast]}}
/* => */(void)const_cast<intconst&&>(ni);
// non-class lvalue, const:
intconstci{};
(void)static_cast<int>(ci);// expected-error {{static_cast from 'const int' lvalue to 'int' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
/* => */(void)int(ci);
// (void) static_cast<int &>(ci);
// (void) static_cast<int &&>(ci);
(void)static_cast<intconst>(ci);// expected-error {{in static_cast from 'const int' lvalue to 'const int' prvalue, remove redundant top-level const qualifier [loplugin:redundantcast]}}
/* => */(void)static_cast<int>(ci);// expected-error {{static_cast from 'const int' lvalue to 'int' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
/* => */(void)int(ci);
(void)static_cast<intconst&>(ci);// expected-error {{static_cast from 'const int' lvalue to 'const int &' lvalue is redundant [loplugin:redundantcast]}}
(void)static_cast<intconst&&>(ci);
// non-class xvalue, non-const:
(void)static_cast<int>(nix());// expected-error {{static_cast from 'int' xvalue to 'int' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
(void)static_cast<int&&>(nix());// expected-error {{static_cast from 'int' xvalue to 'int &&' xvalue is redundant [loplugin:redundantcast]}}
(void)static_cast<intconst>(nix());// expected-error {{in static_cast from 'int' xvalue to 'const int' prvalue, remove redundant top-level const qualifier [loplugin:redundantcast]}}
/* => */(void)static_cast<int>(nix());// expected-error {{static_cast from 'int' xvalue to 'int' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
(void)static_cast<intconst&>(nix());
(void)static_cast<intconst&&>(nix());// expected-error {{static_cast from 'int' xvalue to 'const int &&' xvalue should be written as const_cast [loplugin:redundantcast]}}
/* => */(void)const_cast<intconst&&>(nix());
// non-class xvalue, const:
(void)static_cast<int>(cix());// expected-error {{static_cast from 'const int' xvalue to 'int' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
/* => */(void)int(cix());
// (void) static_cast<int &>(cix());
// (void) static_cast<int &&>(cix());
(void)static_cast<intconst>(cix());// expected-error {{in static_cast from 'const int' xvalue to 'const int' prvalue, remove redundant top-level const qualifier [loplugin:redundantcast]}}
/* => */(void)static_cast<int>(cix());// expected-error {{static_cast from 'const int' xvalue to 'int' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
/* => */(void)int(cix());
(void)static_cast<intconst&>(cix());
(void)static_cast<intconst&&>(cix());// expected-error {{static_cast from 'const int' xvalue to 'const int &&' xvalue is redundant [loplugin:redundantcast]}}
// non-class prvalue, non-const:
(void)static_cast<int>(nir());// expected-error {{static_cast from 'int' prvalue to 'int' prvalue is redundant [loplugin:redundantcast]}}
// (void) static_cast<int &>(nir());
(void)static_cast<int&&>(nir());
(void)static_cast<intconst>(nir());// expected-error {{in static_cast from 'int' prvalue to 'const int' prvalue, remove redundant top-level const qualifier [loplugin:redundantcast]}}
/* => */(void)static_cast<int>(nir());// expected-error {{static_cast from 'int' prvalue to 'int' prvalue is redundant [loplugin:redundantcast]}}
(void)static_cast<intconst&>(nir());// expected-error {{static_cast from 'int' prvalue to 'const int &' lvalue is redundant [loplugin:redundantcast]}}
(void)static_cast<intconst&&>(nir());
// non-class prvalue, const:
(void)static_cast<int>(cir());// expected-error {{static_cast from 'int' prvalue to 'int' prvalue is redundant [loplugin:redundantcast]}}
// (void) static_cast<int &>(cir());
(void)static_cast<int&&>(cir());
(void)static_cast<intconst>(cir());// expected-error {{in static_cast from 'int' prvalue to 'const int' prvalue, remove redundant top-level const qualifier [loplugin:redundantcast]}}
/* => */(void)static_cast<int>(cir());// expected-error {{static_cast from 'int' prvalue to 'int' prvalue is redundant [loplugin:redundantcast]}}
(void)static_cast<intconst&>(cir());// expected-error {{static_cast from 'int' prvalue to 'const int &' lvalue is redundant [loplugin:redundantcast]}}
(void)static_cast<intconst&&>(cir());
// class lvalue, non-const:
Sns{};
(void)static_cast<S>(ns);// expected-error {{static_cast from 'S' lvalue to 'S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
(void)static_cast<S&>(ns);// expected-error {{static_cast from 'S' lvalue to 'S &' lvalue is redundant [loplugin:redundantcast]}}
(void)static_cast<S&&>(ns);
(void)static_cast<Sconst>(ns);// expected-error {{static_cast from 'S' lvalue to 'const S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
/* => */usingCS=constS;(void)CS(ns);
(void)static_cast<Sconst&>(ns);// expected-error {{static_cast from 'S' lvalue to 'const S &' lvalue should be written as const_cast [loplugin:redundantcast]}}
/* => */(void)const_cast<Sconst&>(ns);
(void)static_cast<Sconst&&>(ns);// expected-error {{static_cast from 'S' lvalue to 'const S &&' xvalue should be written as const_cast [loplugin:redundantcast]}}
/* => */(void)const_cast<Sconst&&>(ns);
// class lvalue, const:
Sconstcs{};
(void)static_cast<S>(cs);// expected-error {{static_cast from 'const S' lvalue to 'S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
/* => */(void)S(cs);
// (void) static_cast<S &>(cs);
// (void) static_cast<S &&>(cs);
(void)static_cast<Sconst>(cs);// expected-error {{static_cast from 'const S' lvalue to 'const S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
/* => */(void)CS(cs);
(void)static_cast<Sconst&>(cs);// expected-error {{static_cast from 'const S' lvalue to 'const S &' lvalue is redundant [loplugin:redundantcast]}}
(void)static_cast<Sconst&&>(cs);
// class xvalue, non-const:
(void)static_cast<S>(nsx());// expected-error {{static_cast from 'S' xvalue to 'S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
(void)static_cast<S&&>(nsx());// expected-error {{static_cast from 'S' xvalue to 'S &&' xvalue is redundant [loplugin:redundantcast]}}
(void)static_cast<Sconst>(nsx());// expected-error {{static_cast from 'S' xvalue to 'const S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
/* => */(void)CS(nsx());
(void)static_cast<Sconst&>(nsx());
(void)static_cast<Sconst&&>(nsx());// expected-error {{static_cast from 'S' xvalue to 'const S &&' xvalue should be written as const_cast [loplugin:redundantcast]}}
/* => */(void)const_cast<Sconst&&>(nsx());
// class xvalue, const:
(void)static_cast<S>(csx());// expected-error {{static_cast from 'const S' xvalue to 'S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
/* => */(void)S(csx());
// (void) static_cast<S &>(csx());
// (void) static_cast<S &&>(csx());
(void)static_cast<Sconst>(csx());// expected-error {{static_cast from 'const S' xvalue to 'const S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
/* => */(void)CS(csx());
(void)static_cast<Sconst&>(csx());
(void)static_cast<Sconst&&>(csx());// expected-error {{static_cast from 'const S' xvalue to 'const S &&' xvalue is redundant [loplugin:redundantcast]}}
// class prvalue, non-const:
(void)static_cast<S>(nsr());// expected-error {{static_cast from 'S' prvalue to 'S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
(void)static_cast<Sconst>(nsr());// expected-error {{static_cast from 'S' prvalue to 'const S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
/* => */(void)CS(nsr());
(void)static_cast<Sconst&>(nsr());// expected-error {{static_cast from 'S' prvalue to 'const S &' lvalue is redundant [loplugin:redundantcast]}}
(void)static_cast<Sconst&&>(nsr());// expected-error {{static_cast from 'S' prvalue to 'const S &&' xvalue should be written as const_cast [loplugin:redundantcast]}}
/* => */(void)const_cast<Sconst&&>(nsr());
// class prvalue, const:
(void)static_cast<S>(csr());// expected-error {{static_cast from 'const S' prvalue to 'S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
/* => */(void)S(csr());
// (void) static_cast<S &>(csr());
// (void) static_cast<S &&>(csr());
(void)static_cast<Sconst>(csr());// expected-error {{static_cast from 'const S' prvalue to 'const S' prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
/* => */(void)CS(csr());
(void)static_cast<Sconst&>(csr());// expected-error {{static_cast from 'const S' prvalue to 'const S &' lvalue is redundant [loplugin:redundantcast]}}
(void)reinterpret_cast<std::size_t>((const_cast<intconst*>(&n)));// expected-error-re {{redundant const_cast from 'int *' to 'const int *' within reinterpret_cast to fundamental type 'std::size_t' (aka 'unsigned {{.+}}') [loplugin:redundantcast]}}
// expected-error@+1 {{suspicious reinterpret_cast from derived 'D *' to base 'S *', maybe this was meant to be a static_cast [loplugin:redundantcast]}}
(void)reinterpret_cast<S*>(p);
(void)reinterpret_cast<sal_uIntPtr>(p);// expected no error
(void)static_cast<void(*)()>(nonOverload);// expected-error {{static_cast from 'void (*)()' prvalue to 'void (*)()' prvalue is redundant [loplugin:redundantcast]}}
(void)static_cast<void(*)()>((nonOverload));// expected-error {{static_cast from 'void (*)()' prvalue to 'void (*)()' prvalue is redundant [loplugin:redundantcast]}}
(void)static_cast<void(*)()>(&nonOverload);// expected-error {{static_cast from 'void (*)()' prvalue to 'void (*)()' prvalue is redundant [loplugin:redundantcast]}}
(void)static_cast<void(*)()>((&nonOverload));// expected-error {{static_cast from 'void (*)()' prvalue to 'void (*)()' prvalue is redundant [loplugin:redundantcast]}}
(void)static_cast<void(*)()>(&((nonOverload)));// expected-error {{static_cast from 'void (*)()' prvalue to 'void (*)()' prvalue is redundant [loplugin:redundantcast]}}
(void)static_cast<void(Overload::*)()>(&Overload::nonOverload);// expected-error {{static_cast from 'void (Overload::*)()' prvalue to 'void (Overload::*)()' prvalue is redundant [loplugin:redundantcast]}}
usingOverloadFn=void(*)(long);
(void)OverloadFn(overload);
usingNonOverloadFn=void(*)();
(void)NonOverloadFn(nonOverload);// expected-error {{redundant functional cast from 'void (*)()' to 'NonOverloadFn' (aka 'void (*)()') [loplugin:redundantcast]}}
usingOverloadMemFn=long(Overload::*)()const;
(void)OverloadMemFn(&Overload::overload);
usingNonOverloadMemFn=void(Overload::*)();
(void)NonOverloadMemFn(&Overload::nonOverload);// expected-error {{redundant functional cast from 'void (Overload::*)()' to 'NonOverloadMemFn' (aka 'void (Overload::*)()') [loplugin:redundantcast]}}
n=static_cast<double>(n);// expected-error {{suspicious static_cast from 'int' to 'double', result is implicitly cast to 'int' [loplugin:redundantcast]}}
n=double(n);// expected-error {{suspicious functional cast from 'int' to 'double', result is implicitly cast to 'int' [loplugin:redundantcast]}}
doubled=0.0;
d=static_cast<int>(d)+1.0;// expected-error {{suspicious static_cast from 'double' to 'int', result is implicitly cast to 'double' [loplugin:redundantcast]}}
d=int(d)+1.0;// expected-error {{suspicious functional cast from 'double' to 'int', result is implicitly cast to 'double' [loplugin:redundantcast]}}
(void)static_cast<sal_Int16>(n);// expected-error-re {{static_cast from 'const sal_Int16' (aka 'const {{.+}}') lvalue to 'sal_Int16' (aka '{{.+}}') prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
(void)static_cast<::sal_Int16>(n);// expected-error-re {{static_cast from 'const sal_Int16' (aka 'const {{.+}}') lvalue to '::sal_Int16' (aka '{{.+}}') prvalue is redundant or should be written as an explicit construction of a temporary [loplugin:redundantcast]}}
(void)static_cast<short>(n);// doesn't warn, even if 'sal_Int16' is 'short'
usingOther=sal_Int16;
(void)static_cast<Other>(n);// doesn't warn either