Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@
"Strings3",
"Syntax",
"Templates",
"Trigraph",
"TypeRanges",
"Lambdas",
"Pointers",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import Statements
import Strings
import Templates
import Toolchain
import Trigraph
import TrustBoundaries
import TypeRanges
import Uninitialized
Expand Down Expand Up @@ -123,6 +124,7 @@ newtype TCPPQuery =
TStringsPackageQuery(StringsQuery q) or
TTemplatesPackageQuery(TemplatesQuery q) or
TToolchainPackageQuery(ToolchainQuery q) or
TTrigraphPackageQuery(TrigraphQuery q) or
TTrustBoundariesPackageQuery(TrustBoundariesQuery q) or
TTypeRangesPackageQuery(TypeRangesQuery q) or
TUninitializedPackageQuery(UninitializedQuery q) or
Expand Down Expand Up @@ -187,6 +189,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat
isStringsQueryMetadata(query, queryId, ruleId, category) or
isTemplatesQueryMetadata(query, queryId, ruleId, category) or
isToolchainQueryMetadata(query, queryId, ruleId, category) or
isTrigraphQueryMetadata(query, queryId, ruleId, category) or
isTrustBoundariesQueryMetadata(query, queryId, ruleId, category) or
isTypeRangesQueryMetadata(query, queryId, ruleId, category) or
isUninitializedQueryMetadata(query, queryId, ruleId, category) or
Expand Down
26 changes: 26 additions & 0 deletions cpp/common/src/codingstandards/cpp/exclusions/cpp/Trigraph.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/
import cpp
import RuleMetadata
import codingstandards.cpp.exclusions.RuleMetadata

newtype TrigraphQuery = TTrigraphLikeSequencesShouldNotBeUsedQuery()

predicate isTrigraphQueryMetadata(Query query, string queryId, string ruleId, string category) {
query =
// `Query` instance for the `trigraphLikeSequencesShouldNotBeUsed` query
TrigraphPackage::trigraphLikeSequencesShouldNotBeUsedQuery() and
queryId =
// `@id` for the `trigraphLikeSequencesShouldNotBeUsed` query
"cpp/misra/trigraph-like-sequences-should-not-be-used" and
ruleId = "RULE-5-0-1" and
category = "advisory"
}

module TrigraphPackage {
Query trigraphLikeSequencesShouldNotBeUsedQuery() {
//autogenerate `Query` type
result =
// `Query` type for `trigraphLikeSequencesShouldNotBeUsed` query
TQueryCPP(TTrigraphPackageQuery(TTrigraphLikeSequencesShouldNotBeUsedQuery()))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @id cpp/misra/trigraph-like-sequences-should-not-be-used
* @name RULE-5-0-1: Trigraph-like sequences should not be used
* @description Using trigraph-like sequences can lead to developer confusion.
* @kind problem
* @precision medium
* @problem.severity warning
* @tags external/misra/id/rule-5-0-1
* readability
* scope/single-translation-unit
* external/misra/enforcement/decidable
* external/misra/obligation/advisory
*/

import cpp
import codingstandards.cpp.misra

from StringLiteral s, int occurrenceOffset
where
not isExcluded(s, TrigraphPackage::trigraphLikeSequencesShouldNotBeUsedQuery()) and
exists(s.getValue().regexpFind("\\?\\?[=/'()!<>-]", _, occurrenceOffset)) and
//one escape character is enough to mean this isnt a trigraph-like sequence
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment //one escape character is enough to mean this isnt a trigraph-like sequence contains a spelling/grammar issue; isnt should be written as isn't for clarity and consistency with surrounding documentation comments.

Suggested change
//one escape character is enough to mean this isnt a trigraph-like sequence
//one escape character is enough to mean this isn't a trigraph-like sequence

Copilot uses AI. Check for mistakes.
not exists(s.getASimpleEscapeSequence(_, occurrenceOffset + 1))
select s, "Trigraph-like sequence used in string literal."
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
| test.cpp:1:17:1:21 | ??= | Trigraph-like sequence used in string literal. |
| test.cpp:2:18:2:22 | ??/ | Trigraph-like sequence used in string literal. |
| test.cpp:3:18:3:22 | ??' | Trigraph-like sequence used in string literal. |
| test.cpp:4:18:4:22 | ??( | Trigraph-like sequence used in string literal. |
| test.cpp:5:18:5:22 | ??) | Trigraph-like sequence used in string literal. |
| test.cpp:6:18:6:22 | ??! | Trigraph-like sequence used in string literal. |
| test.cpp:7:18:7:22 | ??< | Trigraph-like sequence used in string literal. |
| test.cpp:8:18:8:22 | ??> | Trigraph-like sequence used in string literal. |
| test.cpp:9:18:9:22 | ??- | Trigraph-like sequence used in string literal. |
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rules/RULE-5-0-1/TrigraphLikeSequencesShouldNotBeUsed.ql
12 changes: 12 additions & 0 deletions cpp/misra/test/rules/RULE-5-0-1/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const char *g = "??="; // NON_COMPLIANT
const char *g1 = "??/"; // NON_COMPLIANT
const char *g2 = "??'"; // NON_COMPLIANT
const char *g3 = "??("; // NON_COMPLIANT
const char *g4 = "??)"; // NON_COMPLIANT
const char *g5 = "??!"; // NON_COMPLIANT
const char *g6 = "??<"; // NON_COMPLIANT
const char *g7 = "??>"; // NON_COMPLIANT
const char *g8 = "??-"; // NON_COMPLIANT

const char *g9 = "\?\?="; // COMPLIANT
const char *g10 = "?="; // COMPLIANT
28 changes: 28 additions & 0 deletions rule_packages/cpp/Trigraph.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"MISRA-C++-2023": {
"RULE-5-0-1": {
"properties": {
"enforcement": "decidable",
"obligation": "advisory"
},
"queries": [
{
"description": "Using trigraph-like sequences can lead to developer confusion.",
"kind": "problem",
"name": "Trigraph-like sequences should not be used",
"precision": "medium",
"severity": "warning",
"short_name": "TrigraphLikeSequencesShouldNotBeUsed",
"tags": [
"readability",
"scope/single-translation-unit"
],
"implementation_scope": {
"description": "The rule checks within string literals only for trigraph-like sequences."
}
}
],
"title": "Trigraph-like sequences should not be used"
}
}
}
Loading