Skip to content

Commit 7bb9dee

Browse files
committed
C++: Recognize more function decls as code
1 parent 821a7bf commit 7bb9dee

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

cpp/ql/src/Documentation/CommentedOutCode.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ private predicate looksLikeCode(string line) {
2525
// brace that's preceded by something other than whitespace ...
2626
trimmed.regexpMatch(".*.\\}")
2727
implies
28-
// ... then there has to be ") {" (with some variation of
29-
// whitespace) on the line, suggesting it's a statement like `if`
28+
// ... then there has to be ") {" (or some variation)
29+
// on the line, suggesting it's a statement like `if`
3030
// or a function declaration. Otherwise it's likely to be a
3131
// benign use of braces such as a JSON example or explanatory
3232
// pseudocode.
33-
trimmed.regexpMatch(".*\\)\\s*\\{.*")
33+
trimmed.regexpMatch(".*(\\)|const|volatile|override|final|noexcept|&)\\s*\\{.*")
3434
)
3535
and not trimmed.regexpMatch("(>.*|.*[\\\\@][{}].*|(optional|repeated) .*;|.*(\\{\\{\\{|\\}\\}\\}).*|\\{[-0-9a-zA-Z]+\\})"))
3636
}

cpp/ql/test/query-tests/Documentation/CommentedOutCode/CommentedOutCode.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
| test2.cpp:37:1:37:39 | // int myFunction() { return myValue; } | This comment appears to contain commented-out code |
2+
| test2.cpp:39:1:39:45 | // int myFunction() const { return myValue; } | This comment appears to contain commented-out code |
3+
| test2.cpp:41:1:41:54 | // int myFunction() const noexcept { return myValue; } | This comment appears to contain commented-out code |
24
| test.c:2:1:2:22 | // commented out code; | This comment appears to contain commented-out code |
35
| test.c:4:1:7:8 | // some; | This comment appears to contain commented-out code |
46
| test.c:9:1:13:8 | // also; | This comment appears to contain commented-out code |

cpp/ql/test/query-tests/Documentation/CommentedOutCode/test2.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,7 @@
3535
// Example: { 1, 2, 3, 4 }
3636

3737
// int myFunction() { return myValue; }
38+
39+
// int myFunction() const { return myValue; }
40+
41+
// int myFunction() const noexcept { return myValue; }

0 commit comments

Comments
 (0)