Chandler Carruth | d9063c4 | 2013-09-04 17:35:07 +0000 | [diff] [blame] | 1 | .. index:: clang-modernize |
| 2 | |
| 3 | ================================== |
| 4 | Clang 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 Vane | 5a816f0 | 2013-09-06 19:27:19 +0000 | [diff] [blame^] | 17 | cpp11-migrate |
| 18 | MigratorUsage |
Chandler Carruth | d9063c4 | 2013-09-04 17:35:07 +0000 | [diff] [blame] | 19 | |
| 20 | :program:`clang-modernize` is a standalone tool used to automatically convert |
| 21 | C++ code written against old standards to use features of the newest C++ |
| 22 | standard where appropriate. |
| 23 | |
| 24 | Getting Started |
| 25 | =============== |
| 26 | |
| 27 | To build from source: |
| 28 | |
| 29 | 1. 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 | |
| 33 | 2. `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 | |
| 41 | Before continuing, take a look at :doc:`ModernizerUsage` to see how to invoke |
| 42 | the Modernizer. |
| 43 | |
| 44 | Before running the Modernizer on code you'll need the arguments you'd normally |
| 45 | pass to the compiler. If you're migrating a single file with few compiler |
| 46 | arguments, it might be easier to pass the compiler args on the command line |
| 47 | after ``--``. If you don't have any compiler arguments then ``--`` is not needed. |
| 48 | If you're working with multiple files or even a single file with many compiler |
| 49 | args, it's probably best to use a *compilation database*. |
| 50 | |
| 51 | A `compilation database`_ contains the command-line arguments for multiple |
| 52 | files. If the code you want to transform can be built with CMake, you can |
| 53 | generate this database easily by running CMake with the |
| 54 | ``-DCMAKE_EXPORT_COMPILE_COMMANDS`` option. The Ninja_ build system, since |
| 55 | v1.2, can create this file too using the *compdb* tool: ``ninja -t compdb``. If |
| 56 | you're not already using either of these tools or cannot easily make use of |
| 57 | them you might consider looking into Bear_. |
| 58 | |
| 59 | In addition to the compiler arguments you usually build your code with, you must |
| 60 | provide the option for enabling C++11 features. For clang and versions of gcc |
| 61 | ≥ v4.8 this is ``-std=c++11``. |
| 62 | |
| 63 | Now with compiler arguments, the Modernizer can be applied to source. Sources |
| 64 | are transformed in place and changes are only written to disk if compilation |
| 65 | errors aren't caused by the transforms. Each transform will re-parse the output |
| 66 | from the previous transform. The output from the last transform is not checked |
| 67 | unless ``-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 | |
| 77 | Getting Involved |
| 78 | ================ |
| 79 | |
| 80 | If 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 | |
| 96 | Bugs and feature development of the Modernizer are tracked at |
| 97 | http://cpp11-migrate.atlassian.net. If you want to get involved the front page |
| 98 | shows a list of outstanding issues or you can browse around the project to get |
| 99 | familiar. To take on issues or contribute feature requests and/or bug reports |
| 100 | you need to sign up for an account from the `log in page`_. An account also |
| 101 | lets you sign up for notifications on issues or vote for unassigned issues to |
| 102 | be completed. |
| 103 | |
| 104 | .. _log in page: https://cpp11-migrate.atlassian.net/login |
| 105 | |
| 106 | .. _transforms: |
| 107 | |
| 108 | Transformations |
| 109 | =============== |
| 110 | |
| 111 | The Modernizer is a collection of independent transforms which can be |
| 112 | independently 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` |