[PATCH] D54395: [clang-tidy] implement utility-function to add 'const' to variables

Jonas Toth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 5 05:12:03 PST 2018


JonasToth marked 2 inline comments as done.
JonasToth added inline comments.


================
Comment at: clang-tidy/utils/FixItHintUtils.cpp:35
+static bool isValueType(QualType QT) { return isValueType(QT.getTypePtr()); }
+static bool isArrayType(QualType QT) { return isa<ArrayType>(QT.getTypePtr()); }
+static bool isReferenceType(QualType QT) {
----------------
aaron.ballman wrote:
> This file is replicating a bunch of functionality that exists on the `Type*` already. Why do this rather than have the caller do `QT->isArrayType()` and skip this function entirely? (Same exists elsewhere here.)
I had the issue that typedefs are resolved, but shouldn't. If I am not mistaken `QT->isArrayType()` would go to the canconical type.

```
using MyPtr = int*;
MyPtr foo = nullptr;
```
Is treated wrong in that case.


================
Comment at: clang-tidy/utils/FixItHintUtils.h:47
+/// \c SourceLocation it is not returned.
+Optional<FixItHint> changeVarDeclToConst(const VarDecl &Var,
+                                         ConstTarget CT = ConstTarget::Pointee,
----------------
aaron.ballman wrote:
> I feel like this could be trivially generalized to any type qualifier, not just `const`. How would you feel about renaming this to: `addQualifierToVarDecl()` and adding a parameter of type `DeclSpec::TQ` to specify which qualifier to add?
Yes, sounds good.


Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54395/new/

https://reviews.llvm.org/D54395





More information about the cfe-commits mailing list