[clang-tools-extra] [clang-tidy] add 'IgnoreMarcos' option to 'avoid-goto' check (PR #143554)
Congcong Cai via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 13 23:30:48 PDT 2025
================
@@ -132,8 +133,41 @@ void jump_out_backwards() {
for (int j = 0; j < 10; ++j) {
if (i * j > 80)
goto before_the_loop;
- // CHECK-NOTES: [[@LINE-1]]:9: warning: avoid using 'goto' for flow control
- // CHECK-NOTES: [[@LINE-8]]:1: note: label defined here
+ // CHECK-MESSAGES: [[@LINE-1]]:9: warning: avoid using 'goto' for flow control
+ // CHECK-MESSAGES: [[@LINE-8]]:1: note: label defined here
}
}
}
+
+#define macro_goto_code \
+ noop(); \
+ goto jump_to_me; \
+ noop(); \
+jump_to_me:; \
+
+#define macro_goto_label jump_to_me:;
+#define macro_goto_jump goto jump_to_me;
+
+void inside_macro_all() {
+ macro_goto_code
+ // CHECK-MESSAGES-MACRO: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
+ // CHECK-MESSAGES-MACRO: [[@LINE-2]]:3: note: label defined here
+}
+
+void inside_macro_label() {
+ noop();
+ goto jump_to_me;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
+ // CHECK-MESSAGES: [[@LINE+2]]:3: note: label defined here
+ noop();
+ macro_goto_label
+}
+
+void inside_macro_goto() {
+ noop();
+ macro_goto_jump
+ // CHECK-MESSAGES-MACRO: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
+ // CHECK-MESSAGES-MACRO: [[@LINE+2]]:3: note: label defined here
----------------
HerrCai0907 wrote:
> If set to `true`, the check will not warn if both label and ``goto`` statement are placed inside a macro. Default is `true`.
According to doc, it should be warn also since label is not in macro.
https://github.com/llvm/llvm-project/pull/143554
More information about the cfe-commits
mailing list