diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2017-06-02 10:39:28 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2017-06-02 10:39:53 +0200 |
commit | 5872221094834af8553b3a7028d52f26dda391fa (patch) | |
tree | cb4e55028f1fa0e7b1bff41d1911cd94e729b104 /compilerplugins | |
parent | 4d0f4fefeb128cf7d61ebfceb8fb2befd3e98904 (diff) |
Reorganize tests
Change-Id: Ic3d9e55b2730a3ea01cc6c7c9fbdd80a1e653c7e
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/test/redundantcast.cxx | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/compilerplugins/clang/test/redundantcast.cxx b/compilerplugins/clang/test/redundantcast.cxx index ddf525ae9f0c..6e5a8d42e589 100644 --- a/compilerplugins/clang/test/redundantcast.cxx +++ b/compilerplugins/clang/test/redundantcast.cxx @@ -14,7 +14,7 @@ void f2(char const *) {} enum Enum1 { X }; -int main() { +void testConstCast() { char * p1; char const * p2; p1 = nullptr; @@ -32,15 +32,14 @@ int main() { 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]}} - Enum1 e = (Enum1)Enum1::X; // expected-error {{redundant cstyle cast from 'Enum1' to 'Enum1' [loplugin:redundantcast]}} - (void)e; - 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(); +} +void testStaticCast() { // non-class lvalue, non-const: int ni{}; (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]}} @@ -174,4 +173,15 @@ int main() { (void) static_cast<S const &&>(csr()); } +void testCStyleCast() { + Enum1 e = (Enum1)Enum1::X; // expected-error {{redundant cstyle cast from 'Enum1' to 'Enum1' [loplugin:redundantcast]}} + (void)e; +} + +int main() { + testConstCast(); + testStaticCast(); + testCStyleCast(); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |