Skip to content

Commit 0227052

Browse files
committed
improve option description and remove redundant code from tests
1 parent 2ae8a9a commit 0227052

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-goto.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ Options
5757

5858
.. option:: IgnoreMacros
5959

60-
If set to `true`, the check will not warn if ``goto`` statement is placed
61-
inside a macro. Default is `false`.
60+
If set to `true`, the check will not warn if a ``goto`` statement is
61+
expanded from a macro. Default is `false`.

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-goto.cpp

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
// RUN: %check_clang_tidy %s cppcoreguidelines-avoid-goto %t
2-
// RUN: %check_clang_tidy -check-suffix=MACRO %s cppcoreguidelines-avoid-goto %t -- -config="{CheckOptions: { cppcoreguidelines-avoid-goto.IgnoreMacros: true }}"
1+
// RUN: %check_clang_tidy -check-suffix=,MACRO %s cppcoreguidelines-avoid-goto %t
2+
// RUN: %check_clang_tidy %s cppcoreguidelines-avoid-goto %t -- -config="{CheckOptions: { cppcoreguidelines-avoid-goto.IgnoreMacros: true }}"
33

44
void noop() {}
55

66
int main() {
77
noop();
88
goto jump_to_me;
99
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
10-
// CHECK-MESSAGES: [[@LINE+5]]:1: note: label defined here
11-
// CHECK-MESSAGES-MACRO: [[@LINE-3]]:3: warning: avoid using 'goto' for flow control
12-
// CHECK-MESSAGES-MACRO: [[@LINE+3]]:1: note: label defined here
10+
// CHECK-MESSAGES: [[@LINE+3]]:1: note: label defined here
1311
noop();
1412

1513
jump_to_me:;
@@ -19,16 +17,12 @@ jump_backwards:;
1917
goto jump_backwards;
2018
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
2119
// CHECK-MESSAGES: [[@LINE-4]]:1: note: label defined here
22-
// CHECK-MESSAGES-MACRO: [[@LINE-3]]:3: warning: avoid using 'goto' for flow control
23-
// CHECK-MESSAGES-MACRO: [[@LINE-6]]:1: note: label defined here
2420

2521
goto jump_in_line;
2622
;
2723
jump_in_line:;
2824
// CHECK-MESSAGES: [[@LINE-3]]:3: warning: avoid using 'goto' for flow control
2925
// CHECK-MESSAGES: [[@LINE-2]]:1: note: label defined here
30-
// CHECK-MESSAGES-MACRO: [[@LINE-5]]:3: warning: avoid using 'goto' for flow control
31-
// CHECK-MESSAGES-MACRO: [[@LINE-4]]:1: note: label defined here
3226

3327
// Test the GNU extension https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
3428
some_label:;
@@ -141,8 +135,6 @@ void jump_out_backwards() {
141135
goto before_the_loop;
142136
// CHECK-MESSAGES: [[@LINE-1]]:9: warning: avoid using 'goto' for flow control
143137
// CHECK-MESSAGES: [[@LINE-8]]:1: note: label defined here
144-
// CHECK-MESSAGES-MACRO: [[@LINE-3]]:9: warning: avoid using 'goto' for flow control
145-
// CHECK-MESSAGES-MACRO: [[@LINE-10]]:1: note: label defined here
146138
}
147139
}
148140
}
@@ -158,26 +150,24 @@ jump_to_me:; \
158150

159151
void inside_macro_all() {
160152
macro_goto_code
161-
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
162-
// CHECK-MESSAGES: [[@LINE-2]]:3: note: label defined here
153+
// CHECK-MESSAGES-MACRO: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
154+
// CHECK-MESSAGES-MACRO: [[@LINE-2]]:3: note: label defined here
163155
}
164156

165157
void inside_macro_label() {
166158
noop();
167159
goto jump_to_me;
168160
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
169-
// CHECK-MESSAGES: [[@LINE+4]]:3: note: label defined here
170-
// CHECK-MESSAGES-MACRO: [[@LINE-3]]:3: warning: avoid using 'goto' for flow control
171-
// CHECK-MESSAGES-MACRO: [[@LINE+2]]:3: note: label defined here
161+
// CHECK-MESSAGES: [[@LINE+2]]:3: note: label defined here
172162
noop();
173163
macro_goto_label
174164
}
175165

176166
void inside_macro_goto() {
177167
noop();
178168
macro_goto_jump
179-
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
180-
// CHECK-MESSAGES: [[@LINE+2]]:3: note: label defined here
169+
// CHECK-MESSAGES-MACRO: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
170+
// CHECK-MESSAGES-MACRO: [[@LINE+2]]:3: note: label defined here
181171
noop();
182172
jump_to_me:;
183173
}

0 commit comments

Comments
 (0)