Skip to content

Commit e4b4e4b

Browse files
committed
Add Banned6 and improve @description metadata of A9-5-1
1 parent cd095be commit e4b4e4b

File tree

13 files changed

+114
-3
lines changed

13 files changed

+114
-3
lines changed

cpp/autosar/src/rules/A9-5-1/UnionsUsed.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @id cpp/autosar/unions-used
33
* @name A9-5-1: Unions shall not be used
4-
* @description Unions shall not be used. Tagged untions can be used if std::variant is not
4+
* @description Unions shall not be used. Tagged unions can be used if 'std::variant' is not
55
* available.
66
* @kind problem
77
* @precision very-high
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cpp/common/test/rules/unionkeywordused/UnionKeywordUsed.ql
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 Banned6Query = TUnionKeywordUsedQuery()
7+
8+
predicate isBanned6QueryMetadata(Query query, string queryId, string ruleId, string category) {
9+
query =
10+
// `Query` instance for the `unionKeywordUsed` query
11+
Banned6Package::unionKeywordUsedQuery() and
12+
queryId =
13+
// `@id` for the `unionKeywordUsed` query
14+
"cpp/misra/union-keyword-used" and
15+
ruleId = "RULE-12-3-1" and
16+
category = "required"
17+
}
18+
19+
module Banned6Package {
20+
Query unionKeywordUsedQuery() {
21+
//autogenerate `Query` type
22+
result =
23+
// `Query` type for `unionKeywordUsed` query
24+
TQueryCPP(TBanned6PackageQuery(TUnionKeywordUsedQuery()))
25+
}
26+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import codingstandards.cpp.exclusions.RuleMetadata
55
import Allocations
66
import Banned1
77
import Banned5
8+
import Banned6
89
import Banned8
910
import BannedAPIs
1011
import BannedFunctions
@@ -98,6 +99,7 @@ newtype TCPPQuery =
9899
TAllocationsPackageQuery(AllocationsQuery q) or
99100
TBanned1PackageQuery(Banned1Query q) or
100101
TBanned5PackageQuery(Banned5Query q) or
102+
TBanned6PackageQuery(Banned6Query q) or
101103
TBanned8PackageQuery(Banned8Query q) or
102104
TBannedAPIsPackageQuery(BannedAPIsQuery q) or
103105
TBannedFunctionsPackageQuery(BannedFunctionsQuery q) or
@@ -191,6 +193,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat
191193
isAllocationsQueryMetadata(query, queryId, ruleId, category) or
192194
isBanned1QueryMetadata(query, queryId, ruleId, category) or
193195
isBanned5QueryMetadata(query, queryId, ruleId, category) or
196+
isBanned6QueryMetadata(query, queryId, ruleId, category) or
194197
isBanned8QueryMetadata(query, queryId, ruleId, category) or
195198
isBannedAPIsQueryMetadata(query, queryId, ruleId, category) or
196199
isBannedFunctionsQueryMetadata(query, queryId, ruleId, category) or
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Provides a configurable module UnionKeywordUsed with a `problems` predicate
3+
* for the following issue:
4+
* Unions shall not be used. Tagged unions can be used if 'std::variant' is not
5+
* available.
6+
*/
7+
8+
import cpp
9+
import codingstandards.cpp.Customizations
10+
import codingstandards.cpp.Exclusions
11+
12+
signature module UnionKeywordUsedConfigSig {
13+
Query getQuery();
14+
}
15+
16+
module UnionKeywordUsed<UnionKeywordUsedConfigSig Config> {
17+
query predicate problems(Element e, string message) {
18+
not isExcluded(e, Config::getQuery()) and message = "<replace with problem alert message for >"
19+
}
20+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
No expected results have yet been specified
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.unionkeywordused.UnionKeywordUsed
3+
4+
module TestFileConfig implements UnionKeywordUsedConfigSig {
5+
Query getQuery() { result instanceof TestQuery }
6+
}
7+
8+
import UnionKeywordUsed<TestFileConfig>

cpp/common/test/rules/unionkeywordused/test.cpp

Whitespace-only changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @id cpp/misra/union-keyword-used
3+
* @name RULE-12-3-1: The union keyword shall not be used
4+
* @description Using unions should be avoided and 'std::variant' should be used as a type-safe
5+
* alternative.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity error
9+
* @tags external/misra/id/rule-12-3-1
10+
* scope/single-translation-unit
11+
* correctness
12+
* external/misra/enforcement/decidable
13+
* external/misra/obligation/required
14+
*/
15+
16+
import cpp
17+
import codingstandards.cpp.misra
18+
import codingstandards.cpp.rules.unionkeywordused.UnionKeywordUsed
19+
20+
module UnionKeywordUsedConfig implements UnionKeywordUsedConfigSig {
21+
Query getQuery() { result = Banned6Package::unionKeywordUsedQuery() }
22+
}
23+
24+
import UnionKeywordUsed<UnionKeywordUsedConfig>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cpp/common/test/rules/unionkeywordused/UnionKeywordUsed.ql

0 commit comments

Comments
 (0)