Adds an option called AddConstToQualified to readability-qualified-auto to toggle adding const to the auto typed pointers and references. By default its enabled but in the LLVM module its disabled.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Time | Test | |
---|---|---|
380 ms | Clang.CodeGenOpenCL::Unknown Unit Message ("") |
Event Timeline
clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp | ||
---|---|---|
209 | If a variables is typed as auto x = cast<const int*>(y), should the behaviour be const auto*x = ... even if AddConstQualifier is turned off. Thereby making the AddConstQualifier check only there to ensure that variables already typed as auto * and auto & get const qualifier if necessary |
Unit tests: pass. 62260 tests passed, 0 failed and 827 were skipped.
clang-tidy: pass.
clang-format: pass.
Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml
Pre-merge checks is in beta. Report issue. Please join beta or enable it for your project.
clang-tools-extra/docs/clang-tidy/checks/readability-qualified-auto.rst | ||
---|---|---|
50 | Is it worth adding an example of a double pointer? auto BarN = cast<int **>(FooN); Does that become auto* or auto** (and why)? My wild guess is that it becomes auto* (and because nobody cares about double pointers), but I could be wrong. | |
73 | s/Will be/will be/ In the preceding section you give an example with volatile. How about here? What happens with auto *volatile Foo3 = cast<const int *>(Bar3); auto *Foo4 = cast<volatile int *>(Bar4); Do they become const auto *volatile Foo3 = cast<const int *>(Bar3); volatile auto *Foo4 = cast<volatile int *>(Bar4); as I would expect? | |
78 | How does this option interact with const int range[10]; for (auto&& elt : range) Does it (incorrectly IMHO) make that const auto&& elt, or (correctly IMHO) const auto& elt, or (also correctly) leave it as [auto&&, which Always Works](https://quuxplusone.github.io/blog/2018/12/15/autorefref-always-works/)? | |
clang-tools-extra/test/clang-tidy/checkers/llvm-qualified-auto.cpp | ||
21 | It is worth adding one test case to show that the LLVM alias does not gratuitously remove const from declarations: auto const &ExtendedConstPtr = getCIntPtr(); // becomes auto *const &ExtendedConstPtr = getCIntPtr(); |
clang-tools-extra/docs/clang-tidy/checks/readability-qualified-auto.rst | ||
---|---|---|
50 | Double pointers are just resolved to auto *. | |
73 | Good spot on the Will/be/get/(whatever I tried to type) the check keeps local volatile qualifiers, but it wont add volatile pointer (or ref) qualifiers even if the deduced type is a volatile pointer. In the first patch we came to the conclusion not to add them. | |
78 | RValueReferences are ignored | |
clang-tools-extra/test/clang-tidy/checkers/llvm-qualified-auto.cpp | ||
21 | That test case looks malformed as the function getCIntPtr() doesn't return a reference. as for removing const etc those cases are all in the readability-qualified-auto.cpp test file |
clang-tools-extra/docs/clang-tidy/checks/readability-qualified-auto.rst | ||
---|---|---|
50 | They resolve to auto * today but I could see a real argument that they should resolve to auto ** instead based on the same logic of: don't make the reader infer pointer/references and qualifiers. |
clang-tools-extra/docs/clang-tidy/checks/readability-qualified-auto.rst | ||
---|---|---|
50 | One change per patch... |
- Always add const to auto typed variable.
This update adds const to variables just typed with auto, but wont enforce checking on auto * or auto & unless AddConstToQualified is set.
Unit tests: fail. 62275 tests passed, 1 failed and 827 were skipped.
failed: Clang.CodeGenOpenCL/amdgpu-features.cl
clang-tidy: pass.
clang-format: pass.
Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml
Pre-merge checks is in beta. Report issue. Please join beta or enable it for your project.
clang-tools-extra/docs/clang-tidy/checks/readability-qualified-auto.rst | ||
---|---|---|
50 | I wasn't suggesting a change to this patch, I was checking to see if there's sentiment that we missed this case in the first place. Sorry for not making that more clear. |
- Streamline fixits
- Add documentation about double pointers, maybe a follow up patch to fix
Unit tests: fail. 62275 tests passed, 1 failed and 827 were skipped.
failed: Clang.CodeGenOpenCL/amdgpu-features.cl
clang-tidy: pass.
clang-format: fail. Please format your changes with clang-format by running git-clang-format HEAD^ or applying this patch.
Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml
Pre-merge checks is in beta. Report issue. Please join beta or enable it for your project.
Unit tests: pass. 62383 tests passed, 0 failed and 839 were skipped.
clang-tidy: pass.
clang-format: pass.
Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml
Pre-merge checks is in beta. Report issue. Please join beta or enable it for your project.
LGTM!
clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp | ||
---|---|---|
276 | Not specific to this patch, so feel free to address in another one -- I think you should be passing Var instead of Var->getName() -- the diagnostics engine does magic to format the name properly for any NamedDecl, including proper quoting. (Similar applies elsewhere.) |
clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp | ||
---|---|---|
276 | I couldn't do that as it actually messes the quotes up: 'auto &'TdNakedCRef'' |
clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp | ||
---|---|---|
276 | Ah, good point. I was thinking about variable template specializations, but I'm not certain there's an actual issue with them -- it seems like we really want just the base identifier here. |
If a variables is typed as auto x = cast<const int*>(y), should the behaviour be const auto*x = ... even if AddConstQualifier is turned off. Thereby making the AddConstQualifier check only there to ensure that variables already typed as auto * and auto & get const qualifier if necessary