Skip to content

Fixes for #215, 232 FP reports #245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
Expand Up @@ -80,11 +80,11 @@ class AcceptableWrapper extends PreprocessorBranch {

from PreprocessorDirective directive, string message
where
(
not directive instanceof PermittedDirectiveType and
not directive instanceof AcceptableWrapper and
message = "Preprocessor directive used for conditional compilation."
) and
//special exception case - pragmas already reported by A16-7-1
not directive instanceof PreprocessorPragma and
not directive instanceof PermittedDirectiveType and
not directive instanceof AcceptableWrapper and
message = "Preprocessor directive used for conditional compilation." and
not isExcluded(directive,
MacrosPackage::preProcessorShallOnlyBeUsedForCertainDirectivesPatternsQuery())
select directive, message
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
| test.cpp:3:1:3:25 | #pragma gcc testingpragma | Preprocessor directive used for conditional compilation. |
| test.cpp:5:1:5:18 | #ifndef TESTHEADER | Preprocessor directive used for conditional compilation. |
| test.cpp:9:1:9:26 | #define OBJECTLIKE_MACRO 1 | Preprocessor directive used for conditional compilation. |
| test.cpp:10:1:10:35 | #define FUNCTIONLIKE_MACRO(X) X + 1 | Preprocessor directive used for conditional compilation. |
Expand Down
2 changes: 1 addition & 1 deletion cpp/autosar/test/rules/A16-0-1/test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <string> //COMPLIANT

#pragma gcc testingpragma // NON_COMPLIANT
#pragma gcc testingpragma // COMPLIANT - exception - already reported by A16-7-1

#ifndef TESTHEADER // NON_COMPLIANT
int g;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ predicate isGeneratedByUserMacro(Declaration d) {
from Locatable l, string s
where
not isExcluded(l, NamingPackage::useOfDoubleUnderscoreReservedPrefixQuery()) and
//exclude uses of __func__, which are modelled as LocalVariable declarations
not(l.(LocalVariable).getName() = "__func__") and
(
exists(Macro m | l = m and isReservedMacroPrefix(m) and s = m.getName())
or
Expand All @@ -47,4 +49,4 @@ where
)
)
)
select l, "Name $@ uses the reserved prefix '__'.", l, s
select l, "Name $@ uses the reserved prefix '__'.", l, s
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
| test.cpp:24:5:24:7 | __x | Name $@ uses the reserved prefix '__'. | test.cpp:24:5:24:7 | __x | __x |
| test.cpp:29:5:29:7 | __x | Name $@ uses the reserved prefix '__'. | test.cpp:29:5:29:7 | __x | __x |
| test.cpp:25:5:25:7 | __x | Name $@ uses the reserved prefix '__'. | test.cpp:25:5:25:7 | __x | __x |
| test.cpp:30:5:30:7 | __x | Name $@ uses the reserved prefix '__'. | test.cpp:30:5:30:7 | __x | __x |
7 changes: 6 additions & 1 deletion cpp/cert/test/rules/DCL51-CPP/test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <cstdint>
#include <string>

#include "test.h"

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

#define FD_SET(X) \
int _##X // NON_COMPLIANT - redefinition of standard library macro
FD_SET(j); // COMPLIANT - standard library macro
FD_SET(j); // COMPLIANT - standard library macro

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