Skip to content

Commit fe8b779

Browse files
committed
Add declarations package 3 cpp misra 2023
1 parent 69147ac commit fe8b779

File tree

19 files changed

+274
-9
lines changed

19 files changed

+274
-9
lines changed

cpp/autosar/src/rules/M3-1-2/FunctionsDeclaredAtBlockScope.ql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
import cpp
1919
import codingstandards.cpp.autosar
20+
import codingstandards.cpp.rules.functiondeclaredatblockscope.FunctionDeclaredAtBlockScope
2021

21-
from DeclStmt decl, Function f
22-
where
23-
not isExcluded(decl, DeclarationsPackage::functionsDeclaredAtBlockScopeQuery()) and
24-
not isExcluded(f, DeclarationsPackage::functionsDeclaredAtBlockScopeQuery()) and
25-
decl.getADeclaration() = f
26-
select f, "Function " + f.getName() + " is declared at block scope."
22+
module FunctionDeclaredAtBlockScopeConfig implements FunctionDeclaredAtBlockScopeConfigSig {
23+
Query getQuery() { result = DeclarationsPackage::functionsDeclaredAtBlockScopeQuery() }
24+
}
25+
26+
import FunctionDeclaredAtBlockScope<FunctionDeclaredAtBlockScopeConfig>

cpp/autosar/test/rules/M3-1-2/FunctionsDeclaredAtBlockScope.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cpp/common/test/rules/functiondeclaredatblockscope/FunctionDeclaredAtBlockScope.ql
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/
2+
import cpp
3+
import RuleMetadata
4+
import codingstandards.cpp.exclusions.RuleMetadata
5+
6+
newtype Declarations3Query =
7+
TVariableDeclaredArrayTypeQuery() or
8+
TBlockScopeFunctionAmbiguousQuery() or
9+
TBlockScopeObjectAmbiguousQuery()
10+
11+
predicate isDeclarations3QueryMetadata(Query query, string queryId, string ruleId, string category) {
12+
query =
13+
// `Query` instance for the `variableDeclaredArrayType` query
14+
Declarations3Package::variableDeclaredArrayTypeQuery() and
15+
queryId =
16+
// `@id` for the `variableDeclaredArrayType` query
17+
"cpp/misra/variable-declared-array-type" and
18+
ruleId = "RULE-11-3-1" and
19+
category = "advisory"
20+
or
21+
query =
22+
// `Query` instance for the `blockScopeFunctionAmbiguous` query
23+
Declarations3Package::blockScopeFunctionAmbiguousQuery() and
24+
queryId =
25+
// `@id` for the `blockScopeFunctionAmbiguous` query
26+
"cpp/misra/block-scope-function-ambiguous" and
27+
ruleId = "RULE-6-0-1" and
28+
category = "required"
29+
or
30+
query =
31+
// `Query` instance for the `blockScopeObjectAmbiguous` query
32+
Declarations3Package::blockScopeObjectAmbiguousQuery() and
33+
queryId =
34+
// `@id` for the `blockScopeObjectAmbiguous` query
35+
"cpp/misra/block-scope-object-ambiguous" and
36+
ruleId = "RULE-6-0-1" and
37+
category = "required"
38+
}
39+
40+
module Declarations3Package {
41+
Query variableDeclaredArrayTypeQuery() {
42+
//autogenerate `Query` type
43+
result =
44+
// `Query` type for `variableDeclaredArrayType` query
45+
TQueryCPP(TDeclarations3PackageQuery(TVariableDeclaredArrayTypeQuery()))
46+
}
47+
48+
Query blockScopeFunctionAmbiguousQuery() {
49+
//autogenerate `Query` type
50+
result =
51+
// `Query` type for `blockScopeFunctionAmbiguous` query
52+
TQueryCPP(TDeclarations3PackageQuery(TBlockScopeFunctionAmbiguousQuery()))
53+
}
54+
55+
Query blockScopeObjectAmbiguousQuery() {
56+
//autogenerate `Query` type
57+
result =
58+
// `Query` type for `blockScopeObjectAmbiguous` query
59+
TQueryCPP(TDeclarations3PackageQuery(TBlockScopeObjectAmbiguousQuery()))
60+
}
61+
}

cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import DeadCode8
3333
import DeadCode9
3434
import Declarations
3535
import Declarations1
36+
import Declarations3
3637
import ExceptionSafety
3738
import Exceptions1
3839
import Exceptions2
@@ -129,6 +130,7 @@ newtype TCPPQuery =
129130
TDeadCode9PackageQuery(DeadCode9Query q) or
130131
TDeclarationsPackageQuery(DeclarationsQuery q) or
131132
TDeclarations1PackageQuery(Declarations1Query q) or
133+
TDeclarations3PackageQuery(Declarations3Query q) or
132134
TExceptionSafetyPackageQuery(ExceptionSafetyQuery q) or
133135
TExceptions1PackageQuery(Exceptions1Query q) or
134136
TExceptions2PackageQuery(Exceptions2Query q) or
@@ -225,6 +227,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat
225227
isDeadCode9QueryMetadata(query, queryId, ruleId, category) or
226228
isDeclarationsQueryMetadata(query, queryId, ruleId, category) or
227229
isDeclarations1QueryMetadata(query, queryId, ruleId, category) or
230+
isDeclarations3QueryMetadata(query, queryId, ruleId, category) or
228231
isExceptionSafetyQueryMetadata(query, queryId, ruleId, category) or
229232
isExceptions1QueryMetadata(query, queryId, ruleId, category) or
230233
isExceptions2QueryMetadata(query, queryId, ruleId, category) or
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Provides a configurable module FunctionDeclaredAtBlockScope with a `problems` predicate
3+
* for the following issue:
4+
* A function declared at block scope can make code harder to read and may lead to
5+
* developer confusion.
6+
*/
7+
8+
import cpp
9+
import codingstandards.cpp.Customizations
10+
import codingstandards.cpp.Exclusions
11+
12+
signature module FunctionDeclaredAtBlockScopeConfigSig {
13+
Query getQuery();
14+
}
15+
16+
module FunctionDeclaredAtBlockScope<FunctionDeclaredAtBlockScopeConfigSig Config> {
17+
query predicate problems(Function f, string message) {
18+
exists(DeclStmt decl |
19+
not isExcluded(decl, Config::getQuery()) and
20+
not isExcluded(f, Config::getQuery()) and
21+
decl.getADeclaration() = f and
22+
message = "Function " + f.getName() + " is declared at block scope."
23+
)
24+
}
25+
}

cpp/common/test/includes/standard-library/string_view

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ typedef basic_string_view<wchar_t> wstring_view;
7575
typedef basic_string_view<char16_t> u16string_view;
7676
typedef basic_string_view<char32_t> u32string_view;
7777

78+
inline namespace literals {
79+
inline namespace string_view_literals {
80+
// suffix for basic_string_view literals
81+
constexpr string_view operator""sv(const char *str, size_t len) noexcept;
82+
} // namespace string_view_literals
83+
} // namespace literals
84+
7885
} // namespace std
7986

8087
#endif // _GHLIBCPP_STRING_VIEW

cpp/autosar/test/rules/M3-1-2/FunctionsDeclaredAtBlockScope.expected renamed to cpp/common/test/rules/functiondeclaredatblockscope/FunctionDeclaredAtBlockScope.expected

File renamed without changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// GENERATED FILE - DO NOT MODIFY
2+
import codingstandards.cpp.rules.functiondeclaredatblockscope.FunctionDeclaredAtBlockScope
3+
4+
module TestFileConfig implements FunctionDeclaredAtBlockScopeConfigSig {
5+
Query getQuery() { result instanceof TestQuery }
6+
}
7+
8+
import FunctionDeclaredAtBlockScope<TestFileConfig>

cpp/autosar/test/rules/M3-1-2/test.cpp renamed to cpp/common/test/rules/functiondeclaredatblockscope/test.cpp

File renamed without changes.

0 commit comments

Comments
 (0)