summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2017-02-16 17:36:21 +0100
committerStephan Bergmann <sbergman@redhat.com>2017-02-16 17:36:21 +0100
commit6d3db33328fb2fec3539c828d062cad6d16d3195 (patch)
treebd17c7d6403a2b96fc91659bf0237526d3add13e
parent463f764aa0bcf4930ac914e6ed367d95338c65b4 (diff)
Capture loplugin:redundantcast status-quo wrt const_cast
...including some double-warnings that'll get cleaned up shortly Change-Id: I14e9796f2846a6bb61e4c93dfb23cba6488ea2e6
-rw-r--r--compilerplugins/clang/test/redundantcast.cxx32
-rw-r--r--solenv/CompilerTest_compilerplugins_clang.mk1
2 files changed, 33 insertions, 0 deletions
diff --git a/compilerplugins/clang/test/redundantcast.cxx b/compilerplugins/clang/test/redundantcast.cxx
new file mode 100644
index 000000000000..7af9716fa27c
--- /dev/null
+++ b/compilerplugins/clang/test/redundantcast.cxx
@@ -0,0 +1,32 @@
+/* -*- 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 *) {}
+
+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));
+ f2(const_cast<char *>(p1)); // expected-error {{redundant const_cast from 'char *' to 'char *', result is implictly cast to 'const char *' [loplugin:redundantcast]}} 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 *', result is implictly cast to 'const char *' [loplugin:redundantcast]}} expected-error {{redundant const_cast from 'char *' to 'char *const' [loplugin:redundantcast]}}
+ f2(const_cast<char const *>(p1));
+ f2(const_cast<char const * const>(p1));
+ f2(const_cast<char *>(p2)); // expected-error {{redundant const_cast from 'const char *' to 'char *', result is implictly cast to 'const char *' [loplugin:redundantcast]}}
+ f2(const_cast<char * const>(p2)); // expected-error {{redundant const_cast from 'const char *' to 'char *', result is implictly cast to 'const char *' [loplugin:redundantcast]}}
+ 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]}}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/solenv/CompilerTest_compilerplugins_clang.mk b/solenv/CompilerTest_compilerplugins_clang.mk
index 7840b1e0ff1b..85de035974c6 100644
--- a/solenv/CompilerTest_compilerplugins_clang.mk
+++ b/solenv/CompilerTest_compilerplugins_clang.mk
@@ -17,6 +17,7 @@ $(eval $(call gb_CompilerTest_add_exception_objects,compilerplugins_clang, \
compilerplugins/clang/test/oslendian-1 \
compilerplugins/clang/test/oslendian-2 \
compilerplugins/clang/test/oslendian-3 \
+ compilerplugins/clang/test/redundantcast \
compilerplugins/clang/test/salbool \
compilerplugins/clang/test/stringconstant \
compilerplugins/clang/test/unnecessaryoverride-dtor \