docs/misra: add Rule 7.4 and 9.4
PATCH 1/1 docs/misra: add Rule 7.4 and 9.4
From: Stefano Stabellini <[email protected]>
Rule 9.4 is non-controversial and we have no violations.
Rule 7.4 is considered a good idea with the caveat that assigning a string literal to const void is allowed. I added a note to specify it.
--- docs/misra/rules.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+)
docs/misra/rules.rst +12 -0
@@ -203,6 +203,13 @@ maintainers if you want to suggest a change. - The lowercase character l shall not be used in a literal suffix - + * - `Rule 7.4 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_07_04.c>`_ + - Required + - A string literal shall not be assigned to an object unless the + objects type is pointer to const-qualified char + - Assigning a string literal to any object with type + "pointer to const-qualified void" is allowed + * - `Rule 8.1 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_08_01.c>`_ - Required - Types shall be explicitly specified
@@ -275,6 +282,11 @@ maintainers if you want to suggest a change. braces - + * - `Rule 9.4 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_09_04.c>`_ + - Required + - An element of an object shall not be initialized more than once + - + * - `Rule 12.5 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_12_05.c>`_ - Mandatory - The sizeof operator shall not have an operand which is a function
Signature · 1 line
2.25.1
docs/misra/rules.rst maintainers if you want to suggest a change. · line 211
Quoted 12 lines · Stefano Stabellini
docs/misra/rules.rst +6
-0@@ -203,6 +203,13 @@ maintainers if you want to suggest a change. - The lowercase character l shall not be used in a literal suffix - + * - `Rule 7.4 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_07_04.c>`_ + - Required + - A string literal shall not be assigned to an object unless the + objects type is pointer to const-qualified char + - Assigning a string literal to any object with type + "pointer to const-qualified void" is allowed
I guess this is relevant also in a few other cases: Considering the significant difference between title and actual text of the rule, and further assuming people looking here won't always pull out the full doc (they may not even have a copy of it), I think it is important to also mention in a remark that despite the title all "character types" are permitted, as long as string element type and character type match. Since the compiler won't allow mismatches when the lhs type isn't void, mandating no use of casts to "satisfy" the rule may be a way to express our intentions.
Jan
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Stefano Stabellini
docs/misra/rules.rst +0
-0@@ -203,6 +203,13 @@ maintainers if you want to suggest a change. - The lowercase character l shall not be used in a literal suffix -
Quoted 16 lines
docs/misra/rules.rst maintainers if you want to suggest a change. · line 211
Quoted 6 lines
docs/misra/rules.rst +6
-0+ * - `Rule 7.4 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_07_04.c>`_ + - Required + - A string literal shall not be assigned to an object unless the + objects type is pointer to const-qualified char + - Assigning a string literal to any object with type + "pointer to const-qualified void" is allowedI guess this is relevant also in a few other cases: Considering the significant difference between title and actual text of the rule, and further assuming people looking here won't always pull out the full doc (they may not even have a copy of it), I think it is important to also mention in a remark that despite the title all "character types" are permitted, as long as string element type and character type match. Since the compiler won't allow mismatches when the lhs type isn't void, mandating no use of casts to "satisfy" the rule may be a way to express our intentions.
What about:
* - Rule 7.4 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_07_04.c>_
- Required
- A string literal shall not be assigned to an object unless the
objects type is pointer to const-qualified char
- All "character types" are permitted, as long as the string
element type and the character type match. (There should be no
casts.) Assigning a string literal to any object with type
"pointer to const-qualified void" is allowed.
Quoted 27 lines · Stefano Stabellini
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Stefano Stabellini
docs/misra/rules.rst +0
-0@@ -203,6 +203,13 @@ maintainers if you want to suggest a change. - The lowercase character l shall not be used in a literal suffix -Quoted 16 lines
docs/misra/rules.rst maintainers if you want to suggest a change. · line 211
Quoted 6 lines
docs/misra/rules.rst +6
-0+ * - `Rule 7.4 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_07_04.c>`_ + - Required + - A string literal shall not be assigned to an object unless the + objects type is pointer to const-qualified char + - Assigning a string literal to any object with type + "pointer to const-qualified void" is allowedI guess this is relevant also in a few other cases: Considering the significant difference between title and actual text of the rule, and further assuming people looking here won't always pull out the full doc (they may not even have a copy of it), I think it is important to also mention in a remark that despite the title all "character types" are permitted, as long as string element type and character type match. Since the compiler won't allow mismatches when the lhs type isn't void, mandating no use of casts to "satisfy" the rule may be a way to express our intentions.
What about:
Quoted 8 lines
* -
Rule 7.4 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_07_04.c>_
- Required
- A string literal shall not be assigned to an object unless the
objects type is pointer to const-qualified char
- All "character types" are permitted, as long as the string
element type and the character type match. (There should be no
casts.) Assigning a string literal to any object with type
"pointer to const-qualified void" is allowed.
SGTM.
Jan