Skip to content

Commit 6bd9ed7

Browse files
authored
Merge pull request #788 from fjatWbyT/fix-issue-629
Fix #629 about `A7-1-7`
2 parents cc7df81 + 301d133 commit 6bd9ed7

File tree

3 files changed

+34
-20
lines changed

3 files changed

+34
-20
lines changed

Diff for: change_notes/2024-10-30-fix-issue-629.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `A7-1-7` - `IdentifierDeclarationAndInitializationNotOnSeparateLines.ql`
2+
- Fixes #629. Adds brackets, excluding expressions statements in macros.

Diff for: cpp/autosar/src/rules/A7-1-7/IdentifierDeclarationAndInitializationNotOnSeparateLines.ql

+21-19
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,28 @@ import codingstandards.cpp.autosar
1919
class UniqueLineStmt extends Locatable {
2020
UniqueLineStmt() {
2121
not isAffectedByMacro() and
22-
exists(Declaration d |
23-
this = d.getADeclarationEntry() and
24-
not d instanceof Parameter and
25-
not d instanceof TemplateParameter and
26-
// TODO - Needs to be enhanced to solve issues with
27-
// templated inner classes.
28-
not d instanceof Function and
29-
not d.isFromTemplateInstantiation(_) and
30-
not d.(Variable).isCompilerGenerated() and
31-
not exists(RangeBasedForStmt f | f.getADeclaration() = d) and
32-
not exists(DeclStmt declStmt, ForStmt f |
33-
f.getInitialization() = declStmt and
34-
declStmt.getADeclaration() = d
35-
) and
36-
not exists(LambdaCapture lc | lc.getField().getADeclarationEntry() = this)
22+
(
23+
exists(Declaration d |
24+
this = d.getADeclarationEntry() and
25+
not d instanceof Parameter and
26+
not d instanceof TemplateParameter and
27+
// TODO - Needs to be enhanced to solve issues with
28+
// templated inner classes.
29+
not d instanceof Function and
30+
not d.isFromTemplateInstantiation(_) and
31+
not d.(Variable).isCompilerGenerated() and
32+
not exists(RangeBasedForStmt f | f.getADeclaration() = d) and
33+
not exists(DeclStmt declStmt, ForStmt f |
34+
f.getInitialization() = declStmt and
35+
declStmt.getADeclaration() = d
36+
) and
37+
not exists(LambdaCapture lc | lc.getField().getADeclarationEntry() = this)
38+
)
39+
or
40+
this instanceof ExprStmt and
41+
not exists(ForStmt f | f.getInitialization().getAChild*() = this) and
42+
not exists(LambdaExpression l | l.getLambdaFunction().getBlock().getAChild*() = this)
3743
)
38-
or
39-
this instanceof ExprStmt and
40-
not exists(ForStmt f | f.getInitialization().getAChild*() = this) and
41-
not exists(LambdaExpression l | l.getLambdaFunction().getBlock().getAChild*() = this)
4244
}
4345
}
4446

Diff for: cpp/autosar/test/rules/A7-1-7/test.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,14 @@ void example_function() { f1(); } // COMPLIANT
152152

153153
// clang-format off
154154
typedef struct x { int y; } z; //COMPLIANT - for struct typedef and struct var //NON_COMPLIANT - for struct all on one line
155-
// clang-format on
155+
// clang-format on
156+
157+
#define foo(x, y) \
158+
x++; \
159+
y++;
160+
161+
void test_foo() {
162+
int a = 1;
163+
int b = 1;
164+
foo(a, b); // COMPLIANT
165+
}

0 commit comments

Comments
 (0)