Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7efdf4c

Browse filesBrowse files
committed
A7-1-7: exclusions
exclude functions exclude struct identifiers and variables when used with typedefs
1 parent 976e01a commit 7efdf4c
Copy full SHA for 7efdf4c

File tree

Expand file treeCollapse file tree

4 files changed

+14
-3
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+14
-3
lines changed
+3Lines changed: 3 additions & 0 deletions
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

Copy file name to clipboardExpand all lines: cpp/autosar/src/rules/A7-1-7/IdentifierDeclarationAndInitializationNotOnSeparateLines.ql
+4-3Lines changed: 4 additions & 3 deletions
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

Copy file name to clipboardExpand all lines: cpp/autosar/test/rules/A7-1-7/IdentifierDeclarationAndInitializationNotOnSeparateLines.expected
+1Lines changed: 1 addition & 0 deletions
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

Copy file name to clipboardExpand all lines: cpp/autosar/test/rules/A7-1-7/test.cpp
+6Lines changed: 6 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.