Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +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.
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,8 @@ where
isGeneratedByUserMacro(d)
)
)
)
) and
// Ignore compiler generated functions and variables
not l.(Function).isCompilerGenerated() and
not l.(Variable).isCompilerGenerated()
select l, "Name $@ uses the reserved prefix '_'.", l, s
12 changes: 10 additions & 2 deletions cpp/cert/test/rules/DCL51-CPP/test.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "test.h"
#include <cstdint>
#include <functional>
#include <string>

#include "test.h"

#undef INT_MAX // NON_COMPLIANT
#define SIZE_MAX 256 // NON_COMPLIANT

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

void f() {
std::string x = __func__; // COMPLIANT
}

void g(int (*l)(int)) {}

void test_lambda(const int y) {
// Lambda generates a static function called `_FUN` when the lambda is
// converted to a function pointer
g([](int x) { return x; }); // COMPLIANT - compiler generated
}