summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
diff options
context:
space:
mode:
authorJonas Toth <development@jonas-toth.eu>2020-01-03 20:36:49 +0100
committerJonas Toth <development@jonas-toth.eu>2020-01-03 20:37:47 +0100
commitcf48101200ee192dd82e6ed0512ae42e7b3162a9 (patch)
treee389873c7d814c730d412eb935cf22d1eb0407eb /clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
parentaaaf6c456093101aea50be740ce1598174e6e5aa (diff)
downloadbcm5719-llvm-cf48101200ee192dd82e6ed0512ae42e7b3162a9.tar.gz
bcm5719-llvm-cf48101200ee192dd82e6ed0512ae42e7b3162a9.zip
[clang-tidy] implement utility-function to add 'const' to variables
Summary: This patch extends the already existing facility to add 'const' to variables to be more flexible and correct. The previous version did not consider pointers as value AND pointee. For future automatic introduction for const-correctness this shortcoming needs to be fixed. It always allows configuration where the 'const' token is inserted, either on the left side (if possible) or the right side. It adds many unit-tests to the utility-function that did not exist before, as the function was implicitly tested through clang-tidy checks. These tests were not changed, as the API is still compatible. Reviewers: aaron.ballman, hokein, alexfh, shuaiwang, lebedev.ri Reviewed By: aaron.ballman Subscribers: jdoerfert, mgorny, xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D54395
Diffstat (limited to 'clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
index 7e36b374fba..c9ae37d036c 100644
--- a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
+++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
@@ -12,6 +12,7 @@
#include "../utils/FixItHintUtils.h"
#include "../utils/Matchers.h"
#include "../utils/OptionsUtils.h"
+#include "clang/Basic/Diagnostic.h"
namespace clang {
namespace tidy {
@@ -21,8 +22,11 @@ namespace {
void recordFixes(const VarDecl &Var, ASTContext &Context,
DiagnosticBuilder &Diagnostic) {
Diagnostic << utils::fixit::changeVarDeclToReference(Var, Context);
- if (!Var.getType().isLocalConstQualified())
- Diagnostic << utils::fixit::changeVarDeclToConst(Var);
+ if (!Var.getType().isLocalConstQualified()) {
+ if (llvm::Optional<FixItHint> Fix = utils::fixit::addQualifierToVarDecl(
+ Var, Context, DeclSpec::TQ::TQ_const))
+ Diagnostic << *Fix;
+ }
}
} // namespace
OpenPOWER on IntegriCloud