Skip to content

Commit 13ed50f

Browse files
committed
CPP: Improve the regexp.
1 parent d70e7ce commit 13ed50f

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

cpp/ql/src/Documentation/CommentedOutCode.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ private predicate looksLikeCode(string line) {
3030
)
3131
) or (
3232
// Match comment lines that look like preprocessor code
33-
trimmed.regexpMatch("#(include|define|undef|if|ifdef|ifndef|elif|else|endif|error)(\\s.*|)")
33+
trimmed.regexpMatch("#\\s*(include|define|undef|if|ifdef|ifndef|elif|else|endif|error|pragma)\\b.*")
3434
)
3535
) and (
3636
// Exclude lines that start with '>' or contain '@{' or '@}'.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
| test2.cpp:43:1:43:18 | // #define MYMACRO | This comment appears to contain commented-out code |
55
| test2.cpp:45:1:45:23 | // #include "include.h" | This comment appears to contain commented-out code |
66
| test2.cpp:47:1:51:2 | /*\n#ifdef\nvoid myFunction();\n#endif\n*/ | This comment appears to contain commented-out code |
7+
| test2.cpp:59:1:59:24 | // #if(defined(MYMACRO)) | This comment appears to contain commented-out code |
8+
| test2.cpp:63:1:63:15 | // #pragma once | This comment appears to contain commented-out code |
9+
| test2.cpp:65:1:65:17 | // # pragma once | This comment appears to contain commented-out code |
10+
| test2.cpp:67:1:67:19 | /*#error"myerror"*/ | This comment appears to contain commented-out code |
711
| test.c:2:1:2:22 | // commented out code; | This comment appears to contain commented-out code |
812
| test.c:4:1:7:8 | // some; | This comment appears to contain commented-out code |
913
| test.c:9:1:13:8 | // also; | This comment appears to contain commented-out code |

0 commit comments

Comments
 (0)