File: qualified-auto.rst

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (84 lines) | stat: -rw-r--r-- 2,195 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
.. title:: clang-tidy - readability-qualified-auto

readability-qualified-auto
==========================

Adds pointer qualifications to ``auto``-typed variables that are deduced to
pointers.

`LLVM Coding Standards <https://llvm.org/docs/CodingStandards.html#beware-unnecessary-copies-with-auto>`_
advises to make it obvious if a ``auto`` typed variable is a pointer. This
check will transform ``auto`` to ``auto *`` when the type is deduced to be a
pointer.

.. code-block:: c++

  for (auto Data : MutatablePtrContainer) {
    change(*Data);
  }
  for (auto Data : ConstantPtrContainer) {
    observe(*Data);
  }

Would be transformed into:

.. code-block:: c++

  for (auto *Data : MutatablePtrContainer) {
    change(*Data);
  }
  for (const auto *Data : ConstantPtrContainer) {
    observe(*Data);
  }

Note ``const`` ``volatile`` qualified types will retain their ``const`` and
``volatile`` qualifiers. Pointers to pointers will not be fully qualified.

.. code-block:: c++

  const auto Foo = cast<int *>(Baz1);
  const auto Bar = cast<const int *>(Baz2);
  volatile auto FooBar = cast<int *>(Baz3);
  auto BarFoo = cast<int **>(Baz4);

Would be transformed into:

.. code-block:: c++

  auto *const Foo = cast<int *>(Baz1);
  const auto *const Bar = cast<const int *>(Baz2);
  auto *volatile FooBar = cast<int *>(Baz3);
  auto *BarFoo = cast<int **>(Baz4);

Options
-------

.. option:: AddConstToQualified

   When set to `true` the check will add const qualifiers variables defined as
   ``auto *`` or ``auto &`` when applicable.
   Default value is `true`.

.. code-block:: c++

   auto Foo1 = cast<const int *>(Bar1);
   auto *Foo2 = cast<const int *>(Bar2);
   auto &Foo3 = cast<const int &>(Bar3);

If AddConstToQualified is set to `false`, it will be transformed into:

.. code-block:: c++

   const auto *Foo1 = cast<const int *>(Bar1);
   auto *Foo2 = cast<const int *>(Bar2);
   auto &Foo3 = cast<const int &>(Bar3);

Otherwise it will be transformed into:

.. code-block:: c++

   const auto *Foo1 = cast<const int *>(Bar1);
   const auto *Foo2 = cast<const int *>(Bar2);
   const auto &Foo3 = cast<const int &>(Bar3);

Note in the LLVM alias, the default value is `false`.