[PATCH] D23265: [clang-tidy] enhance readability-else-after-return

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 9 12:09:03 PDT 2016

alexfh added inline comments.

Comment at: test/clang-tidy/readability-else-after-return.cpp:33
@@ -32,1 +32,3 @@
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use 'else' after 'return'
+  // CHECK-FIXES: // comment
omtcyfz wrote:
> alexfh wrote:
> > CHECK-FIXES pattern should be sticter. Current pattern will match for any `// comment` occurrence anywhere in the test file, even if it's on a different line and still prefixed with `else`.
> > 
> > Two action items here: 1. make comments and patterns unique, 2. anchor patterns to the start of line (`{{ˆ}}`).
> Why make comments and patterns unique? If I anchor patterns to the start of line, it will only look at the line above, why does it need to be unique then?
> Why make comments and patterns unique?

Because FileCheck is way simpler than one usually thinks of it.

It doesn't maintain any relation between the location of the check line and the input line. So your assumption that

> it will only look at the line above

is wrong.

The only thing FileCheck cares about is that the input contains a subsequence of lines that match all the CHECK patterns (a bit more complicated, if CHECK-NOT, CHECK-NEXT, CHECK-SAME, CHECK-DAG, or CHECK-LABEL are in use, but the basic idea is roughly the same).

So, if all CHECK-FIXES patterns in this test are `// comment`, then any input that contains at least the same number of `// comment` substrings on different lines will pass the test.

Please read http://llvm.org/docs/CommandGuide/FileCheck.html as well.


More information about the cfe-commits mailing list