Merge pull request #788 from fjatWbyT/fix-issue-629

Fix #629 about `A7-1-7`
This commit is contained in:
Luke Cartey 2024-11-15 11:08:59 +00:00 коммит произвёл GitHub
Родитель cc7df812b4 301d133844
Коммит 6bd9ed7e3c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 34 добавлений и 20 удалений

Просмотреть файл

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

Просмотреть файл

@ -19,26 +19,28 @@ import codingstandards.cpp.autosar
class UniqueLineStmt extends Locatable {
UniqueLineStmt() {
not isAffectedByMacro() and
exists(Declaration d |
this = d.getADeclarationEntry() and
not d instanceof Parameter and
not d instanceof TemplateParameter and
// TODO - Needs to be enhanced to solve issues with
// templated inner classes.
not d instanceof Function and
not d.isFromTemplateInstantiation(_) and
not d.(Variable).isCompilerGenerated() and
not exists(RangeBasedForStmt f | f.getADeclaration() = d) and
not exists(DeclStmt declStmt, ForStmt f |
f.getInitialization() = declStmt and
declStmt.getADeclaration() = d
) and
not exists(LambdaCapture lc | lc.getField().getADeclarationEntry() = this)
(
exists(Declaration d |
this = d.getADeclarationEntry() and
not d instanceof Parameter and
not d instanceof TemplateParameter and
// TODO - Needs to be enhanced to solve issues with
// templated inner classes.
not d instanceof Function and
not d.isFromTemplateInstantiation(_) and
not d.(Variable).isCompilerGenerated() and
not exists(RangeBasedForStmt f | f.getADeclaration() = d) and
not exists(DeclStmt declStmt, ForStmt f |
f.getInitialization() = declStmt and
declStmt.getADeclaration() = d
) and
not exists(LambdaCapture lc | lc.getField().getADeclarationEntry() = this)
)
or
this instanceof ExprStmt and
not exists(ForStmt f | f.getInitialization().getAChild*() = this) and
not exists(LambdaExpression l | l.getLambdaFunction().getBlock().getAChild*() = this)
)
or
this instanceof ExprStmt and
not exists(ForStmt f | f.getInitialization().getAChild*() = this) and
not exists(LambdaExpression l | l.getLambdaFunction().getBlock().getAChild*() = this)
}
}

Просмотреть файл

@ -152,4 +152,14 @@ 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
// clang-format on
#define foo(x, y) \
x++; \
y++;
void test_foo() {
int a = 1;
int b = 1;
foo(a, b); // COMPLIANT
}