Skip to content

Commit 871ef6f

Browse files
authored
Merge pull request #1099 from knewbury01/knewbury01/cpp-misra2023-declarations3
Declarations3 cpp misra 2023
2 parents b234b22 + 0c70684 commit 871ef6f

File tree

19 files changed

+262
-14
lines changed

19 files changed

+262
-14
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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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()
9+
10+
predicate isDeclarations3QueryMetadata(Query query, string queryId, string ruleId, string category) {
11+
query =
12+
// `Query` instance for the `variableDeclaredArrayType` query
13+
Declarations3Package::variableDeclaredArrayTypeQuery() and
14+
queryId =
15+
// `@id` for the `variableDeclaredArrayType` query
16+
"cpp/misra/variable-declared-array-type" and
17+
ruleId = "RULE-11-3-1" and
18+
category = "advisory"
19+
or
20+
query =
21+
// `Query` instance for the `blockScopeFunctionAmbiguous` query
22+
Declarations3Package::blockScopeFunctionAmbiguousQuery() and
23+
queryId =
24+
// `@id` for the `blockScopeFunctionAmbiguous` query
25+
"cpp/misra/block-scope-function-ambiguous" and
26+
ruleId = "RULE-6-0-1" and
27+
category = "required"
28+
}
29+
30+
module Declarations3Package {
31+
Query variableDeclaredArrayTypeQuery() {
32+
//autogenerate `Query` type
33+
result =
34+
// `Query` type for `variableDeclaredArrayType` query
35+
TQueryCPP(TDeclarations3PackageQuery(TVariableDeclaredArrayTypeQuery()))
36+
}
37+
38+
Query blockScopeFunctionAmbiguousQuery() {
39+
//autogenerate `Query` type
40+
result =
41+
// `Query` type for `blockScopeFunctionAmbiguous` query
42+
TQueryCPP(TDeclarations3PackageQuery(TBlockScopeFunctionAmbiguousQuery()))
43+
}
44+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import DeadCode9
3434
import Declarations
3535
import Declarations1
3636
import Declarations2
37+
import Declarations3
3738
import ExceptionSafety
3839
import Exceptions1
3940
import Exceptions2
@@ -131,6 +132,7 @@ newtype TCPPQuery =
131132
TDeclarationsPackageQuery(DeclarationsQuery q) or
132133
TDeclarations1PackageQuery(Declarations1Query q) or
133134
TDeclarations2PackageQuery(Declarations2Query q) or
135+
TDeclarations3PackageQuery(Declarations3Query q) or
134136
TExceptionSafetyPackageQuery(ExceptionSafetyQuery q) or
135137
TExceptions1PackageQuery(Exceptions1Query q) or
136138
TExceptions2PackageQuery(Exceptions2Query q) or
@@ -228,6 +230,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat
228230
isDeclarationsQueryMetadata(query, queryId, ruleId, category) or
229231
isDeclarations1QueryMetadata(query, queryId, ruleId, category) or
230232
isDeclarations2QueryMetadata(query, queryId, ruleId, category) or
233+
isDeclarations3QueryMetadata(query, queryId, ruleId, category) or
231234
isExceptionSafetyQueryMetadata(query, queryId, ruleId, category) or
232235
isExceptions1QueryMetadata(query, queryId, ruleId, category) or
233236
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)