blob: bbcba93211cd3af29fb022379cd0bb77c01eccc0 [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
63Now with compiler arguments, the Modernizer can be applied to source. Sources
64are transformed in place and changes are only written to disk if compilation
65errors aren't caused by the transforms. Each transform will re-parse the output
66from the previous transform. The output from the last transform is not checked
67unless ``-final-syntax-check`` is enabled.
68
69
70.. _Ninja: http://martine.github.io/ninja/
71.. _Bear: https://github.com/rizsotto/Bear
72.. _compilation database: http://clang.llvm.org/docs/JSONCompilationDatabase.html
73.. _Getting Started with the LLVM System: http://llvm.org/docs/GettingStarted.html
74.. _Building LLVM with CMake: http://llvm.org/docs/CMake.html
75.. _Clang Tools Documentation: http://clang.llvm.org/docs/ClangTools.html
76
77Getting Involved
78================
79
80If you find a bug
81
82.. raw:: html
83
84 <input type="button" id="logbug" value="Log a Bug!" />
85 <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>
86 <script type="text/javascript">window.ATL_JQ_PAGE_PROPS = {
87 "triggerFunction": function(showCollectorDialog) {
88 //Requries that jQuery is available!
89 jQuery("#logbug").click(function(e) {
90 e.preventDefault();
91 showCollectorDialog();
92 });
93 }};
94 </script>
95
96Bugs and feature development of the Modernizer are tracked at
97http://cpp11-migrate.atlassian.net. If you want to get involved the front page
98shows a list of outstanding issues or you can browse around the project to get
99familiar. To take on issues or contribute feature requests and/or bug reports
100you need to sign up for an account from the `log in page`_. An account also
101lets you sign up for notifications on issues or vote for unassigned issues to
102be completed.
103
104.. _log in page: https://cpp11-migrate.atlassian.net/login
105
106.. _transforms:
107
108Transformations
109===============
110
111The Modernizer is a collection of independent transforms which can be
112independently enabled. The transforms currently implemented are:
113
114* :doc:`LoopConvertTransform`
115
116* :doc:`UseNullptrTransform`
117
118* :doc:`UseAutoTransform`
119
120* :doc:`AddOverrideTransform`
121
122* :doc:`PassByValueTransform`
123
124* :doc:`ReplaceAutoPtrTransform`