Skip to content

Commit 1c9286b

Browse files
committed
Fix FP for issue 215
1 parent 3b17207 commit 1c9286b

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ predicate isGeneratedByUserMacro(Declaration d) {
3333
from Locatable l, string s
3434
where
3535
not isExcluded(l, NamingPackage::useOfDoubleUnderscoreReservedPrefixQuery()) and
36+
//exclude uses of __func__, which are modelled as LocalVariable declarations
37+
not(l.(LocalVariable).getName() = "__func__") and
3638
(
3739
exists(Macro m | l = m and isReservedMacroPrefix(m) and s = m.getName())
3840
or
@@ -47,4 +49,4 @@ where
4749
)
4850
)
4951
)
50-
select l, "Name $@ uses the reserved prefix '__'.", l, s
52+
select l, "Name $@ uses the reserved prefix '__'.", l, s
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| test.cpp:24:5:24:7 | __x | Name $@ uses the reserved prefix '__'. | test.cpp:24:5:24:7 | __x | __x |
2-
| test.cpp:29:5:29:7 | __x | Name $@ uses the reserved prefix '__'. | test.cpp:29:5:29:7 | __x | __x |
1+
| test.cpp:25:5:25:7 | __x | Name $@ uses the reserved prefix '__'. | test.cpp:25:5:25:7 | __x | __x |
2+
| test.cpp:30:5:30:7 | __x | Name $@ uses the reserved prefix '__'. | test.cpp:30:5:30:7 | __x | __x |

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <cstdint>
2+
#include <string>
23

34
#include "test.h"
45

@@ -35,4 +36,8 @@ F(i); // NON_COMPLIANT - user macro
3536

3637
#define FD_SET(X) \
3738
int _##X // NON_COMPLIANT - redefinition of standard library macro
38-
FD_SET(j); // COMPLIANT - standard library macro
39+
FD_SET(j); // COMPLIANT - standard library macro
40+
41+
void f() {
42+
std::string x = __func__; // COMPLIANT
43+
}

0 commit comments

Comments
 (0)