File tree Expand file tree Collapse file tree 6 files changed +34
-9
lines changed Expand file tree Collapse file tree 6 files changed +34
-9
lines changed Original file line number Diff line number Diff line change @@ -210,9 +210,10 @@ void ConstCorrectnessCheck::check(const MatchFinder::MatchResult &Result) {
210210 registerScope (LocalScope, Result.Context );
211211 if (ScopesCache[LocalScope]->isPointeeMutated (Variable))
212212 return ;
213- auto Diag = diag (Variable->getBeginLoc (),
214- " variable %0 of type %1 can be declared 'const'" )
215- << Variable << VT;
213+ auto Diag =
214+ diag (Variable->getBeginLoc (),
215+ " pointee of variable %0 of type %1 can be declared 'const'" )
216+ << Variable << VT;
216217 if (IsNormalVariableInTemplate)
217218 TemplateDiagnosticsCache.insert (Variable->getBeginLoc ());
218219 if (!CanBeFixIt)
@@ -241,14 +242,16 @@ void ConstCorrectnessCheck::check(const MatchFinder::MatchResult &Result) {
241242 if (WarnPointersAsValues && !VT.isConstQualified ())
242243 CheckValue ();
243244 if (WarnPointersAsPointers) {
244- if (const auto *PT = dyn_cast<PointerType>(VT))
245+ if (const auto *PT = dyn_cast<PointerType>(VT)) {
245246 if (!PT->getPointeeType ().isConstQualified ())
246247 CheckPointee ();
247- if (const auto *AT = dyn_cast<ArrayType>(VT))
248+ }
249+ if (const auto *AT = dyn_cast<ArrayType>(VT)) {
248250 if (!AT->getElementType ().isConstQualified ()) {
249251 assert (AT->getElementType ()->isPointerType ());
250252 CheckPointee ();
251253 }
254+ }
252255 }
253256 return ;
254257 }
Original file line number Diff line number Diff line change 33// RUN: misc-const-correctness.AllowedTypes: '[Pp]ointer$;[Pp]tr$;[Rr]ef(erence)?$;qualified::Type;::fully::QualifiedType;ConstTemplate', \
44// RUN: misc-const-correctness.TransformPointersAsValues: true, \
55// RUN: misc-const-correctness.TransformReferences: true, \
6- // RUN: misc-const-correctness.WarnPointersAsValues: true } \
6+ // RUN: misc-const-correctness.WarnPointersAsValues: true, \
7+ // RUN: misc-const-correctness.WarnPointersAsPointers: false } \
78// RUN: }" -- -fno-delayed-template-parsing
89
910struct SmartPointer {
Original file line number Diff line number Diff line change 1+ // RUN: %check_clang_tidy %s misc-const-correctness %t \
2+ // RUN: -config='{CheckOptions: {\
3+ // RUN: misc-const-correctness.AnalyzeValues: false,\
4+ // RUN: misc-const-correctness.AnalyzeReferences: false,\
5+ // RUN: misc-const-correctness.AnalyzePointers: true,\
6+ // RUN: misc-const-correctness.WarnPointersAsValues: true,\
7+ // RUN: misc-const-correctness.WarnPointersAsPointers: true,\
8+ // RUN: misc-const-correctness.TransformPointersAsValues: true,\
9+ // RUN: misc-const-correctness.TransformPointersAsPointers: true\
10+ // RUN: }}' \
11+ // RUN: -- -fno-delayed-template-parsing
12+
13+ void pointee_to_const () {
14+ int a[] = {1 , 2 };
15+ int *p_local0 = &a[0 ];
16+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: pointee of variable 'p_local0' of type 'int *' can be declared 'const'
17+ // CHECK-MESSAGES: [[@LINE-2]]:3: warning: variable 'p_local0' of type 'int *' can be declared 'const'
18+ // CHECK-FIXES: int const*const p_local0 = &a[0];
19+ }
Original file line number Diff line number Diff line change 1313void pointee_to_const () {
1414 int a[] = {1 , 2 };
1515 int *p_local0 = &a[0 ];
16- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int *' can be declared 'const'
16+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: pointee of variable 'p_local0' of type 'int *' can be declared 'const'
1717 // CHECK-FIXES: int const*p_local0
1818 p_local0 = &a[1 ];
1919}
2020
2121void array_of_pointer_to_const () {
2222 int a[] = {1 , 2 };
2323 int *p_local0[1 ] = {&a[0 ]};
24- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int *[1]' can be declared 'const'
24+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: pointee of variable 'p_local0' of type 'int *[1]' can be declared 'const'
2525 // CHECK-FIXES: int const*p_local0[1]
2626 p_local0[0 ] = &a[1 ];
2727}
@@ -30,7 +30,7 @@ template<class T>
3030void template_fn () {
3131 T a[] = {1 , 2 };
3232 T *p_local0 = &a[0 ];
33- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'char *' can be declared 'const'
33+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: pointee of variable 'p_local0' of type 'char *' can be declared 'const'
3434 // CHECK-FIXES: T const*p_local0
3535 p_local0 = &a[1 ];
3636}
Original file line number Diff line number Diff line change 22// RUN: -config='{CheckOptions: \
33// RUN: {misc-const-correctness.AnalyzeValues: true,\
44// RUN: misc-const-correctness.WarnPointersAsValues: true,\
5+ // RUN: misc-const-correctness.WarnPointersAsPointers: false,\
56// RUN: misc-const-correctness.TransformPointersAsValues: true}}' \
67// RUN: -- -fno-delayed-template-parsing
78
Original file line number Diff line number Diff line change 22// RUN: -config='{CheckOptions: \
33// RUN: {misc-const-correctness.AnalyzeValues: true,\
44// RUN: misc-const-correctness.WarnPointersAsValues: true, \
5+ // RUN: misc-const-correctness.WarnPointersAsPointers: false, \
56// RUN: misc-const-correctness.TransformPointersAsValues: true}\
67// RUN: }' -- -fno-delayed-template-parsing
78
You can’t perform that action at this time.
0 commit comments