1// RUN: %check_clang_tidy -check-suffix=0-0 %s modernize-use-auto %t -- -config="{CheckOptions: {modernize-use-auto.RemoveStars: false, modernize-use-auto.MinTypeNameLength: 0}}" -- -frtti
2// RUN: %check_clang_tidy -check-suffix=0-8 %s modernize-use-auto %t -- -config="{CheckOptions: {modernize-use-auto.RemoveStars: false, modernize-use-auto.MinTypeNameLength: 8}}" -- -frtti
3// RUN: %check_clang_tidy -check-suffix=1-0 %s modernize-use-auto %t -- -config="{CheckOptions: {modernize-use-auto.RemoveStars: true, modernize-use-auto.MinTypeNameLength: 0}}" -- -frtti
4// RUN: %check_clang_tidy -check-suffix=1-8 %s modernize-use-auto %t -- -config="{CheckOptions: {modernize-use-auto.RemoveStars: true, modernize-use-auto.MinTypeNameLength: 8}}" -- -frtti
5
6template <class T> extern T foo();
7template <class T> struct P { explicit P(T t) : t_(t) {} T t_;};
8template <class T> P<T> *foo_ptr();
9template <class T> P<T> &foo_ref();
10
11int bar() {
12 {
13 // Lenth(long) = 4
14 long i = static_cast<long>(foo<long>());
15 // CHECK-FIXES-0-0: auto i = {{.*}}
16 // CHECK-FIXES-0-8: long i = {{.*}}
17 // CHECK-FIXES-1-0: auto i = {{.*}}
18 // CHECK-FIXES-1-8: long i = {{.*}}
19 const long ci = static_cast<long>(foo<const long>());
20 // CHECK-FIXES-0-0: auto ci = {{.*}}
21 // CHECK-FIXES-0-8: long ci = {{.*}}
22 // CHECK-FIXES-1-0: auto ci = {{.*}}
23 // CHECK-FIXES-1-8: long ci = {{.*}}
24 long *pi = static_cast<long *>(foo<long *>());
25 // CHECK-FIXES-0-0: auto *pi = {{.*}}
26 // CHECK-FIXES-0-8: long *pi = {{.*}}
27 // CHECK-FIXES-1-0: auto pi = {{.*}}
28 // CHECK-FIXES-1-8: long *pi = {{.*}}
29
30 // Length(long *) is still 5
31 long * pi2 = static_cast<long *>(foo<long *>());
32 // CHECK-FIXES-0-0: auto * pi2 = {{.*}}
33 // CHECK-FIXES-0-8: long * pi2 = {{.*}}
34 // CHECK-FIXES-1-0: auto pi2 = {{.*}}
35 // CHECK-FIXES-1-8: long * pi2 = {{.*}}
36
37 // Length(long **) = 6
38 long **ppi = static_cast<long **>(foo<long **>());
39 // CHECK-FIXES-0-0: auto **ppi = {{.*}}
40 // CHECK-FIXES-0-8: long **ppi = {{.*}}
41 // CHECK-FIXES-1-0: auto ppi = {{.*}}
42 // CHECK-FIXES-1-8: long **ppi = {{.*}}
43 }
44
45 {
46 // Lenth(long int) = 4 + 1 + 3 = 8
47 // Lenth(long int) is still 8
48 long int i = static_cast<long int>(foo<long int>());
49 // CHECK-FIXES-0-0: auto i = {{.*}}
50 // CHECK-FIXES-0-8: auto i = {{.*}}
51 // CHECK-FIXES-1-0: auto i = {{.*}}
52 // CHECK-FIXES-1-8: auto i = {{.*}}
53
54 long int *pi = static_cast<long int *>(foo<long int *>());
55 // CHECK-FIXES-0-0: auto *pi = {{.*}}
56 // CHECK-FIXES-0-8: auto *pi = {{.*}}
57 // CHECK-FIXES-1-0: auto pi = {{.*}}
58 // CHECK-FIXES-1-8: auto pi = {{.*}}
59 }
60
61 // Templates
62 {
63 // Length(P<long>) = 7
64 P<long>& i = static_cast<P<long>&>(foo_ref<long>());
65 // CHECK-FIXES-0-0: auto& i = {{.*}}
66 // CHECK-FIXES-0-8: P<long>& i = {{.*}}
67 // CHECK-FIXES-1-0: auto & i = {{.*}}
68 // CHECK-FIXES-1-8: P<long>& i = {{.*}}
69
70 // Length(P<long*>) = 8
71 P<long*>& pi = static_cast<P<long*> &>(foo_ref<long*>());
72 // CHECK-FIXES-0-0: auto& pi = {{.*}}
73 // CHECK-FIXES-0-8: auto& pi = {{.*}}
74 // CHECK-FIXES-1-0: auto & pi = {{.*}}
75 // CHECK-FIXES-1-8: auto & pi = {{.*}}
76
77 P<long>* pi2 = static_cast<P<long>*>(foo_ptr<long>());
78 // CHECK-FIXES-0-0: auto* pi2 = {{.*}}
79 // CHECK-FIXES-0-8: P<long>* pi2 = {{.*}}
80 // CHECK-FIXES-1-0: auto pi2 = {{.*}}
81 // CHECK-FIXES-1-8: auto pi2 = {{.*}}
82 }
83
84 return 1;
85}
86

source code of clang-tools-extra/test/clang-tidy/checkers/modernize/use-auto-min-type-name-length.cpp