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 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
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 +1 @@
| test.cpp:9:3:9:9 | INT_MAX | The enumerator $@ reuses a reserved standard library name. | test.cpp:9:3:9:9 | INT_MAX | INT_MAX |
| test.cpp:10:3:10:9 | INT_MAX | The enumerator $@ reuses a reserved standard library name. | test.cpp:10:3:10:9 | INT_MAX | INT_MAX |
Original file line number Diff line number Diff line change
@@ -1 +1 @@
| test.cpp:19:6:19:8 | min | The function $@ reuses a reserved standard library name. | test.cpp:19:6:19:8 | min | min |
| test.cpp:20:6:20:8 | min | The function $@ reuses a reserved standard library name. | test.cpp:20:6:20:8 | min | min |
Original file line number Diff line number Diff line change
@@ -1 +1 @@
| test.cpp:17:5:17:10 | tzname | The variable $@ reuses a reserved standard library name. | test.cpp:17:5:17:10 | tzname | tzname |
| test.cpp:18:5:18:10 | tzname | The variable $@ reuses a reserved standard library name. | test.cpp:18:5:18:10 | tzname | tzname |
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
| test.cpp:5:1:5:14 | #undef INT_MAX | Redefinition of INT_MAX declared in a standard library header. |
| test.cpp:6:1:6:20 | #define SIZE_MAX 256 | Redefinition of SIZE_MAX declared in a standard library header. |
| test.cpp:36:1:37:9 | #define FD_SET(X) int _ ## X | Redefinition of FD_SET declared in a standard library header. |
| test.cpp:6:1:6:14 | #undef INT_MAX | Redefinition of INT_MAX declared in a standard library header. |
| test.cpp:7:1:7:20 | #define SIZE_MAX 256 | Redefinition of SIZE_MAX declared in a standard library header. |
| test.cpp:37:1:38:9 | #define FD_SET(X) int _ ## X | Redefinition of FD_SET declared in a standard library header. |
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
| test.cpp:12:1:12:15 | #undef noreturn | Redefinition of $@ lexically identical to reserved attribute token. | test.cpp:12:1:12:15 | #undef noreturn | noreturn |
| test.cpp:13:1:13:17 | #define private 1 | Redefinition of $@ lexically identical to keyword. | test.cpp:13:1:13:17 | #define private 1 | private |
| test.cpp:13:1:13:15 | #undef noreturn | Redefinition of $@ lexically identical to reserved attribute token. | test.cpp:13:1:13:15 | #undef noreturn | noreturn |
| test.cpp:14:1:14:17 | #define private 1 | Redefinition of $@ lexically identical to keyword. | test.cpp:14:1:14:17 | #define private 1 | private |
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 |
Original file line number Diff line number Diff line change
@@ -1 +1 @@
| test.cpp:21:6:21:17 | operator ""x | Literal suffix identifier $@ does not start with an underscore. | test.cpp:21:6:21:17 | operator ""x | operator ""x |
| test.cpp:22:6:22:17 | operator ""x | Literal suffix identifier $@ does not start with an underscore. | test.cpp:22:6:22:17 | operator ""x | operator ""x |
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
| test.cpp:25:5:25:6 | _X | Name $@ uses the reserved prefix '_'. | test.cpp:25:5:25:6 | _X | _X |
| test.cpp:26:5:26:6 | _x | Name $@ uses the reserved prefix '_'. | test.cpp:26:5:26:6 | _x | _x |
| test.cpp:30:5:30:6 | _X | Name $@ uses the reserved prefix '_'. | test.cpp:30:5:30:6 | _X | _X |
| test.cpp:34:1:34:3 | _i | Name $@ uses the reserved prefix '_'. | test.cpp:34:1:34:3 | _i | _i |
| test.cpp:26:5:26:6 | _X | Name $@ uses the reserved prefix '_'. | test.cpp:26:5:26:6 | _X | _X |
| test.cpp:27:5:27:6 | _x | Name $@ uses the reserved prefix '_'. | test.cpp:27:5:27:6 | _x | _x |
| test.cpp:31:5:31:6 | _X | Name $@ uses the reserved prefix '_'. | test.cpp:31:5:31:6 | _X | _X |
| test.cpp:35:1:35:3 | _i | Name $@ uses the reserved prefix '_'. | test.cpp:35:1:35:3 | _i | _i |
| test.h:2:1:2:15 | #define _TEST_H | Name $@ uses the reserved prefix '_'. | test.h:2:1:2:15 | #define _TEST_H | _TEST_H |
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
}