@@ -12,7 +12,7 @@ ERR3 = 'Cast removed _Atomic qualification from %1'
1212
1313
1414def ids():
15- return ('MISRA08_5-2-5', 'MISRA12_11.8', 'A5-2-3', 'CPP_T021', 'MISRA23_8.2.3', 'MISRA23_11.8', 'MISRA25_11.8')
15+ return ('MISRA08_5-2-5', 'MISRA12_11.8', 'A5-2-3', 'CPP_T021', 'MISRA23_8.2.3', 'MISRA23_11.8', 'MISRA25_11.8', 'MISRA04_11.5' )
1616
1717
1818def name(id):
@@ -31,6 +31,8 @@ A cast shall not remove any const or volatile qualification from the type of a p
313111.8 A conversion shall not remove any const, volatile or _Atomic qualification from the type pointed to by a pointer',
3232 'MISRA25_11.8': 'Published Standards/MISRA C 2025/\
333311.8 A conversion shall not remove any const, volatile or _Atomic qualification from the type pointed to by a pointer',
34+ 'MISRA04_11.5': 'Published Standards/MISRA-C 2004/\
35+ 11.5 A cast shall not be performed that removes any const or volatile qualification from the type addressed by a pointer',
3436 }[id]
3537
3638
@@ -84,6 +86,12 @@ def tags(id):
8486 'Category: Required',
8587 'Types',
8688 ],
89+ 'MISRA04_11.5': [
90+ 'Language: C',
91+ 'Standard: MISRA C 2004',
92+ 'Category: Required',
93+ 'Types',
94+ ],
8795 }.get(id)
8896
8997
@@ -342,6 +350,34 @@ int main( void )
342350
343351<p><b>See also</b></p>
344352<p>Rule 11.3, Rule 11.10</p>''',
353+
354+ 'MISRA04_11.5': '''\
355+ <p><b>Title</b></p>
356+ <p>A cast shall not be performed that removes any const or volatile
357+ qualification from the type addressed by a pointer.</p>
358+
359+ <p><b>Rationale</b></p>
360+ <p>Any attempt to remove the qualification associated with the addressed type by
361+ using casting is a violation of the principle of type qualification. Notice that
362+ the qualification referred to here is not the same as any qualification that may
363+ be applied to the pointer itself.</p>
364+
365+ <p><b>Example</b></p>
366+ <pre><code language="C++"> uint16_t x;
367+ uint16_t * const cpi = &x; /* const pointer */
368+ uint16_t * const *pcpi; /* pointer to const pointer */
369+ uint16_t * *ppi;
370+ const uint16_t *pci; /* pointer to const */
371+ volatile uint16_t *pvi; /* pointer to volatile */
372+ uint16_t *pi;
373+
374+ pi = cpi; /* Compliant - no conversion
375+ no cast required */
376+
377+ pi = (uint16_t *)pci; /* Not compliant */
378+ pi = (uint16_t *)pvi; /* Not compliant */
379+ ppi = (uint16_t * *)pcpi; /* Not compliant */
380+ </code></pre>''',
345381 }[id]
346382
347383
0 commit comments