blob: ea7e3140783da2ae82f62345b56d6b4b6ea472da [file] [log] [blame]
Edwin Vane8ef7fa12013-04-09 20:49:49 +00001.. index:: Add-Override Transform
2
3======================
4Add-Override Transform
5======================
6
7The Add-Override Transform adds the ``override`` specifier to member
8functions that override a virtual function in a base class and that
9don't already have the specifier. The transform is enabled with the
Chandler Carruthd9063c42013-09-04 17:35:07 +000010:option:`-add-override` option of :program:`clang-modernize`.
Edwin Vane8ef7fa12013-04-09 20:49:49 +000011For 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 Vane573ec4f2013-06-06 14:30:14 +000028Using Expands-to-Override Macros
Edwin Vane8d286462013-06-14 15:14:20 +000029================================
Edwin Vane573ec4f2013-06-06 14:30:14 +000030
Craig Toppere67972c2014-03-02 10:24:34 +000031Like LLVM's ``LLVM_OVERRIDE``, several projects have macros that conditionally
Edwin Vane573ec4f2013-06-06 14:30:14 +000032expand to the ``override`` keyword when compiling with C++11 features enabled.
33To maintain compatibility with non-C++11 builds, the Add-Override Transform
34supports detection and use of these macros instead of using the ``override``
35keyword directly. Specify ``-override-macros`` on the command line to the
Chandler Carruthd9063c42013-09-04 17:35:07 +000036Modernizer to enable this behavior.
Edwin Vane573ec4f2013-06-06 14:30:14 +000037
Edwin Vane8ef7fa12013-04-09 20:49:49 +000038
39Known Limitations
Edwin Vane8d286462013-06-14 15:14:20 +000040=================
Edwin Vaneba6a0962013-05-14 17:34:12 +000041* 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 Vane8ef7fa12013-04-09 20:49:49 +000044
45.. code-block:: c++
46
47 class B : public A {
48 public:
Edwin Vaneba6a0962013-05-14 17:34:12 +000049 virtual void h() const = 0;
Edwin Vane8ef7fa12013-04-09 20:49:49 +000050
Edwin Vaneba6a0962013-05-14 17:34:12 +000051 // The declaration of h is NOT transformed to
52 virtual void h() const override = 0;
Edwin Vane8ef7fa12013-04-09 20:49:49 +000053 };
54