Skip to content

Commit 568daa7

Browse files
Merge branch 'main' into jeongsoolee09/MISRA-C++-2023-Banned7
2 parents cd9a841 + fd9c1d7 commit 568daa7

25 files changed

+385
-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+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/
2+
import cpp
3+
import RuleMetadata
4+
import codingstandards.cpp.exclusions.RuleMetadata
5+
6+
newtype Declarations4Query = TVolatileQualifierNotUsedAppropriatelyQuery()
7+
8+
predicate isDeclarations4QueryMetadata(Query query, string queryId, string ruleId, string category) {
9+
query =
10+
// `Query` instance for the `volatileQualifierNotUsedAppropriately` query
11+
Declarations4Package::volatileQualifierNotUsedAppropriatelyQuery() and
12+
queryId =
13+
// `@id` for the `volatileQualifierNotUsedAppropriately` query
14+
"cpp/misra/volatile-qualifier-not-used-appropriately" and
15+
ruleId = "RULE-10-1-2" and
16+
category = "required"
17+
}
18+
19+
module Declarations4Package {
20+
Query volatileQualifierNotUsedAppropriatelyQuery() {
21+
//autogenerate `Query` type
22+
result =
23+
// `Query` type for `volatileQualifierNotUsedAppropriately` query
24+
TQueryCPP(TDeclarations4PackageQuery(TVolatileQualifierNotUsedAppropriatelyQuery()))
25+
}
26+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import DeadCode9
3535
import Declarations
3636
import Declarations1
3737
import Declarations2
38+
import Declarations3
39+
import Declarations4
3840
import ExceptionSafety
3941
import Exceptions1
4042
import Exceptions2
@@ -133,6 +135,8 @@ newtype TCPPQuery =
133135
TDeclarationsPackageQuery(DeclarationsQuery q) or
134136
TDeclarations1PackageQuery(Declarations1Query q) or
135137
TDeclarations2PackageQuery(Declarations2Query q) or
138+
TDeclarations3PackageQuery(Declarations3Query q) or
139+
TDeclarations4PackageQuery(Declarations4Query q) or
136140
TExceptionSafetyPackageQuery(ExceptionSafetyQuery q) or
137141
TExceptions1PackageQuery(Exceptions1Query q) or
138142
TExceptions2PackageQuery(Exceptions2Query q) or
@@ -231,6 +235,8 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat
231235
isDeclarationsQueryMetadata(query, queryId, ruleId, category) or
232236
isDeclarations1QueryMetadata(query, queryId, ruleId, category) or
233237
isDeclarations2QueryMetadata(query, queryId, ruleId, category) or
238+
isDeclarations3QueryMetadata(query, queryId, ruleId, category) or
239+
isDeclarations4QueryMetadata(query, queryId, ruleId, category) or
234240
isExceptionSafetyQueryMetadata(query, queryId, ruleId, category) or
235241
isExceptions1QueryMetadata(query, queryId, ruleId, category) or
236242
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>

0 commit comments

Comments
 (0)