1// RUN: %check_clang_tidy --match-partial-fixes %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: false,\
7// RUN: misc-const-correctness.WarnPointersAsPointers: true,\
8// RUN: misc-const-correctness.TransformPointersAsValues: false,\
9// RUN: misc-const-correctness.TransformPointersAsPointers: true\
10// RUN: }}' \
11// RUN: -- -fno-delayed-template-parsing
12
13void 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-FIXES: int const*p_local0
18 p_local0 = &a[1];
19}
20
21void array_of_pointer_to_const() {
22 int a[] = {1, 2};
23 int *p_local0[1] = {&a[0]};
24 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: pointee of variable 'p_local0' of type 'int *[1]' can be declared 'const'
25 // CHECK-FIXES: int const*p_local0[1]
26 p_local0[0] = &a[1];
27}
28
29template<class T>
30void template_fn() {
31 T a[] = {1, 2};
32 T *p_local0 = &a[0];
33 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: pointee of variable 'p_local0' of type 'char *' can be declared 'const'
34 // CHECK-FIXES: T const*p_local0
35 p_local0 = &a[1];
36}
37
38void instantiate() {
39 template_fn<char>();
40 template_fn<int>();
41 template_fn<char const>();
42}
43
44using const_int = int const;
45void ignore_const_alias() {
46 const_int a[] = {1, 2};
47 const_int *p_local0 = &a[0];
48 p_local0 = &a[1];
49}
50
51

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp