aboutsummaryrefslogtreecommitdiffstats
path: root/share/qtcreator
diff options
context:
space:
mode:
authorIvan Donchevskii <ivan.donchevskii@qt.io>2018-02-15 11:31:14 +0100
committerIvan Donchevskii <ivan.donchevskii@qt.io>2018-02-20 06:50:12 +0000
commitcec807f5c1ac609d76d4bc83072e0586cbc55b83 (patch)
treea1862e4192c71c8bcfe095340d4abcff30668ace /share/qtcreator
parent66c7629814e01cf8ea213b06548eabcf32d1c206 (diff)
Clang: Provide example with a lot of tidy warnings
Change-Id: I6d6d2559bb8e2b6c972e88c3af9ce06968e7c959 Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Diffstat (limited to 'share/qtcreator')
-rw-r--r--share/qtcreator/cplusplus/examples/examples.pro9
-rw-r--r--share/qtcreator/cplusplus/examples/tidy_example.cpp273
-rw-r--r--share/qtcreator/cplusplus/examples/tidy_example.h39
3 files changed, 321 insertions, 0 deletions
diff --git a/share/qtcreator/cplusplus/examples/examples.pro b/share/qtcreator/cplusplus/examples/examples.pro
new file mode 100644
index 00000000000..01a711810e7
--- /dev/null
+++ b/share/qtcreator/cplusplus/examples/examples.pro
@@ -0,0 +1,9 @@
+QT += core
+
+CONFIG+= c++1z
+
+TARGET = examples
+
+SOURCES += tidy_example.cpp
+
+HEADERS += tidy_example.h
diff --git a/share/qtcreator/cplusplus/examples/tidy_example.cpp b/share/qtcreator/cplusplus/examples/tidy_example.cpp
new file mode 100644
index 00000000000..3d094608183
--- /dev/null
+++ b/share/qtcreator/cplusplus/examples/tidy_example.cpp
@@ -0,0 +1,273 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+// llvm-include-order
+#include <cassert>
+#include <numeric>
+#include <algorithm>
+#include <cstdlib>
+#include <vector>
+
+#include "tidy_example.h"
+
+#define INCREMENT_TWO(x, y) (x)++; (y)++
+
+namespace Foo {
+
+void macro()
+{
+ bool do_increment = true;
+ int a, b;
+
+ // misc-multiple-statement-macro
+ if (do_increment)
+ INCREMENT_TWO(a, b);
+}
+
+} // llvm-namespace-comment
+
+// misc-forward-declaration-namespace
+namespace na { struct A; }
+namespace nb { struct A {}; }
+nb::A a;
+
+// cppcoreguidelines-special-member-functions
+class Base
+{
+public:
+ Base();
+
+ // google-explicit-constructor
+ Base(int arg);
+ virtual ~Base();
+ Base(const Base &) = default;
+ Base(Base &&) = default;
+
+ // cppcoreguidelines-c-copy-assignment-signature
+ // misc-noexcept-move-constructor
+ // misc-unconventional-assign-operator
+ // misc-unused-parameters
+ Base operator=(Base &&param) {}
+ virtual int function()
+ {
+ // modernize-use-nullptr
+ int *a = 0;
+ return 0;
+ }
+protected:
+ void anotherFunctions(bool flag);
+public:
+ // cppcoreguidelines-pro-type-member-init
+ int value;
+};
+
+// cert-err58-cpp
+static Base base;
+
+// modernize-redundant-void-arg
+double getDouble(void)
+{
+ return 10.5;
+}
+
+void bad_malloc(char *str)
+{
+ // modernize-use-auto
+ // cppcoreguidelines-pro-type-cstyle-cast
+ // google-readability-casting
+ // cppcoreguidelines-no-malloc
+ // cppcoreguidelines-pro-bounds-pointer-arithmetic
+ char *c = (char*) malloc(strlen(str + 1));
+}
+
+template <typename T>
+void foo(T&& t)
+{
+ // misc-move-forwarding-reference
+ bar(std::move(t));
+}
+
+void afterMove(Base &&base)
+{
+ Base moved(std::move(base));
+
+ // misc-use-after-move
+ base.value;
+}
+
+// google-runtime-references
+void reference(Base &base)
+{
+
+}
+
+class Derived : public Base {
+public:
+ // modernize-use-equals-default
+ Derived() {}
+
+ // readability-named-parameter
+ Derived(const Derived &) {}
+
+ // modernize-use-override
+ int function()
+ {
+ int a = 0;
+ bool *p = nullptr;
+ // misc-bool-pointer-implicit-conversion, readability-implicit-bool-cast
+ if (p) {
+ }
+ auto b = {0.5f, 0.5f, 0.5f, 0.5f};
+
+ // misc-fold-init-type
+ std::accumulate(std::begin(b), std::end(b), 0);
+
+ // google-readability-casting, misc-incorrect-roundings
+ auto c = (int)(getDouble() + 0.5);
+
+ // misc-string-constructor
+ std::string str('x', 50);
+
+ int i[5] = {1, 2, 3, 4, 5};
+ // cppcoreguidelines-pro-bounds-array-to-pointer-decay
+ int *ip = i;
+
+ // cert-flp30-c
+ for (float a = .0; a != 5.; a += .1) {
+ // cert-msc30-c, cert-msc50-cpp
+ std::rand();
+ }
+
+ // misc-sizeof-container
+ const Base constVal = sizeof(str);
+
+ // cppcoreguidelines-pro-type-const-cast
+ auto val = const_cast<Base &>(constVal);
+
+ // readability-redundant-string-init
+ std::string str2 = "";
+
+ // misc-string-compare
+ if (str.compare(str2)) {
+ return 0;
+ }
+
+ // cppcoreguidelines-pro-type-reinterpret-cast
+ return a + c + reinterpret_cast<int>(&val);
+ }
+};
+
+union Union
+{
+ int intVal;
+ double doubleVal;
+};
+
+class Derived2 : public Base
+{
+public:
+ // misc-virtual-near-miss
+ virtual int functiom()
+ {
+ // cert-env33-c
+ std::system("echo ");
+ // cert-err52-cpp
+ setjmp(nullptr);
+ }
+
+ // google-default-arguments
+ virtual bool check(bool enable = true);
+};
+
+// performance-unnecessary-value-param
+void use(Base b)
+{
+
+}
+
+void FancyFunction()
+{
+ // cppcoreguidelines-pro-type-vararg
+ // cppcoreguidelines-pro-bounds-array-to-pointer-decay
+ // misc-lambda-function-name
+ [] { printf("Called from %s\n", __func__); }();
+}
+
+// modernize-use-using
+typedef int *int_ptr;
+
+// readability-avoid-const-params-in-decls, misc-misplaced-const
+void f(const int_ptr ptr);
+
+void f(int *X, int Y)
+{
+ // readability-misplaced-array-index
+ Y[X] = 0;
+}
+
+int main()
+{
+ // cppcoreguidelines-pro-type-member-init
+ Union u;
+
+ // cppcoreguidelines-pro-type-union-access
+ u.doubleVal = 10.;
+
+ // readability-braces-around-statements, readability-simplify-boolean-expr
+ if (false)
+ return 1;
+ // readability-else-after-return
+ else {
+ // google-readability-todo
+ // TODO: implement something
+ }
+
+ int arr[] = {1,2,3};
+
+ // modernize-loop-convert
+ for (int i = 0; i < 3; ++i) {
+ // cppcoreguidelines-pro-bounds-constant-array-index
+ arr[i];
+ }
+
+ std::vector<std::pair<int, int>> w;
+
+ // modernize-use-emplace
+ w.push_back(std::pair<int, int>(21, 37));
+
+ bool val = false;
+ if (val)
+ if (val)
+ Foo::macro();
+ // readability-misleading-indentation
+ else
+ Foo::macro();
+
+ Derived derived;
+
+ // cppcoreguidelines-slicing
+ use(derived);
+ return 0;
+}
diff --git a/share/qtcreator/cplusplus/examples/tidy_example.h b/share/qtcreator/cplusplus/examples/tidy_example.h
new file mode 100644
index 00000000000..4c38acd1cde
--- /dev/null
+++ b/share/qtcreator/cplusplus/examples/tidy_example.h
@@ -0,0 +1,39 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+// llvm-header-guard
+
+#include <string>
+
+// google-build-using-namespace, google-global-names-in-headers
+using namespace std;
+
+// cert-dcl59-cpp, google-build-namespaces
+namespace {
+class HeaderClass {
+
+};
+
+} // llvm-namespace-comment