blob: 6567dcd2cce3985cfc1c9dfc27101400393797b0 [file] [log] [blame]
Chandler Carruthd9063c42013-09-04 17:35:07 +00001.. index:: clang-modernize
2
3==================================
4Clang C++ Modernizer User's Manual
5==================================
6
7.. toctree::
8 :hidden:
9
10 UseAutoTransform
11 UseNullptrTransform
12 LoopConvertTransform
13 AddOverrideTransform
14 PassByValueTransform
15 ReplaceAutoPtrTransform
16 ModernizerUsage
17
18:program:`clang-modernize` is a standalone tool used to automatically convert
19C++ code written against old standards to use features of the newest C++
20standard where appropriate.
21
22Getting Started
23===============
24
25To build from source:
26
271. Read `Getting Started with the LLVM System`_ and `Clang Tools
28 Documentation`_ for information on getting sources for LLVM, Clang, and
29 Clang Extra Tools.
30
312. `Getting Started with the LLVM System`_ and `Building LLVM with CMake`_ give
32 directions for how to build. With sources all checked out into the
33 right place the LLVM build will build Clang Extra Tools and their
34 dependencies automatically.
35
36 * If using CMake, you can also use the ``clang-modernize`` target to build
37 just the Modernizer and its dependencies.
38
39Before continuing, take a look at :doc:`ModernizerUsage` to see how to invoke
40the Modernizer.
41
42Before running the Modernizer on code you'll need the arguments you'd normally
43pass to the compiler. If you're migrating a single file with few compiler
44arguments, it might be easier to pass the compiler args on the command line
45after ``--``. If you don't have any compiler arguments then ``--`` is not needed.
46If you're working with multiple files or even a single file with many compiler
47args, it's probably best to use a *compilation database*.
48
49A `compilation database`_ contains the command-line arguments for multiple
50files. If the code you want to transform can be built with CMake, you can
51generate this database easily by running CMake with the
52``-DCMAKE_EXPORT_COMPILE_COMMANDS`` option. The Ninja_ build system, since
53v1.2, can create this file too using the *compdb* tool: ``ninja -t compdb``. If
54you're not already using either of these tools or cannot easily make use of
55them you might consider looking into Bear_.
56
57In addition to the compiler arguments you usually build your code with, you must
58provide the option for enabling C++11 features. For clang and versions of gcc
59 v4.8 this is ``-std=c++11``.
60
61Now with compiler arguments, the Modernizer can be applied to source. Sources
62are transformed in place and changes are only written to disk if compilation
63errors aren't caused by the transforms. Each transform will re-parse the output
64from the previous transform. The output from the last transform is not checked
65unless ``-final-syntax-check`` is enabled.
66
67
68.. _Ninja: http://martine.github.io/ninja/
69.. _Bear: https://github.com/rizsotto/Bear
70.. _compilation database: http://clang.llvm.org/docs/JSONCompilationDatabase.html
71.. _Getting Started with the LLVM System: http://llvm.org/docs/GettingStarted.html
72.. _Building LLVM with CMake: http://llvm.org/docs/CMake.html
73.. _Clang Tools Documentation: http://clang.llvm.org/docs/ClangTools.html
74
75Getting Involved
76================
77
78If you find a bug
79
80.. raw:: html
81
82 <input type="button" id="logbug" value="Log a Bug!" />
83 <script type="text/javascript" src="https://cpp11-migrate.atlassian.net/s/en_USpfg3b3-1988229788/6095/34/1.4.0-m2/_/download/batch/com.atlassian.jira.collector.plugin.jira-issue-collector-plugin:issuecollector/com.atlassian.jira.collector.plugin.jira-issue-collector-plugin:issuecollector.js?collectorId=50813874"></script>
84 <script type="text/javascript">window.ATL_JQ_PAGE_PROPS = {
85 "triggerFunction": function(showCollectorDialog) {
86 //Requries that jQuery is available!
87 jQuery("#logbug").click(function(e) {
88 e.preventDefault();
89 showCollectorDialog();
90 });
91 }};
92 </script>
93
94Bugs and feature development of the Modernizer are tracked at
95http://cpp11-migrate.atlassian.net. If you want to get involved the front page
96shows a list of outstanding issues or you can browse around the project to get
97familiar. To take on issues or contribute feature requests and/or bug reports
98you need to sign up for an account from the `log in page`_. An account also
99lets you sign up for notifications on issues or vote for unassigned issues to
100be completed.
101
102.. _log in page: https://cpp11-migrate.atlassian.net/login
103
104.. _transforms:
105
106Transformations
107===============
108
109The Modernizer is a collection of independent transforms which can be
110independently enabled. The transforms currently implemented are:
111
112* :doc:`LoopConvertTransform`
113
114* :doc:`UseNullptrTransform`
115
116* :doc:`UseAutoTransform`
117
118* :doc:`AddOverrideTransform`
119
120* :doc:`PassByValueTransform`
121
122* :doc:`ReplaceAutoPtrTransform`