aboutsummaryrefslogtreecommitdiffstats
path: root/doc/src/editors/creator-clang-codemodel.qdoc
blob: 001a7c8f5651fbc946bbd6480856a30560559b8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Creator documentation.
**
** 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 Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
**
****************************************************************************/

// **********************************************************************
// NOTE: the sections are not ordered by their logical order to avoid
// reshuffling the file each time the index order changes (i.e., often).
// Run the fixnavi.pl script to adjust the links to the index order.
// **********************************************************************

/*!
    \contentspage {Qt Creator Manual}
    \previouspage creator-diff-editor.html
    \page creator-clang-codemodel.html
    \nextpage creator-finding-overview.html

    \title Parsing C++ Files with the Clang Code Model

    The \e {code model} is the part of an IDE that understands the language you
    are using to write your application. It is the framework that allows \QC
    to provide the following services:

    \list

        \li \l{Completing Code}{Code completion}

        \li Syntactic and \l{Semantic Highlighting}{semantic highlighting}

        \li Navigating in the code by using the \l{Searching with the Locator}
            {locator}, \l{Moving to Symbol Definition or Declaration}
            {following symbols}, and so on

        \li Inspecting code by using the \l{Browsing Project Contents}
            {class browser}, the \l{Viewing QML Types}{outline}, and so on

        \li Diagnostics and \l{Viewing Function Tooltips}{tooltips}

        \li \l{Finding Symbols}{Finding and renaming symbols}

        \li \l{Applying Refactoring Actions}{Refactoring actions}

    \endlist

    \QC comes with a plugin that provides some of these services
    for C++ on top of \l{http://clang.llvm.org/}{Clang}.

    \section1 About the Clang Code Model

    The Clang project provides libraries for parsing
    C language family source files. The feedback you get through warning and
    error markers is the same as a compiler will give you, not an incomplete
    set or a close approximation, as when using the built-in \QC code model.
    Clang focuses on detailed information for diagnostics, which is really
    useful if the code contains typos, for example.

    Clang keeps up with the development of the C++ language. At the time of this
    writing, it supports C++98/03, C++11, C++14, C++17, C89, C99, Objective-C,
    and Objective-C++.

    On the downside, for large projects using Clang as code model is slower than
    using the built-in code model. Clang does not need to generate object files,
    but it still needs to parse and analyze the source files. For small projects
    that only use STL, this is relatively fast. But for larger projects that
    include several files, processing a single file and all the included files
    can take a while.

    The Clang code model plugin replaces services of the old C/C++ code model.
    Currently the following services are implemented:

    \list

        \li Code completion
        \li Syntactic and semantic highlighting
        \li Diagnostics
        \li Clang-Tidy checks
        \li Clazy checks
        \li Tooltips
        \li Renaming of local symbols

    \endlist

    \section1 Code Model Warnings

    The predefined configurations request Clang warnings at the following
    levels:

    \list

        \li \uicontrol {Pedantic Warnings} uses the \c -Wpendantic option that
            requests all the warnings demanded by strict ISO C and ISO C++.

        \li \uicontrol {Warnings for Questionable Constructs} combines the
            \c -Wall and \c -Wextra options to request all warnings about easily
            avoidable questionable constructions and some additional warnings.

        \li \uicontrol {Warnings for Almost Everything} uses the \c -Weverything
            option with negative options to suppress some warnings.

    \endlist

    You can edit the predefined configurations to request specific warnings
    beginning with \c -W. Each of these warnings also has a negative version
    that begins with \c -Wno.

    Keep in mind that some options turn on other options. For more information,
    see \l{https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html}
    {Options to Request or Suppress Warnings} or the GCC or Clang manual pages.

    \section1 Using Clang-Tidy Checks

    \l{https://clang.llvm.org/extra/clang-tidy/}{Clang-Tidy} is delivered
    as a part of the Clang library delivered with \QC. It provides diagnostics
    and fixes for typical programming errors, such as style violations,
    interface misuse, or issues that can be found via static analysis.

    \QC integrates the fixes and diagnostics into the Clang library, and
    therefore they cannot be easily changed or extended when used with \QC.

    \section1 Using Clazy

    \l{https://github.com/KDE/clazy/blob/master/README.md}{Clazy} is delivered
    as a part of the Clang library delivered with \QC. It helps Clang understand
    Qt semantics. It prints out Qt related compiler warnings, ranging from
    unnecessary memory allocation to misuse of API and provides refactoring
    actions for fixing some of the issues.

    The Clazy checks are divided into levels from 0 to 3. Each level adds checks
    to the previous level. The checks at level 0 are very stable and provide
    hardly any false positives, while the checks at level 3 can be considered
    experimental.

    For more information about the checks run at each level, see
    \l{https://github.com/KDE/clazy/blob/master/README.md#list-of-checks}
    {List of Checks} in the Clazy documentation.

    \section1 Configuring Clang Code Model

    To specify settings for the Clang code model:

    \list 1

        \li Select \uicontrol Tools > \uicontrol Options > \uicontrol C++ >
            \uicontrol {Code Model}.

            \image qtcreator-clang-code-model-options.png

        \li To instruct the code model to interpret ambiguous header files as C
            language files if you develop mainly using C, select the
            \uicontrol {Interpret ambiguous headers as C headers} check box.

        \li To process precompiled headers, deselect the
            \uicontrol {Ignore precompiled headers} check box.

        \li To avoid out-of-memory crashes caused by indexing huge source files
            that are typically auto-generated by scripts or code, the size of
            files to index is limited to 5MB by default. To adjust the limit,
            edit the value for the \uicontrol {Do not index files greater than}
            check box. To index all files, deselect the check box.

        \li In \uicontrol {Clang Dianostics}, select one of the predefined
            configurations, or select \uicontrol Copy to create a copy of a
            configuration and edit it to fit your needs.

            \list

                \li In the \uicontrol Clang tab, edit the predefined
                    configuration to request specific warnings.

                \li In the \uicontrol {Clang-Tidy} tab, select the checks to
                    perform.

                    \image qtcreator-clang-tidy.png

                \li In the \uicontrol Clazy tab, select the level of Clazy
                    checks to perform.

                    \image qtcreator-clazy.png

            \endlist

    \endlist

    \section1 Specifying Clang Settings at Project Level

    You can specify Clang settings at project level in the build settings of
    the project by selecting \uicontrol Projects >
    \uicontrol {Clang Code Model}. In addition to configuring the diagnostics,
    you can select the \uicontrol {Enable MSVC-compliant template parsing} check
    box to parse templates in a MSVC-compliant way. This enables Clang to parse
    headers for example from Active Template Library (ATL) or Windows Runtime
    Library (WRL). However, using the relaxed and extended rules means that no
    highlighting or completion can be provided within template functions.

    \image qtcreator-clang-code-model-build-settings.png

*/