diff --git a/change_notes/2024-07-05-fix-fp628-630.md b/change_notes/2024-07-05-fix-fp628-630.md new file mode 100644 index 0000000000..8f0517f708 --- /dev/null +++ b/change_notes/2024-07-05-fix-fp628-630.md @@ -0,0 +1,3 @@ +- `A7-1-7` - `IdentifierDeclarationAndInitializationNotOnSeparateLines.ql`: + - Fixes #628. Excludes Functions. + - Fixes #630. Excludes struct identifiers and variables on the same line when a typedef is used. \ No newline at end of file diff --git a/cpp/autosar/src/rules/A7-1-7/IdentifierDeclarationAndInitializationNotOnSeparateLines.ql b/cpp/autosar/src/rules/A7-1-7/IdentifierDeclarationAndInitializationNotOnSeparateLines.ql index d33d3d8e71..8c10a0f80c 100644 --- a/cpp/autosar/src/rules/A7-1-7/IdentifierDeclarationAndInitializationNotOnSeparateLines.ql +++ b/cpp/autosar/src/rules/A7-1-7/IdentifierDeclarationAndInitializationNotOnSeparateLines.ql @@ -23,12 +23,10 @@ class UniqueLineStmt extends Locatable { this = d.getADeclarationEntry() and not d instanceof Parameter and not d instanceof TemplateParameter and - not d instanceof FunctionTemplateSpecialization and // TODO - Needs to be enhanced to solve issues with // templated inner classes. - not d instanceof MemberFunction and + not d instanceof Function and not d.isFromTemplateInstantiation(_) and - not d.(Function).isCompilerGenerated() and not d.(Variable).isCompilerGenerated() and not exists(RangeBasedForStmt f | f.getADeclaration() = d) and not exists(DeclStmt declStmt, ForStmt f | @@ -52,6 +50,9 @@ where DeclarationsPackage::identifierDeclarationAndInitializationNotOnSeparateLinesQuery()) and not e1 = e2 and not e1.(DeclarationEntry) = e2 and + //omit the cases where there is one struct identifier on a struct var line used with typedef + not exists(Struct s | s.getADeclarationEntry() = e1 and e1 instanceof TypeDeclarationEntry) and + not exists(Struct s | s.getATypeNameUse() = e1 and e1 instanceof TypeDeclarationEntry) and exists(Location l1, Location l2 | e1.getLocation() = l1 and e2.getLocation() = l2 and diff --git a/cpp/autosar/test/rules/A7-1-7/IdentifierDeclarationAndInitializationNotOnSeparateLines.expected b/cpp/autosar/test/rules/A7-1-7/IdentifierDeclarationAndInitializationNotOnSeparateLines.expected index c7abb3ce6f..b84f71e952 100644 --- a/cpp/autosar/test/rules/A7-1-7/IdentifierDeclarationAndInitializationNotOnSeparateLines.expected +++ b/cpp/autosar/test/rules/A7-1-7/IdentifierDeclarationAndInitializationNotOnSeparateLines.expected @@ -26,3 +26,4 @@ | test.cpp:66:12:66:12 | definition of g | Expression statement and identifier are on the same line. | | test.cpp:82:7:82:10 | definition of S3_a | Expression statement and identifier are on the same line. | | test.cpp:82:17:82:20 | definition of S3_b | Expression statement and identifier are on the same line. | +| test.cpp:154:24:154:24 | definition of y | Expression statement and identifier are on the same line. | diff --git a/cpp/autosar/test/rules/A7-1-7/test.cpp b/cpp/autosar/test/rules/A7-1-7/test.cpp index de6e013291..7c5a6263cf 100644 --- a/cpp/autosar/test/rules/A7-1-7/test.cpp +++ b/cpp/autosar/test/rules/A7-1-7/test.cpp @@ -147,3 +147,9 @@ struct s_357 { // clang-format on } }; + +void example_function() { f1(); } // COMPLIANT + +// clang-format off +typedef struct x { int y; } z; //COMPLIANT - for struct typedef and struct var //NON_COMPLIANT - for struct all on one line +// clang-format on \ No newline at end of file