[clang-tools-extra] [clang-tidy] Add new check 'misc-scope-reduction' (PR #175429)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Jan 24 08:09:42 PST 2026
github-actions[bot] wrote:
<!--PREMERGE ADVISOR COMMENT: Windows-->
# :window: Windows x64 Test Results
* 3031 tests passed
* 29 tests skipped
* 1 test failed
## Failed Tests
(click on a test name to see its output)
### Clang Tools
<details>
<summary>Clang Tools.clang-tidy/checkers/misc/scope-reduction.cpp</summary>
```
Exit Code: 1
Command Output (stdout):
--
# RUN: at line 1
C:/Python312/python.exe C:/_work/llvm-project/llvm-project/clang-tools-extra/test/../test\clang-tidy\check_clang_tidy.py C:\_work\llvm-project\llvm-project\clang-tools-extra\test\clang-tidy\checkers\misc\scope-reduction.cpp misc-scope-reduction C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp -- --
# executed command: C:/Python312/python.exe 'C:/_work/llvm-project/llvm-project/clang-tools-extra/test/../test\clang-tidy\check_clang_tidy.py' 'C:\_work\llvm-project\llvm-project\clang-tools-extra\test\clang-tidy\checkers\misc\scope-reduction.cpp' misc-scope-reduction 'C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp' -- --
# .---command stdout------------
# | Running ['clang-tidy', '--experimental-custom-checks', 'C:\\_work\\llvm-project\\llvm-project\\build\\tools\\clang\\tools\\extra\\test\\clang-tidy\\checkers\\misc\\Output\\scope-reduction.cpp.tmp.cpp', '-fix', '--checks=-*,misc-scope-reduction', '--config={}', '--', '-std=c++11', '-nostdinc++']...
# | ------------------------ clang-tidy output -----------------------
# | 41 warnings generated.
# |
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:5:7: warning: variable 'x' can be declared in a smaller scope [misc-scope-reduction]
# | 5 | int x = 42;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:10:13: note: used here
# | 10 | int y = x + 1;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:9:13: note: can be declared in this scope
# | 9 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:25:7: warning: variable 'a' can be declared in a smaller scope [misc-scope-reduction]
# | 25 | int a = 5;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:31:15: note: used here
# | 31 | int b = a * 2;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:30:15: note: can be declared in this scope
# | 30 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:71:7: warning: variable 'i' can be declared in for-loop initialization [misc-scope-reduction]
# | 71 | int i;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:74:3: note: can be declared in this for-loop
# | 74 | for (i = 0; i < 5; i++) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:107:7: warning: variable 'cmplx_expr' can be declared in a smaller scope [misc-scope-reduction]
# | 107 | int cmplx_expr = (5 + 3) * 2;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:112:19: note: used here
# | 112 | int doubled = cmplx_expr * 2;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:111:13: note: can be declared in this scope
# | 111 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:118:7: warning: variable 'movable' can be declared in a smaller scope [misc-scope-reduction]
# | 118 | int movable = 10;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:125:17: note: used here
# | 125 | int local = movable + 5;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:124:13: note: can be declared in this scope
# | 124 | if (flag) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:134:7: warning: variable 'error_code' can be declared in a smaller scope [misc-scope-reduction]
# | 134 | int error_code = 0;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:139:5: note: used here
# | 139 | error_code = 404;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:138:7: note: can be declared in this scope
# | 138 | try {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:157:7: warning: variable 'deep' can be declared in a smaller scope [misc-scope-reduction]
# | 157 | int deep = 1;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:165:24: note: used here
# | 165 | int result = deep * 4;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:164:19: note: can be declared in this scope
# | 164 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:185:9: warning: variable 'local' can be declared in a smaller scope [misc-scope-reduction]
# | 185 | int local = global_var + namespaced_global;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:190:7: note: used here
# | 190 | local *= 2;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:189:15: note: can be declared in this scope
# | 189 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:249:7: warning: variable 'local' can be declared in a smaller scope [misc-scope-reduction]
# | 249 | int local = 5;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:256:20: note: used here
# | 256 | auto lambda = [local]() {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:257:14: note: used here
# | 257 | return local *3;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:255:13: note: can be declared in this scope
# | 255 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:272:7: warning: variable 'mixed' can be declared in a smaller scope [misc-scope-reduction]
# | 272 | int mixed = 0;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:280:9: note: used here
# | 280 | mixed = 10;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:283:5: note: used here
# | 283 | mixed += 5; // Also used outside switch
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:277:13: note: can be declared in this scope
# | 277 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:351:7: warning: variable 'x' can be declared in a smaller scope [misc-scope-reduction]
# | 351 | int x = 42;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:359:13: note: used here
# | 359 | int a = x + 1; // First use
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:360:13: note: used here
# | 360 | int b = x + 2; // Second use
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:361:13: note: used here
# | 361 | int c = x + 3; // Third use
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:362:13: note: and 3 more uses...
# | 362 | int d = x + 4; // Fourth use - should show in overflow note
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:358:13: note: can be declared in this scope
# | 358 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:370:7: warning: variable 'x' can be declared in a smaller scope [misc-scope-reduction]
# | 370 | int x = 1;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:377:13: note: used here
# | 377 | int a = x + 1; // First use
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:378:13: note: used here
# | 378 | int b = x + 2; // Second use
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:379:13: note: used here
# | 379 | int c = x + 3; // Third use
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:376:13: note: can be declared in this scope
# | 376 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:385:7: warning: variable 'x' can be declared in a smaller scope [misc-scope-reduction]
# | 385 | int x = 1;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:390:13: note: used here
# | 390 | int a = x + 1; // First use
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:389:13: note: can be declared in this scope
# | 389 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:396:7: warning: variable 'i' can be declared in for-loop initialization [misc-scope-reduction]
# | 396 | int i;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:399:3: note: can be declared in this for-loop
# | 399 | for (i = 0; i < 5; i++) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:415:7: warning: variable 'value' can be declared in a smaller scope [misc-scope-reduction]
# | 415 | int value = 0; // Should be reported - used in broader if-statement scope
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:421:5: note: used here
# | 421 | value = 42;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:422:5: note: used here
# | 422 | value += 1;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:420:13: note: can be declared in this scope
# | 420 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:431:7: warning: variable 'value' can be declared in a smaller scope [misc-scope-reduction]
# | 431 | int value = 10;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:436:5: note: used here
# | 436 | value *= 2; // Not in loop, should still warn
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:435:13: note: can be declared in this scope
# | 435 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:442:7: warning: variable 'x' can be declared in a smaller scope [misc-scope-reduction]
# | 442 | int x = 5;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:448:5: note: used here
# | 448 | x = x + 10; // Not in loop, should still warn
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:448:9: note: used here
# | 448 | x = x + 10; // Not in loop, should still warn
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:447:13: note: can be declared in this scope
# | 447 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:454:7: warning: variable 'result' can be declared in a smaller scope [misc-scope-reduction]
# | 454 | int result = 0;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:460:5: note: used here
# | 460 | result = result + 42; // Not in loop, should still warn
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:460:14: note: used here
# | 460 | result = result + 42; // Not in loop, should still warn
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:459:13: note: can be declared in this scope
# | 459 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:567:7: warning: variable 'x' can be declared in a smaller scope [misc-scope-reduction]
# | 567 | int x = 10;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:573:10: note: used here
# | 573 | y += x; // x is not the accumulator, y is
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:571:13: note: can be declared in this scope
# | 571 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:700:7: warning: variable 'b' can be declared in a smaller scope [misc-scope-reduction]
# | 700 | int b = a * 2; // b could potentially be moved if only used in smaller scope
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:706:9: note: used here
# | 706 | use(b);
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:705:18: note: can be declared in this scope
# | 705 | if (condition) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:979:7: warning: variable 'limit' can be declared in for-loop initialization [misc-scope-reduction]
# | 979 | int limit = 10;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:982:3: note: can be declared in this for-loop
# | 982 | for (int I = 0; I < limit; ++I) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1041:9: warning: variable 'node' can be declared in for-loop initialization [misc-scope-reduction]
# | 1041 | Node* node = &root;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1044:3: note: can be declared in this for-loop
# | 1044 | for (int i = 0; node && i < 10; ++i) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1058:7: warning: variable 'arr' can be declared in a smaller scope [misc-scope-reduction]
# | 1058 | int arr[10];
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1064:5: note: used here
# | 1064 | arr[0] = 42;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1065:5: note: used here
# | 1065 | arr[1] = 43;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1063:10: note: can be declared in this scope
# | 1063 | if (1) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1072:9: warning: variable 'func_ptr' can be declared in a smaller scope [misc-scope-reduction]
# | 1072 | int (*func_ptr)(int, int) = add;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1077:18: note: used here
# | 1077 | int result = func_ptr(1, 2);
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1076:10: note: can be declared in this scope
# | 1076 | if (1) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1087:16: warning: variable 'p' can be declared in a smaller scope [misc-scope-reduction]
# | 1087 | struct Point p = {10, 20};
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1093:15: note: used here
# | 1093 | int sum = p.x + p.y;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1093:21: note: used here
# | 1093 | int sum = p.x + p.y;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1092:10: note: can be declared in this scope
# | 1092 | if (1) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1115:8: warning: variable 'value' can be declared in a smaller scope [misc-scope-reduction]
# | 1115 | auto value = 42;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1120:19: note: used here
# | 1120 | int doubled = value * 2;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1119:13: note: can be declared in this scope
# | 1119 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1126:8: warning: variable 'value' can be declared in a smaller scope [misc-scope-reduction]
# | 1126 | auto value = 42;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1131:19: note: used here
# | 1131 | int doubled = value * 2;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1130:13: note: can be declared in this scope
# | 1130 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1141:14: warning: variable 'pair_val' can be declared in a smaller scope [misc-scope-reduction]
# | 1141 | SimplePair pair_val = {1, 2};
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1147:15: note: used here
# | 1147 | int sum = pair_val.first + pair_val.second;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1147:32: note: used here
# | 1147 | int sum = pair_val.first + pair_val.second;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1146:13: note: can be declared in this scope
# | 1146 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1153:17: warning: variable 'compile_time_val' can be declared in a smaller scope [misc-scope-reduction]
# | 1153 | constexpr int compile_time_val = 42;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1158:18: note: used here
# | 1158 | int result = compile_time_val * 2;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1157:13: note: can be declared in this scope
# | 1157 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1255:12: warning: variable 'res' can be declared in a smaller scope [misc-scope-reduction]
# | 1255 | Resource res;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1260:5: note: used here
# | 1260 | res.use();
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1259:13: note: can be declared in this scope
# | 1259 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1277:7: warning: variable 'local_copy' can be declared in a smaller scope [misc-scope-reduction]
# | 1277 | int local_copy = tls_var;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1282:19: note: used here
# | 1282 | int doubled = local_copy * 2;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1281:13: note: can be declared in this scope
# | 1281 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1294:7: warning: variable 'value' can be declared in a smaller scope [misc-scope-reduction]
# | 1294 | int value = 10;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1299:26: note: used here
# | 1299 | int result = USE_VAR(value);
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1298:13: note: can be declared in this scope
# | 1298 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1317:7: warning: variable 'debug_var' can be declared in a smaller scope [misc-scope-reduction]
# | 1317 | int debug_var = 42;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1323:16: note: used here
# | 1323 | int temp = debug_var;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1322:13: note: can be declared in this scope
# | 1322 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1345:7: warning: variable 'a' can be declared in a smaller scope [misc-scope-reduction]
# | 1345 | int a = 1, b = 2;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1353:15: note: used here
# | 1353 | int sum = a + b;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1352:13: note: can be declared in this scope
# | 1352 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1345:14: warning: variable 'b' can be declared in a smaller scope [misc-scope-reduction]
# | 1345 | int a = 1, b = 2;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1353:19: note: used here
# | 1353 | int sum = a + b;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1352:13: note: can be declared in this scope
# | 1352 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1360:7: warning: variable 'condition_var' can be declared in a smaller scope [misc-scope-reduction]
# | 1360 | int condition_var = 1;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1373:18: note: used here
# | 1373 | int result = condition_var ? true_val : false_val;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1372:13: note: can be declared in this scope
# | 1372 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1361:7: warning: variable 'true_val' can be declared in a smaller scope [misc-scope-reduction]
# | 1361 | int true_val = 10;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1373:34: note: used here
# | 1373 | int result = condition_var ? true_val : false_val;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1372:13: note: can be declared in this scope
# | 1372 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1362:7: warning: variable 'false_val' can be declared in a smaller scope [misc-scope-reduction]
# | 1362 | int false_val = 20;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1373:45: note: used here
# | 1373 | int result = condition_var ? true_val : false_val;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1372:13: note: can be declared in this scope
# | 1372 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1379:7: warning: variable 'true_val' can be declared in a smaller scope [misc-scope-reduction]
# | 1379 | int true_val = 10;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1388:25: note: used here
# | 1388 | int result = cond ? true_val : false_val;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1387:13: note: can be declared in this scope
# | 1387 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1380:7: warning: variable 'false_val' can be declared in a smaller scope [misc-scope-reduction]
# | 1380 | int false_val = 20;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1388:36: note: used here
# | 1388 | int result = cond ? true_val : false_val;
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1387:13: note: can be declared in this scope
# | 1387 | if (true) {
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1395:7: warning: variable 'array' can be declared in a smaller scope [misc-scope-reduction]
# | 1395 | int array[100];
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1400:23: note: used here
# | 1400 | int size = sizeof(array);
# | | ^
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1399:13: note: can be declared in this scope
# | 1399 | if (true) {
# | | ^
# |
# | ------------------------------------------------------------------
# | ------------------------------ Fixes -----------------------------
# |
# | ------------------------------------------------------------------
# | FileCheck -input-file=C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp.notes C:\_work\llvm-project\llvm-project\clang-tools-extra\test\clang-tidy\checkers\misc\scope-reduction.cpp -check-prefixes=CHECK-NOTES -implicit-check-not={{note|warning|error}}: failed:
# | C:\_work\llvm-project\llvm-project\clang-tools-extra\test\clang-tidy\checkers\misc\scope-reduction.cpp:1166:18: error: CHECK-NOTES: expected string not found in input
# |
# | // CHECK-NOTES: :[[@LINE-1]]:7: warning: variable 'value' can be declared in a smaller scope
# |
# | ^
# |
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp.notes:287:175: note: scanning from here
# |
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1157:13: note: can be declared in this scope
# |
# | ^
# |
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp.notes:287:175: note: with "@LINE-1" equal to "1165"
# |
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1157:13: note: can be declared in this scope
# |
# | ^
# |
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp.notes:308:134: note: possible intended match here
# |
# | C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1294:7: warning: variable 'value' can be declared in a smaller scope [misc-scope-reduction]
# |
# | ^
# |
# |
# |
# | Input file: C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp.notes
# |
# | Check file: C:\_work\llvm-project\llvm-project\clang-tools-extra\test\clang-tidy\checkers\misc\scope-reduction.cpp
# |
# |
# |
# | -dump-input=help explains the following input dump.
# |
# |
# |
# | Input was:
# |
# | <<<<<<
# |
# | .
# |
# | .
# |
# | .
# |
# | 282: 1153 | constexpr int compile_time_val = 42;
# |
# | 283: | ^
# |
# | 284: C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1158:18: note: used here
# |
# | 285: 1158 | int result = compile_time_val * 2;
# |
# | 286: | ^
# |
# | 287: C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1157:13: note: can be declared in this scope
# |
# | check:1166'0 X error: no match found
# |
# | check:1166'1 with "@LINE-1" equal to "1165"
# |
# | 288: 1157 | if (true) {
# |
# | check:1166'0 ~~~~~~~~~~~~~~~~~~~~
# |
# | 289: | ^
# |
# | check:1166'0 ~~~~~
# |
# | 290: C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1255:12: warning: variable 'res' can be declared in a smaller scope [misc-scope-reduction]
# |
# | check:1166'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
# | 291: 1255 | Resource res;
# |
# | check:1166'0 ~~~~~~~~~~~~~~~~~~~~~~
# |
# | 292: | ^
# |
# | check:1166'0 ~~~~~
# |
# | .
# |
# | .
# |
# | .
# |
# | 303: 1282 | int doubled = local_copy * 2;
# |
# | check:1166'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
# | 304: | ^
# |
# | check:1166'0 ~~~~~
# |
# | 305: C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1281:13: note: can be declared in this scope
# |
# | check:1166'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
# | 306: 1281 | if (true) {
# |
# | check:1166'0 ~~~~~~~~~~~~~~~~~~~~
# |
# | 307: | ^
# |
# | check:1166'0 ~~~~~
# |
# | 308: C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1294:7: warning: variable 'value' can be declared in a smaller scope [misc-scope-reduction]
# |
# | check:1166'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
# | check:1166'2 ? possible intended match
# |
# | 309: 1294 | int value = 10;
# |
# | check:1166'0 ~~~~~~~~~~~~~~~~~~~~~~~~
# |
# | 310: | ^
# |
# | check:1166'0 ~~~~~
# |
# | 311: C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra\test\clang-tidy\checkers\misc\Output\scope-reduction.cpp.tmp.cpp:1299:26: note: used here
# |
# | check:1166'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
# | 312: 1299 | int result = USE_VAR(value);
# |
# | check:1166'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
# | 313: | ^
# |
# | check:1166'0 ~~~~~
# |
# | .
# |
# | .
# |
# | .
# |
# | >>>>>>
# |
# |
# `-----------------------------
# .---command stderr------------
# | Traceback (most recent call last):
# | File "C:\_work\llvm-project\llvm-project\clang-tools-extra\test\clang-tidy\check_clang_tidy.py", line 413, in <module>
# | main()
# | File "C:\_work\llvm-project\llvm-project\clang-tools-extra\test\clang-tidy\check_clang_tidy.py", line 409, in main
# | CheckRunner(args, extra_args).run()
# | File "C:\_work\llvm-project\llvm-project\clang-tools-extra\test\clang-tidy\check_clang_tidy.py", line 313, in run
# | self.check_notes(clang_tidy_output)
# | File "C:\_work\llvm-project\llvm-project\clang-tools-extra\test\clang-tidy\check_clang_tidy.py", line 292, in check_notes
# | try_run(
# | File "C:\_work\llvm-project\llvm-project\clang-tools-extra\test\clang-tidy\check_clang_tidy.py", line 63, in try_run
# | process_output = subprocess.check_output(args, stderr=subprocess.STDOUT).decode(
# | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# | File "c:\python312\Lib\subprocess.py", line 466, in check_output
# | return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
# | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# | File "c:\python312\Lib\subprocess.py", line 571, in run
# | raise CalledProcessError(retcode, process.args,
# | subprocess.CalledProcessError: Command '['FileCheck', '-input-file=C:\\_work\\llvm-project\\llvm-project\\build\\tools\\clang\\tools\\extra\\test\\clang-tidy\\checkers\\misc\\Output\\scope-reduction.cpp.tmp.cpp.notes', 'C:\\_work\\llvm-project\\llvm-project\\clang-tools-extra\\test\\clang-tidy\\checkers\\misc\\scope-reduction.cpp', '-check-prefixes=CHECK-NOTES', '-implicit-check-not={{note|warning|error}}:']' returned non-zero exit status 1.
# `-----------------------------
# error: command failed with exit status: 1
--
```
</details>
If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the `infrastructure` label.
https://github.com/llvm/llvm-project/pull/175429
More information about the cfe-commits
mailing list