Rule Definition
Trigraphs are denoted to be a sequence of 2 question marks followed by a specified third character (e.g. ??’ represents a ~character. They can cause accidental confusion with other uses of two question marks.
The Trigraphs are: ??=, ??/, ??’, ??(, ??), ??!, ??<, ??>, ??-.
Remediation
Do not use Trigraphs
Violation Code Sample
#include <iostream>
void fn1()
{
std::cout << "Enter date ??/??/??"; // VIOLATION, ??/??/?? becomes \\??
// after trigraph translation
}
void fn2()
{
std::cout << "Enter date dd/mm/yy"; // Compliant
Fixed Code Sample
void fn2()
{
std::cout << "Enter date dd/mm/yy"; // VIOLATION FIXED
}
Reference
MISRA C++, 2008, Rule 2–3–1: Trigraphs shall not be used.
AUTOSAR 2014, C++, Rule A2-5-1: Trigraphs shall not be used.
MISRA C, 2012, 4.2: Trigraphs should not be used.
Related Technologies
Technical Criterion
Programming Practices - Unexpected Behavior
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.