1 .. title:: clang-tidy - readability-qualified-auto
3 readability-qualified-auto
4 ==========================
6 Adds pointer qualifications to ``auto``-typed variables that are deduced to
9 `LLVM Coding Standards <https://llvm.org/docs/CodingStandards.html#beware-unnecessary-copies-with-auto>`_
10 advises to make it obvious if a ``auto`` typed variable is a pointer. This
11 check will transform ``auto`` to ``auto *`` when the type is deduced to be a
16 for (auto Data : MutatablePtrContainer) {
19 for (auto Data : ConstantPtrContainer) {
23 Would be transformed into:
27 for (auto *Data : MutatablePtrContainer) {
30 for (const auto *Data : ConstantPtrContainer) {
34 Note ``const`` ``volatile`` qualified types will retain their ``const`` and
35 ``volatile`` qualifiers. Pointers to pointers will not be fully qualified.
39 const auto Foo = cast<int *>(Baz1);
40 const auto Bar = cast<const int *>(Baz2);
41 volatile auto FooBar = cast<int *>(Baz3);
42 auto BarFoo = cast<int **>(Baz4);
44 Would be transformed into:
48 auto *const Foo = cast<int *>(Baz1);
49 const auto *const Bar = cast<const int *>(Baz2);
50 auto *volatile FooBar = cast<int *>(Baz3);
51 auto *BarFoo = cast<int **>(Baz4);
56 .. option:: AddConstToQualified
58 When set to `true` the check will add const qualifiers variables defined as
59 ``auto *`` or ``auto &`` when applicable.
60 Default value is `true`.
64 auto Foo1 = cast<const int *>(Bar1);
65 auto *Foo2 = cast<const int *>(Bar2);
66 auto &Foo3 = cast<const int &>(Bar3);
68 If AddConstToQualified is set to `false`, it will be transformed into:
72 const auto *Foo1 = cast<const int *>(Bar1);
73 auto *Foo2 = cast<const int *>(Bar2);
74 auto &Foo3 = cast<const int &>(Bar3);
76 Otherwise it will be transformed into:
80 const auto *Foo1 = cast<const int *>(Bar1);
81 const auto *Foo2 = cast<const int *>(Bar2);
82 const auto &Foo3 = cast<const int &>(Bar3);
84 Note in the LLVM alias, the default value is `false`.