Edwin Vane | 8ef7fa1 | 2013-04-09 20:49:49 +0000 | [diff] [blame] | 1 | .. index:: Add-Override Transform |
| 2 | |
| 3 | ====================== |
| 4 | Add-Override Transform |
| 5 | ====================== |
| 6 | |
| 7 | The Add-Override Transform adds the ``override`` specifier to member |
| 8 | functions that override a virtual function in a base class and that |
| 9 | don't already have the specifier. The transform is enabled with the |
Chandler Carruth | d9063c4 | 2013-09-04 17:35:07 +0000 | [diff] [blame] | 10 | :option:`-add-override` option of :program:`clang-modernize`. |
Edwin Vane | 8ef7fa1 | 2013-04-09 20:49:49 +0000 | [diff] [blame] | 11 | For example: |
| 12 | |
| 13 | .. code-block:: c++ |
| 14 | |
| 15 | class A { |
| 16 | public: |
| 17 | virtual void h() const; |
| 18 | }; |
| 19 | |
| 20 | class B : public A { |
| 21 | public: |
| 22 | void h() const; |
| 23 | |
| 24 | // The declaration of h is transformed to |
| 25 | void h() const override; |
| 26 | }; |
| 27 | |
Edwin Vane | 573ec4f | 2013-06-06 14:30:14 +0000 | [diff] [blame] | 28 | Using Expands-to-Override Macros |
Edwin Vane | 8d28646 | 2013-06-14 15:14:20 +0000 | [diff] [blame] | 29 | ================================ |
Edwin Vane | 573ec4f | 2013-06-06 14:30:14 +0000 | [diff] [blame] | 30 | |
Craig Topper | e67972c | 2014-03-02 10:24:34 +0000 | [diff] [blame] | 31 | Like LLVM's ``LLVM_OVERRIDE``, several projects have macros that conditionally |
Edwin Vane | 573ec4f | 2013-06-06 14:30:14 +0000 | [diff] [blame] | 32 | expand to the ``override`` keyword when compiling with C++11 features enabled. |
| 33 | To maintain compatibility with non-C++11 builds, the Add-Override Transform |
| 34 | supports detection and use of these macros instead of using the ``override`` |
| 35 | keyword directly. Specify ``-override-macros`` on the command line to the |
Chandler Carruth | d9063c4 | 2013-09-04 17:35:07 +0000 | [diff] [blame] | 36 | Modernizer to enable this behavior. |
Edwin Vane | 573ec4f | 2013-06-06 14:30:14 +0000 | [diff] [blame] | 37 | |
Edwin Vane | 8ef7fa1 | 2013-04-09 20:49:49 +0000 | [diff] [blame] | 38 | |
| 39 | Known Limitations |
Edwin Vane | 8d28646 | 2013-06-14 15:14:20 +0000 | [diff] [blame] | 40 | ================= |
Edwin Vane | ba6a096 | 2013-05-14 17:34:12 +0000 | [diff] [blame] | 41 | * This transform will not insert the override keyword if a method is |
| 42 | pure. At the moment it's not possible to track down the pure |
| 43 | specifier location. |
Edwin Vane | 8ef7fa1 | 2013-04-09 20:49:49 +0000 | [diff] [blame] | 44 | |
| 45 | .. code-block:: c++ |
| 46 | |
| 47 | class B : public A { |
| 48 | public: |
Edwin Vane | ba6a096 | 2013-05-14 17:34:12 +0000 | [diff] [blame] | 49 | virtual void h() const = 0; |
Edwin Vane | 8ef7fa1 | 2013-04-09 20:49:49 +0000 | [diff] [blame] | 50 | |
Edwin Vane | ba6a096 | 2013-05-14 17:34:12 +0000 | [diff] [blame] | 51 | // The declaration of h is NOT transformed to |
| 52 | virtual void h() const override = 0; |
Edwin Vane | 8ef7fa1 | 2013-04-09 20:49:49 +0000 | [diff] [blame] | 53 | }; |
| 54 | |