readability-qualified-auto¶
Adds pointer and const
qualifications to auto
-typed variables that are deduced
to pointers and const
pointers.
LLVM Coding Standards advises to
make it obvious if a auto
typed variable is a pointer, constant pointer or
constant reference. This check will transform auto
to auto *
when the
type is deduced to be a pointer, as well as adding const
when applicable to
auto
pointers or references
for (auto &Data : MutatableContainer) {
change(Data);
}
for (auto &Data : ConstantContainer) {
observe(Data);
}
for (auto Data : MutatablePtrContainer) {
change(*Data);
}
for (auto Data : ConstantPtrContainer) {
observe(*Data);
}
Would be transformed into:
for (auto &Data : MutatableContainer) {
change(Data);
}
for (const auto &Data : ConstantContainer) {
observe(Data);
}
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.
const auto Foo = cast<int *>(Baz1);
const auto Bar = cast<const int *>(Baz2);
volatile auto FooBar = cast<int*>(Baz3);
Would be transformed into:
auto *const Foo = cast<int *>(Baz1);
const auto *const Bar = cast<const int *>(Baz2);
auto *volatile FooBar = cast<int*>(Baz3);
This check helps to enforce this LLVM Coding Standards recommendation.