1 | // RUN: %check_clang_tidy %s readability-redundant-access-specifiers %t |
2 | |
3 | class FooPublic { |
4 | public: |
5 | int a; |
6 | public: // comment-0 |
7 | // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers] |
8 | // CHECK-MESSAGES: :[[@LINE-4]]:1: note: previously declared here |
9 | // CHECK-FIXES: {{^}}// comment-0{{$}} |
10 | int b; |
11 | private: |
12 | int c; |
13 | }; |
14 | |
15 | struct StructPublic { |
16 | public: |
17 | int a; |
18 | public: // comment-1 |
19 | // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers] |
20 | // CHECK-MESSAGES: :[[@LINE-4]]:1: note: previously declared here |
21 | // CHECK-FIXES: {{^}}// comment-1{{$}} |
22 | int b; |
23 | private: |
24 | int c; |
25 | }; |
26 | |
27 | union UnionPublic { |
28 | public: |
29 | int a; |
30 | public: // comment-2 |
31 | // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers] |
32 | // CHECK-MESSAGES: :[[@LINE-4]]:1: note: previously declared here |
33 | // CHECK-FIXES: {{^}}// comment-2{{$}} |
34 | int b; |
35 | private: |
36 | int c; |
37 | }; |
38 | |
39 | class FooProtected { |
40 | protected: |
41 | int a; |
42 | protected: // comment-3 |
43 | // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers] |
44 | // CHECK-MESSAGES: :[[@LINE-4]]:1: note: previously declared here |
45 | // CHECK-FIXES: {{^}}// comment-3{{$}} |
46 | int b; |
47 | private: |
48 | int c; |
49 | }; |
50 | |
51 | class FooPrivate { |
52 | private: |
53 | int a; |
54 | private: // comment-4 |
55 | // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers] |
56 | // CHECK-MESSAGES: :[[@LINE-4]]:1: note: previously declared here |
57 | // CHECK-FIXES: {{^}}// comment-4{{$}} |
58 | int b; |
59 | public: |
60 | int c; |
61 | }; |
62 | |
63 | class FooMacro { |
64 | private: |
65 | int a; |
66 | #if defined(ZZ) |
67 | public: |
68 | int b; |
69 | #endif |
70 | private: // comment-5 |
71 | // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers] |
72 | // CHECK-MESSAGES: :[[@LINE-8]]:1: note: previously declared here |
73 | // CHECK-FIXES: {{^}}// comment-5{{$}} |
74 | int c; |
75 | protected: |
76 | int d; |
77 | public: |
78 | int e; |
79 | }; |
80 | |
81 | class Valid { |
82 | private: |
83 | int a; |
84 | public: |
85 | int b; |
86 | private: |
87 | int c; |
88 | protected: |
89 | int d; |
90 | public: |
91 | int e; |
92 | }; |
93 | |
94 | class ValidInnerClass { |
95 | public: |
96 | int a; |
97 | |
98 | class Inner { |
99 | public: |
100 | int b; |
101 | }; |
102 | }; |
103 | |
104 | #define MIXIN private: int b; |
105 | |
106 | class ValidMacro { |
107 | private: |
108 | int a; |
109 | MIXIN |
110 | private: |
111 | int c; |
112 | protected: |
113 | int d; |
114 | public: |
115 | int e; |
116 | }; |
117 | |