Skip to content

Commit 2ae8a9a

Browse files
committed
Changed default value to 'false' and corrected docs
1 parent a45d15f commit 2ae8a9a

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ AST_MATCHER(GotoStmt, isInMacro) {
2525

2626
AvoidGotoCheck::AvoidGotoCheck(StringRef Name, ClangTidyContext *Context)
2727
: ClangTidyCheck(Name, Context),
28-
IgnoreMacros(Options.get("IgnoreMacros", true)) {}
28+
IgnoreMacros(Options.get("IgnoreMacros", false)) {}
2929

3030
void AvoidGotoCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
3131
Options.store(Opts, "IgnoreMacros", IgnoreMacros);

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 both label and ``goto``
61-
statement are placed inside a macro. Default is `true`.
60+
If set to `true`, the check will not warn if ``goto`` statement is placed
61+
inside a macro. Default is `false`.

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
// 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: false }}"
2+
// RUN: %check_clang_tidy -check-suffix=MACRO %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+3]]:1: note: label defined here
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
1113
noop();
1214

1315
jump_to_me:;
@@ -17,12 +19,16 @@ jump_backwards:;
1719
goto jump_backwards;
1820
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
1921
// 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
2024

2125
goto jump_in_line;
2226
;
2327
jump_in_line:;
2428
// CHECK-MESSAGES: [[@LINE-3]]:3: warning: avoid using 'goto' for flow control
2529
// 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
2632

2733
// Test the GNU extension https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
2834
some_label:;
@@ -135,6 +141,8 @@ void jump_out_backwards() {
135141
goto before_the_loop;
136142
// CHECK-MESSAGES: [[@LINE-1]]:9: warning: avoid using 'goto' for flow control
137143
// 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
138146
}
139147
}
140148
}
@@ -150,24 +158,26 @@ jump_to_me:; \
150158

151159
void inside_macro_all() {
152160
macro_goto_code
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
161+
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
162+
// CHECK-MESSAGES: [[@LINE-2]]:3: note: label defined here
155163
}
156164

157165
void inside_macro_label() {
158166
noop();
159167
goto jump_to_me;
160168
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
161-
// CHECK-MESSAGES: [[@LINE+2]]:3: note: label defined here
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
162172
noop();
163173
macro_goto_label
164174
}
165175

166176
void inside_macro_goto() {
167177
noop();
168178
macro_goto_jump
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
179+
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
180+
// CHECK-MESSAGES: [[@LINE+2]]:3: note: label defined here
171181
noop();
172182
jump_to_me:;
173183
}

0 commit comments

Comments
 (0)