blob: cec6a8baa5454fec1ad7ff5da35d9dd8a0bde8f5 [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
Edwin Vane5a816f02013-09-06 19:27:19 +000017 cpp11-migrate
18 MigratorUsage
Chandler Carruthd9063c42013-09-04 17:35:07 +000019
20:program:`clang-modernize` is a standalone tool used to automatically convert
21C++ code written against old standards to use features of the newest C++
22standard where appropriate.
23
24Getting Started
25===============
26
27To build from source:
28
291. Read `Getting Started with the LLVM System`_ and `Clang Tools
30 Documentation`_ for information on getting sources for LLVM, Clang, and
31 Clang Extra Tools.
32
332. `Getting Started with the LLVM System`_ and `Building LLVM with CMake`_ give
34 directions for how to build. With sources all checked out into the
35 right place the LLVM build will build Clang Extra Tools and their
36 dependencies automatically.
37
38 * If using CMake, you can also use the ``clang-modernize`` target to build
39 just the Modernizer and its dependencies.
40
41Before continuing, take a look at :doc:`ModernizerUsage` to see how to invoke
42the Modernizer.
43
44Before running the Modernizer on code you'll need the arguments you'd normally
45pass to the compiler. If you're migrating a single file with few compiler
46arguments, it might be easier to pass the compiler args on the command line
47after ``--``. If you don't have any compiler arguments then ``--`` is not needed.
48If you're working with multiple files or even a single file with many compiler
49args, it's probably best to use a *compilation database*.
50
51A `compilation database`_ contains the command-line arguments for multiple
52files. If the code you want to transform can be built with CMake, you can
53generate this database easily by running CMake with the
54``-DCMAKE_EXPORT_COMPILE_COMMANDS`` option. The Ninja_ build system, since
55v1.2, can create this file too using the *compdb* tool: ``ninja -t compdb``. If
56you're not already using either of these tools or cannot easily make use of
57them you might consider looking into Bear_.
58
59In addition to the compiler arguments you usually build your code with, you must
60provide the option for enabling C++11 features. For clang and versions of gcc
61 v4.8 this is ``-std=c++11``.
62
Edwin Vanec76c0dd2013-10-07 15:56:25 +000063With compiler arguments in hand, the modernizer can be applied to sources. Each
64transform is applied to all sources before the next transform. All the changes
65generated by each transform pass are serialized to disk and applied using
66``clang-apply-replacements``. This executable must be located on the ``PATH``
67or be present in the same directory as the ``clang-modernizer`` executable. If
68any changes fail to apply, the modernizer will **not** proceed to the next
69transform and will halt.
Chandler Carruthd9063c42013-09-04 17:35:07 +000070
Edwin Vanec76c0dd2013-10-07 15:56:25 +000071There's a small chance that changes made by a transform will produce code that
72doesn't compile, also causing the modernizer to halt. This can happen with
73bugs in the transforms or use of the pre-processor to make the same code behave
74differently between translation units. Before logging a bug, be sure which
75situation you are dealing with.
Chandler Carruthd9063c42013-09-04 17:35:07 +000076
77.. _Ninja: http://martine.github.io/ninja/
78.. _Bear: https://github.com/rizsotto/Bear
79.. _compilation database: http://clang.llvm.org/docs/JSONCompilationDatabase.html
80.. _Getting Started with the LLVM System: http://llvm.org/docs/GettingStarted.html
81.. _Building LLVM with CMake: http://llvm.org/docs/CMake.html
82.. _Clang Tools Documentation: http://clang.llvm.org/docs/ClangTools.html
83
84Getting Involved
85================
86
87If you find a bug
88
89.. raw:: html
90
91 <input type="button" id="logbug" value="Log a Bug!" />
92 <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>
93 <script type="text/javascript">window.ATL_JQ_PAGE_PROPS = {
94 "triggerFunction": function(showCollectorDialog) {
95 //Requries that jQuery is available!
96 jQuery("#logbug").click(function(e) {
97 e.preventDefault();
98 showCollectorDialog();
99 });
100 }};
101 </script>
102
103Bugs and feature development of the Modernizer are tracked at
104http://cpp11-migrate.atlassian.net. If you want to get involved the front page
105shows a list of outstanding issues or you can browse around the project to get
106familiar. To take on issues or contribute feature requests and/or bug reports
107you need to sign up for an account from the `log in page`_. An account also
108lets you sign up for notifications on issues or vote for unassigned issues to
109be completed.
110
111.. _log in page: https://cpp11-migrate.atlassian.net/login
112
113.. _transforms:
114
115Transformations
116===============
117
118The Modernizer is a collection of independent transforms which can be
119independently enabled. The transforms currently implemented are:
120
121* :doc:`LoopConvertTransform`
122
123* :doc:`UseNullptrTransform`
124
125* :doc:`UseAutoTransform`
126
127* :doc:`AddOverrideTransform`
128
129* :doc:`PassByValueTransform`
130
131* :doc:`ReplaceAutoPtrTransform`