Skip to content

Commit ff36b36

Browse files
authored
Merge pull request #634 from knewbury01/knewbury01/fix-628
A7-1-7: exclusions
2 parents 976e01a + 7efdf4c commit ff36b36

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- `A7-1-7` - `IdentifierDeclarationAndInitializationNotOnSeparateLines.ql`:
2+
- Fixes #628. Excludes Functions.
3+
- Fixes #630. Excludes struct identifiers and variables on the same line when a typedef is used.

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ class UniqueLineStmt extends Locatable {
2323
this = d.getADeclarationEntry() and
2424
not d instanceof Parameter and
2525
not d instanceof TemplateParameter and
26-
not d instanceof FunctionTemplateSpecialization and
2726
// TODO - Needs to be enhanced to solve issues with
2827
// templated inner classes.
29-
not d instanceof MemberFunction and
28+
not d instanceof Function and
3029
not d.isFromTemplateInstantiation(_) and
31-
not d.(Function).isCompilerGenerated() and
3230
not d.(Variable).isCompilerGenerated() and
3331
not exists(RangeBasedForStmt f | f.getADeclaration() = d) and
3432
not exists(DeclStmt declStmt, ForStmt f |
@@ -52,6 +50,9 @@ where
5250
DeclarationsPackage::identifierDeclarationAndInitializationNotOnSeparateLinesQuery()) and
5351
not e1 = e2 and
5452
not e1.(DeclarationEntry) = e2 and
53+
//omit the cases where there is one struct identifier on a struct var line used with typedef
54+
not exists(Struct s | s.getADeclarationEntry() = e1 and e1 instanceof TypeDeclarationEntry) and
55+
not exists(Struct s | s.getATypeNameUse() = e1 and e1 instanceof TypeDeclarationEntry) and
5556
exists(Location l1, Location l2 |
5657
e1.getLocation() = l1 and
5758
e2.getLocation() = l2 and

cpp/autosar/test/rules/A7-1-7/IdentifierDeclarationAndInitializationNotOnSeparateLines.expected

+1
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@
2626
| test.cpp:66:12:66:12 | definition of g | Expression statement and identifier are on the same line. |
2727
| test.cpp:82:7:82:10 | definition of S3_a | Expression statement and identifier are on the same line. |
2828
| test.cpp:82:17:82:20 | definition of S3_b | Expression statement and identifier are on the same line. |
29+
| test.cpp:154:24:154:24 | definition of y | Expression statement and identifier are on the same line. |

cpp/autosar/test/rules/A7-1-7/test.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,9 @@ struct s_357 {
147147
// clang-format on
148148
}
149149
};
150+
151+
void example_function() { f1(); } // COMPLIANT
152+
153+
// clang-format off
154+
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

0 commit comments

Comments
 (0)