Skip to content

Commit 5c0f635

Browse files
authored
Merge pull request #301 from github/lcartey/dcl51-cpp-fps
DCL51-CPP: Ignore compiler generated
2 parents 60df95b + 8ff407d commit 5c0f635

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* `DCL51-CPP` - `cpp/cert/use-of-single-underscore-reserved-prefix` - remove false positives which were compiler generated, such as the function `_FUN` generated by the compiler for lambdas converted to function pointers.

cpp/cert/src/rules/DCL51-CPP/UseOfSingleUnderscoreReservedPrefix.ql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,8 @@ where
5353
isGeneratedByUserMacro(d)
5454
)
5555
)
56-
)
56+
) and
57+
// Ignore compiler generated functions and variables
58+
not l.(Function).isCompilerGenerated() and
59+
not l.(Variable).isCompilerGenerated()
5760
select l, "Name $@ uses the reserved prefix '_'.", l, s

cpp/cert/test/rules/DCL51-CPP/test.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
#include "test.h"
12
#include <cstdint>
3+
#include <functional>
24
#include <string>
35

4-
#include "test.h"
5-
66
#undef INT_MAX // NON_COMPLIANT
77
#define SIZE_MAX 256 // NON_COMPLIANT
88

@@ -40,4 +40,12 @@ FD_SET(j); // COMPLIANT - standard library macro
4040

4141
void f() {
4242
std::string x = __func__; // COMPLIANT
43+
}
44+
45+
void g(int (*l)(int)) {}
46+
47+
void test_lambda(const int y) {
48+
// Lambda generates a static function called `_FUN` when the lambda is
49+
// converted to a function pointer
50+
g([](int x) { return x; }); // COMPLIANT - compiler generated
4351
}

0 commit comments

Comments
 (0)