1// RUN: %check_clang_tidy %s readability-redundant-access-specifiers %t
2
3class FooPublic {
4public:
5 int a;
6public: // 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;
11private:
12 int c;
13};
14
15struct StructPublic {
16public:
17 int a;
18public: // 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;
23private:
24 int c;
25};
26
27union UnionPublic {
28public:
29 int a;
30public: // 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;
35private:
36 int c;
37};
38
39class FooProtected {
40protected:
41 int a;
42protected: // 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;
47private:
48 int c;
49};
50
51class FooPrivate {
52private:
53 int a;
54private: // 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;
59public:
60 int c;
61};
62
63class FooMacro {
64private:
65 int a;
66#if defined(ZZ)
67 public:
68 int b;
69#endif
70private: // 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;
75protected:
76 int d;
77public:
78 int e;
79};
80
81class Valid {
82private:
83 int a;
84public:
85 int b;
86private:
87 int c;
88protected:
89 int d;
90public:
91 int e;
92};
93
94class ValidInnerClass {
95public:
96 int a;
97
98 class Inner {
99 public:
100 int b;
101 };
102};
103
104#define MIXIN private: int b;
105
106class ValidMacro {
107private:
108 int a;
109MIXIN
110private:
111 int c;
112protected:
113 int d;
114public:
115 int e;
116};
117

source code of clang-tools-extra/test/clang-tidy/checkers/readability/redundant-access-specifiers.cpp