<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title><![CDATA[MISRA Discussion Forums - 4.0 Language independent issues]]></title>
		<link>https://forum.misra.org.uk/</link>
		<description><![CDATA[MISRA Discussion Forums - https://forum.misra.org.uk]]></description>
		<pubDate>Thu, 05 Nov 2026 13:03:25 +0000</pubDate>
		<generator>MyBB</generator>
		<item>
			<title><![CDATA[Rule 0.1.1 Example f4]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1787</link>
			<pubDate>Wed, 30 Sep 2026 12:05:20 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=5614">cgpzs</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1787</guid>
			<description><![CDATA[Hi,<br />
<br />
In MISRA C++:2023 TC1 Rule 0.1.1, the comment about example f4() says:<br />
<br />
<span style="font-style: italic;" class="mycode_i">As j is only incremented, no value is overwritten without first being read. Additionally, all iterations</span><br />
<span style="font-style: italic;" class="mycode_i">of the loop other than the first observe j after it has been incremented, meaning the write in the</span><br />
<span style="font-style: italic;" class="mycode_i">increment is necessary.</span><br />
<br />
This is not technically correct: the *last* iteration of the loop will *not* observe the value of j after it has been incremented. Do you consider that the last increment of "j" violates Rule 0.1.1?<br />
<br />
What about this?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>template &lt;int n&gt;<br />
void f()<br />
{<br />
  int j = 0;<br />
  for (int i = 0; i &lt; n; ++i)<br />
  {<br />
    use(j);<br />
    j++;  // Violates Rule 0.1.1 for n == 1?<br />
  }<br />
}</code></div></div><br />
The above code never uses the incremented value of "j" for a template instantiation with "n = 1". Is that a violation of Rule 0.1.1?<br />
<hr class="mycode_hr" />
I see now that this exact use case was explicitly allowed in the original MISRA C++:2023 document, but removed in the TC1.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>Within a loop, a value may be written to an object with the intent that it will be observed during the<br />
next iteration, meaning that the value written on the last iteration may never be observed. Whilst it is<br />
possible to restructure the loop to avoid this behaviour, there is a risk that the resulting code may be<br />
of lower quality (less clear, for example). This rule therefore considers observation during any iteration<br />
to apply to all values written to such an object, including a value written during the last iteration of a<br />
loop that is not actually observed — see example f3, below.</code></div></div>]]></description>
			<content:encoded><![CDATA[Hi,<br />
<br />
In MISRA C++:2023 TC1 Rule 0.1.1, the comment about example f4() says:<br />
<br />
<span style="font-style: italic;" class="mycode_i">As j is only incremented, no value is overwritten without first being read. Additionally, all iterations</span><br />
<span style="font-style: italic;" class="mycode_i">of the loop other than the first observe j after it has been incremented, meaning the write in the</span><br />
<span style="font-style: italic;" class="mycode_i">increment is necessary.</span><br />
<br />
This is not technically correct: the *last* iteration of the loop will *not* observe the value of j after it has been incremented. Do you consider that the last increment of "j" violates Rule 0.1.1?<br />
<br />
What about this?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>template &lt;int n&gt;<br />
void f()<br />
{<br />
  int j = 0;<br />
  for (int i = 0; i &lt; n; ++i)<br />
  {<br />
    use(j);<br />
    j++;  // Violates Rule 0.1.1 for n == 1?<br />
  }<br />
}</code></div></div><br />
The above code never uses the incremented value of "j" for a template instantiation with "n = 1". Is that a violation of Rule 0.1.1?<br />
<hr class="mycode_hr" />
I see now that this exact use case was explicitly allowed in the original MISRA C++:2023 document, but removed in the TC1.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>Within a loop, a value may be written to an object with the intent that it will be observed during the<br />
next iteration, meaning that the value written on the last iteration may never be observed. Whilst it is<br />
possible to restructure the loop to avoid this behaviour, there is a risk that the resulting code may be<br />
of lower quality (less clear, for example). This rule therefore considers observation during any iteration<br />
to apply to all values written to such an object, including a value written during the last iteration of a<br />
loop that is not actually observed — see example f3, below.</code></div></div>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Clarification Rule 0.2.1]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1779</link>
			<pubDate>Thu, 27 Aug 2026 11:32:03 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=5889">hahn</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1779</guid>
			<description><![CDATA[Hi,<br />
<br />
I have a question regarding rule 0.2.1 on the following code:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>namespace {<br />
<br />
struct Base {<br />
  Base() {<br />
    // do resource management<br />
  }<br />
};<br />
<br />
struct Derived : public Base {<br />
  // has implicit default constructor that calls user-provided Base()<br />
};<br />
<br />
Base b; // (1) compliant<br />
Derived d; // (2) compliant or non-compliant for rule 0.2.1 ?<br />
<br />
}</code></div></div><br />
Case (1) is clearly compliant as b has class type Base and Base has a user-provided constructor.<br />
Case (2) is unclear, as the default constructor of Derived is not user-provided, if I understand the C++ standard correctly, as the user does not declare it at all.<br />
Still case (2) seems fine and in line with the rule's rationale.<br />
<br />
It would be great to get a clarification whether case (2) is considered compliant or not, and if compliant, what the intended definition of "use" should be.<br />
Thanks a lot!]]></description>
			<content:encoded><![CDATA[Hi,<br />
<br />
I have a question regarding rule 0.2.1 on the following code:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>namespace {<br />
<br />
struct Base {<br />
  Base() {<br />
    // do resource management<br />
  }<br />
};<br />
<br />
struct Derived : public Base {<br />
  // has implicit default constructor that calls user-provided Base()<br />
};<br />
<br />
Base b; // (1) compliant<br />
Derived d; // (2) compliant or non-compliant for rule 0.2.1 ?<br />
<br />
}</code></div></div><br />
Case (1) is clearly compliant as b has class type Base and Base has a user-provided constructor.<br />
Case (2) is unclear, as the default constructor of Derived is not user-provided, if I understand the C++ standard correctly, as the user does not declare it at all.<br />
Still case (2) seems fine and in line with the rule's rationale.<br />
<br />
It would be great to get a clarification whether case (2) is considered compliant or not, and if compliant, what the intended definition of "use" should be.<br />
Thanks a lot!]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 0.1.2 - missing exceptions and advisory ?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1746</link>
			<pubDate>Thu, 07 Aug 2025 22:07:31 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=5871">kth</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1746</guid>
			<description><![CDATA[Hi,<br />
<br />
The amplification of MISRA C++:2023 rule 0.1.2 states that <span style="font-style: italic;" class="mycode_i">“This rule only applies when the function is called explicitly using function call syntax”</span>.<br />
Consequently, operators like “+=” are out of scope so in the following code the modification of the std:<img src="https://forum.misra.org.uk/images/smilies/confused.png" alt="Confused" title="Confused" class="smilie smilie_13" />tring object with “+=” is fine and the usage of append, without checking the returned reference, is a violation of this required rule:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void example1() {<br />
    // Non-compliant use of std::string::append<br />
    std::string my_string;<br />
    my_string.append("foo");  // add 'foo'<br />
    my_string.append("bar");  // add 'bar'<br />
}<br />
<br />
void example2() {<br />
    // Compliant use of std::string::operator+=:<br />
    std::string my_string;<br />
    my_string += "foo";  // add 'foo'<br />
    my_string += "bar";  // add 'bar'<br />
}<br />
<br />
void example3() {<br />
    std::vector&lt;int&gt; numbers;<br />
<br />
    numbers.push_back(1);  // Compliant to MISRA C++:2023 Rule 0.1.2 <br />
                           // as push_back ""returns"" void<br />
<br />
    // C++ reference: https://en.cppreference.com/w/cpp/container/vector/push_back.html<br />
<br />
    // emplace_back returns (since C++17) an iterator:<br />
    // https://en.cppreference.com/w/cpp/container/vector/emplace_back.html<br />
<br />
    numbers.emplace_back(2);  // Non-compliant to MISRA C++:2023 Rule 0.1.2 (since C++17)<br />
}</code></div></div><br />
The function <span style="font-style: italic;" class="mycode_i">append</span> of std:<img src="https://forum.misra.org.uk/images/smilies/confused.png" alt="Confused" title="Confused" class="smilie smilie_13" />tring (std::basic_string) and the <span style="font-style: italic;" class="mycode_i">operator+=</span> append additional characters to the end of the string. Both return a reference to “*this”. Both throw std::length_error if the operation would cause size() to exceed max_size() and provide the strong exception safety guarantee. So, there is no real difference between using “+=” or “append” in terms of safety or code quality. If one wants to write compliant code, example1 needs to be refactored to use a void cast  to ignore the result:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void example1_compliant_version() {<br />
    std::string my_string;<br />
    static_cast&lt;void&gt;(my_string.append("foo"));  // add 'foo'<br />
    static_cast&lt;void&gt;(my_string.append("bar"));  // add 'bar'<br />
}</code></div></div><br />
That would implicitly force developers to always prefer operators like “+=” over functions like “append” as the alternatives make the code harder to read or lead to additional effort (deviations need to be justified).<br />
<br />
If one decides to rework this kind of code to a “fluent API style” that could lead to extra copies:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>std::string BuildFailureMsg(std::string_view name, std::string_view reason) {<br />
    std::string msg{};<br />
    msg.reserve(name.size() + reason.size() + 26);  // reserve sufficient memory<br />
    msg.append("Component ");<br />
    msg.append(name);<br />
    msg.append(" failed due to ");<br />
    msg.append(reason);<br />
    msg.append("&#92;n");<br />
    return msg;<br />
}<br />
std::string BuildFailureMsgNaiveRefactor(std::string_view name,<br />
                                      std::string_view reason) {<br />
    std::string msg{};<br />
    msg.reserve(name.size() + reason.size() + 26);  // reserve sufficient memory<br />
    return msg.append("Component ")<br />
        .append(name)<br />
        .append(" failed due to ")<br />
        .append(reason)<br />
        .append("&#92;n"); // will create and return copy of msg (i.e. see extra "memcpy")<br />
}<br />
int main() {<br />
    std::string failure_msg_01 = BuildFailureMsg("Logger", "insufficient memory");  // no copies/moves<br />
    std::string failure_msg_02 = BuildFailureMsgNaiveRefactor("Logger", "insufficient memory");  // extra copy<br />
}</code></div></div><br />
Consequently, existing code that uses append needs to be refactored to use “+=”. A huge refactoring effort for large code bases, but without any real benefit.<br />
Also, it might lead to the negative effect that developers that uses std::vector prefer “push_back” over “emplace_back”, as with C++17 std::vector::emplace_back returns a reference (example3). Other alternatives might lead to less efficient code. <br />
<br />
Our questions:<br />
<ol type="1" class="mycode_list"><li><span style="font-size: 1pt;" class="mycode_size"><span style="font-family: Times New Roman;" class="mycode_font">      </span></span>Is it really intended to promote the usage of operators over functions and (for std::vector and other std-library types like std::optional::emplace) to use push_back over emplace_back or are here just exceptions missing?<br />
</li>
<li>As the rationale states that <span style="font-style: italic;" class="mycode_i">“it is <span style="font-weight: bold;" class="mycode_b">possible</span> to call a function without using the return value, which may be an error”</span>, should this rule be changed to “advisory” and the title changed to “<span style="font-style: italic;" class="mycode_i">The value returned by a function should be used</span>”.<br />
</li>
<li>Independent of 1 and 2: should an additional exception for functions that use C++ exceptions to report errors added?<br />
</li>
</ol>
]]></description>
			<content:encoded><![CDATA[Hi,<br />
<br />
The amplification of MISRA C++:2023 rule 0.1.2 states that <span style="font-style: italic;" class="mycode_i">“This rule only applies when the function is called explicitly using function call syntax”</span>.<br />
Consequently, operators like “+=” are out of scope so in the following code the modification of the std:<img src="https://forum.misra.org.uk/images/smilies/confused.png" alt="Confused" title="Confused" class="smilie smilie_13" />tring object with “+=” is fine and the usage of append, without checking the returned reference, is a violation of this required rule:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void example1() {<br />
    // Non-compliant use of std::string::append<br />
    std::string my_string;<br />
    my_string.append("foo");  // add 'foo'<br />
    my_string.append("bar");  // add 'bar'<br />
}<br />
<br />
void example2() {<br />
    // Compliant use of std::string::operator+=:<br />
    std::string my_string;<br />
    my_string += "foo";  // add 'foo'<br />
    my_string += "bar";  // add 'bar'<br />
}<br />
<br />
void example3() {<br />
    std::vector&lt;int&gt; numbers;<br />
<br />
    numbers.push_back(1);  // Compliant to MISRA C++:2023 Rule 0.1.2 <br />
                           // as push_back ""returns"" void<br />
<br />
    // C++ reference: https://en.cppreference.com/w/cpp/container/vector/push_back.html<br />
<br />
    // emplace_back returns (since C++17) an iterator:<br />
    // https://en.cppreference.com/w/cpp/container/vector/emplace_back.html<br />
<br />
    numbers.emplace_back(2);  // Non-compliant to MISRA C++:2023 Rule 0.1.2 (since C++17)<br />
}</code></div></div><br />
The function <span style="font-style: italic;" class="mycode_i">append</span> of std:<img src="https://forum.misra.org.uk/images/smilies/confused.png" alt="Confused" title="Confused" class="smilie smilie_13" />tring (std::basic_string) and the <span style="font-style: italic;" class="mycode_i">operator+=</span> append additional characters to the end of the string. Both return a reference to “*this”. Both throw std::length_error if the operation would cause size() to exceed max_size() and provide the strong exception safety guarantee. So, there is no real difference between using “+=” or “append” in terms of safety or code quality. If one wants to write compliant code, example1 needs to be refactored to use a void cast  to ignore the result:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void example1_compliant_version() {<br />
    std::string my_string;<br />
    static_cast&lt;void&gt;(my_string.append("foo"));  // add 'foo'<br />
    static_cast&lt;void&gt;(my_string.append("bar"));  // add 'bar'<br />
}</code></div></div><br />
That would implicitly force developers to always prefer operators like “+=” over functions like “append” as the alternatives make the code harder to read or lead to additional effort (deviations need to be justified).<br />
<br />
If one decides to rework this kind of code to a “fluent API style” that could lead to extra copies:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>std::string BuildFailureMsg(std::string_view name, std::string_view reason) {<br />
    std::string msg{};<br />
    msg.reserve(name.size() + reason.size() + 26);  // reserve sufficient memory<br />
    msg.append("Component ");<br />
    msg.append(name);<br />
    msg.append(" failed due to ");<br />
    msg.append(reason);<br />
    msg.append("&#92;n");<br />
    return msg;<br />
}<br />
std::string BuildFailureMsgNaiveRefactor(std::string_view name,<br />
                                      std::string_view reason) {<br />
    std::string msg{};<br />
    msg.reserve(name.size() + reason.size() + 26);  // reserve sufficient memory<br />
    return msg.append("Component ")<br />
        .append(name)<br />
        .append(" failed due to ")<br />
        .append(reason)<br />
        .append("&#92;n"); // will create and return copy of msg (i.e. see extra "memcpy")<br />
}<br />
int main() {<br />
    std::string failure_msg_01 = BuildFailureMsg("Logger", "insufficient memory");  // no copies/moves<br />
    std::string failure_msg_02 = BuildFailureMsgNaiveRefactor("Logger", "insufficient memory");  // extra copy<br />
}</code></div></div><br />
Consequently, existing code that uses append needs to be refactored to use “+=”. A huge refactoring effort for large code bases, but without any real benefit.<br />
Also, it might lead to the negative effect that developers that uses std::vector prefer “push_back” over “emplace_back”, as with C++17 std::vector::emplace_back returns a reference (example3). Other alternatives might lead to less efficient code. <br />
<br />
Our questions:<br />
<ol type="1" class="mycode_list"><li><span style="font-size: 1pt;" class="mycode_size"><span style="font-family: Times New Roman;" class="mycode_font">      </span></span>Is it really intended to promote the usage of operators over functions and (for std::vector and other std-library types like std::optional::emplace) to use push_back over emplace_back or are here just exceptions missing?<br />
</li>
<li>As the rationale states that <span style="font-style: italic;" class="mycode_i">“it is <span style="font-weight: bold;" class="mycode_b">possible</span> to call a function without using the return value, which may be an error”</span>, should this rule be changed to “advisory” and the title changed to “<span style="font-style: italic;" class="mycode_i">The value returned by a function should be used</span>”.<br />
</li>
<li>Independent of 1 and 2: should an additional exception for functions that use C++ exceptions to report errors added?<br />
</li>
</ol>
]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 0.1.1]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1741</link>
			<pubDate>Mon, 30 Jun 2025 12:59:47 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=6654">Merge</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1741</guid>
			<description><![CDATA[Hi,<br />
<br />
I was made aware of the following by a colleague.<br />
In one of the official examples for rule 0.1.1 MISRA C++ 2023 states, quote:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>m = 10; // Non-compliant - when looping, overwrites incremented value</code></div></div><br />
However, I would argue that during the last loop iteration, the value is being read (and modified) by the increment before being returned. In the rule amplification, it is stated that an object is considered observed if it has been observed in any iteration, which I would therefore consider being the case here.<br />
<br />
In other words, `m` is observed in this line, so it should not be a violation as per the rule amplification. Am I missing something?<br />
<br />
I'll admit that the example is not the cleanest code for expressing the particular functionality (e.g., statement could be moved out of the loop), but we have to keep in mind that this is merely a simple example for illustration purposes and a real-world example might look comparatively more complex.<br />
<br />
I would appreciate a second opinion :-)<br />
<br />
Best regards,<br />
Daniel "Merge" Merget]]></description>
			<content:encoded><![CDATA[Hi,<br />
<br />
I was made aware of the following by a colleague.<br />
In one of the official examples for rule 0.1.1 MISRA C++ 2023 states, quote:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>m = 10; // Non-compliant - when looping, overwrites incremented value</code></div></div><br />
However, I would argue that during the last loop iteration, the value is being read (and modified) by the increment before being returned. In the rule amplification, it is stated that an object is considered observed if it has been observed in any iteration, which I would therefore consider being the case here.<br />
<br />
In other words, `m` is observed in this line, so it should not be a violation as per the rule amplification. Am I missing something?<br />
<br />
I'll admit that the example is not the cleanest code for expressing the particular functionality (e.g., statement could be moved out of the loop), but we have to keep in mind that this is merely a simple example for illustration purposes and a real-world example might look comparatively more complex.<br />
<br />
I would appreciate a second opinion :-)<br />
<br />
Best regards,<br />
Daniel "Merge" Merget]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 0.1.2]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1715</link>
			<pubDate>Thu, 21 Nov 2024 13:12:46 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=6527">stephanmuench</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1715</guid>
			<description><![CDATA[Dear MISRA members,<br />
<br />
I would have a question about <span style="font-family: 'Open Sans', sans-serif;" class="mycode_font">MISRA C++:2023 Rule 0.1.2 which mentions in its rationale</span><br />
<span style="font-family: 'Open Sans', sans-serif;" class="mycode_font"><span style="color: #1f2328;" class="mycode_color"><span style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';" class="mycode_font">"Overloaded operators are excluded from this rule because [...]"</span></span></span><br />
<br />
<span style="font-family: 'Open Sans', sans-serif;" class="mycode_font"><span style="color: #1f2328;" class="mycode_color"><span style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';" class="mycode_font">Here, my question is whether in this scope, `operator()` should be considered to be a built-in operator.</span></span></span><br />
<span style="color: #1f2328;" class="mycode_color"><span style="font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Noto Sans, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji;" class="mycode_font">Since to me, such one should instead be considered </span></span><span style="color: #1f2328;" class="mycode_color"><span style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';" class="mycode_font">more of a normal function call.</span></span><br />
<span style="color: #1f2328;" class="mycode_color"><span style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';" class="mycode_font">Otherwise, it would undermine the rule's actual intention, which is to diagnose </span></span><span style="color: #1f2328;" class="mycode_color"><span style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';" class="mycode_font">any unused return values of function calls, am I right?</span></span><br />
<span style="color: #1f2328;" class="mycode_color"><span style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';" class="mycode_font">Especially for modern C++ where plenty of code gets put into lambdas and/or std::function.</span></span><br />
<br />
<span style="color: #1f2328;" class="mycode_color"><span style="font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Noto Sans, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji;" class="mycode_font">I would very happy if you could share some thoughts about this.</span></span><br />
<br />
<span style="color: #1f2328;" class="mycode_color"><span style="font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Noto Sans, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji;" class="mycode_font">Thanks a lot in advance &amp; best regards,</span></span><br />
<span style="color: #1f2328;" class="mycode_color"><span style="font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Noto Sans, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji;" class="mycode_font">Stephan</span></span>]]></description>
			<content:encoded><![CDATA[Dear MISRA members,<br />
<br />
I would have a question about <span style="font-family: 'Open Sans', sans-serif;" class="mycode_font">MISRA C++:2023 Rule 0.1.2 which mentions in its rationale</span><br />
<span style="font-family: 'Open Sans', sans-serif;" class="mycode_font"><span style="color: #1f2328;" class="mycode_color"><span style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';" class="mycode_font">"Overloaded operators are excluded from this rule because [...]"</span></span></span><br />
<br />
<span style="font-family: 'Open Sans', sans-serif;" class="mycode_font"><span style="color: #1f2328;" class="mycode_color"><span style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';" class="mycode_font">Here, my question is whether in this scope, `operator()` should be considered to be a built-in operator.</span></span></span><br />
<span style="color: #1f2328;" class="mycode_color"><span style="font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Noto Sans, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji;" class="mycode_font">Since to me, such one should instead be considered </span></span><span style="color: #1f2328;" class="mycode_color"><span style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';" class="mycode_font">more of a normal function call.</span></span><br />
<span style="color: #1f2328;" class="mycode_color"><span style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';" class="mycode_font">Otherwise, it would undermine the rule's actual intention, which is to diagnose </span></span><span style="color: #1f2328;" class="mycode_color"><span style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';" class="mycode_font">any unused return values of function calls, am I right?</span></span><br />
<span style="color: #1f2328;" class="mycode_color"><span style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';" class="mycode_font">Especially for modern C++ where plenty of code gets put into lambdas and/or std::function.</span></span><br />
<br />
<span style="color: #1f2328;" class="mycode_color"><span style="font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Noto Sans, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji;" class="mycode_font">I would very happy if you could share some thoughts about this.</span></span><br />
<br />
<span style="color: #1f2328;" class="mycode_color"><span style="font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Noto Sans, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji;" class="mycode_font">Thanks a lot in advance &amp; best regards,</span></span><br />
<span style="color: #1f2328;" class="mycode_color"><span style="font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Noto Sans, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji;" class="mycode_font">Stephan</span></span>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 0.0.1]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1686</link>
			<pubDate>Fri, 24 May 2024 05:20:55 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=1246">gdavis</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1686</guid>
			<description><![CDATA[Hello,<br />
<br />
I apologize for this basic question, but can somebody please walk me through the first first five lines of MISRA C++ 2023 Rule 0.0.1?<br />
<br />
<span style="font-family: Courier New;" class="mycode_font">bool f0();</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">int32_t f1( int32_t c, int32_t &amp;res )</span><br />
<span style="font-family: Courier New;" class="mycode_font">{</span><br />
<span style="font-family: Courier New;" class="mycode_font">  if ( false &amp;&amp; f0() ) { }       // Compliant - statement is considered to be reachable</span><br />
<span style="font-family: Courier New;" class="mycode_font">  ...</span><br />
<br />
In particular, why is the empty block statement (<span style="font-family: Courier New;" class="mycode_font">"{ }"</span>) considered to be reachable? My thinking is:<br />
<br />
The condition of the if statement is considered a constant expression in C++17, one that evaluates to false. Therefore, we follow the third bullet point:<br />
<ul class="mycode_list"><li>The blocks linked by the edges from a condition of a selection-statement or an iteration-statement are all considered reachable, except when the condition is a constant expression, in which case only the blocks linked by edges selected by the condition are considered reachable.<br />
</li>
</ul>
<br />
So, this seems to me that we should consider the empty block statement to be unreachable.<br />
<br />
Also, what is the purpose of the first two bullet points:<br />
<ul class="mycode_list"><li>Both operands of a reachable logical AND (&amp;&amp;) or logical OR (||) operator are considered reachable<br />
</li>
<li>All three operands of a reachable conditional operator ( ? : ) are considered reachable<br />
</li>
</ul>
<br />
Rule 0.0.1 is concerned with statements, so I don't see how subexpressions matter unless these rules are meant to convey that an expression such as ( false &amp;&amp; f0() ) is potentially throwing and/or not a constant expression (for the purposes of this rule).. But, I feel like I may be reading too much into this.<br />
<br />
Thank you in advance.]]></description>
			<content:encoded><![CDATA[Hello,<br />
<br />
I apologize for this basic question, but can somebody please walk me through the first first five lines of MISRA C++ 2023 Rule 0.0.1?<br />
<br />
<span style="font-family: Courier New;" class="mycode_font">bool f0();</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">int32_t f1( int32_t c, int32_t &amp;res )</span><br />
<span style="font-family: Courier New;" class="mycode_font">{</span><br />
<span style="font-family: Courier New;" class="mycode_font">  if ( false &amp;&amp; f0() ) { }       // Compliant - statement is considered to be reachable</span><br />
<span style="font-family: Courier New;" class="mycode_font">  ...</span><br />
<br />
In particular, why is the empty block statement (<span style="font-family: Courier New;" class="mycode_font">"{ }"</span>) considered to be reachable? My thinking is:<br />
<br />
The condition of the if statement is considered a constant expression in C++17, one that evaluates to false. Therefore, we follow the third bullet point:<br />
<ul class="mycode_list"><li>The blocks linked by the edges from a condition of a selection-statement or an iteration-statement are all considered reachable, except when the condition is a constant expression, in which case only the blocks linked by edges selected by the condition are considered reachable.<br />
</li>
</ul>
<br />
So, this seems to me that we should consider the empty block statement to be unreachable.<br />
<br />
Also, what is the purpose of the first two bullet points:<br />
<ul class="mycode_list"><li>Both operands of a reachable logical AND (&amp;&amp;) or logical OR (||) operator are considered reachable<br />
</li>
<li>All three operands of a reachable conditional operator ( ? : ) are considered reachable<br />
</li>
</ul>
<br />
Rule 0.0.1 is concerned with statements, so I don't see how subexpressions matter unless these rules are meant to convey that an expression such as ( false &amp;&amp; f0() ) is potentially throwing and/or not a constant expression (for the purposes of this rule).. But, I feel like I may be reading too much into this.<br />
<br />
Thank you in advance.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Rule 0.2.4 non-compliant reason]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1676</link>
			<pubDate>Fri, 15 Mar 2024 14:20:50 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=6367">danix800</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1676</guid>
			<description><![CDATA[<span style="color: #222222;" class="mycode_color"><span style="font-size: medium;" class="mycode_size"><span style="font-family: Arial, Helvetica, sans-serif;" class="mycode_font"><span style="color: #555555;" class="mycode_color"><br />
Hi! I've questions about the examples of MISRA C++:2023 Rule 0.2.4 "Functions with limited visibility should be used at least once":</span><br />
</span></span></span><br />
<span style="color: #222222;" class="mycode_color"><span style="font-size: medium;" class="mycode_size"><span style="font-family: Arial, Helvetica, sans-serif;" class="mycode_font"><span style="color: #555555;" class="mycode_color">namespace B<br />
{<br />
  struct C2 {};<br />
  static void swap( C2 &amp;, C2 &amp; ); // Non-compliant<br />
}</span></span></span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Arial, Helvetica, sans-serif;" class="mycode_font"><br />
<span style="color: #555555;" class="mycode_color"><span style="color: #555555;" class="mycode_color">B:<img src="https://forum.misra.org.uk/images/smilies/confused.png" alt="Confused" title="Confused" class="smilie smilie_13" />wap() is marked as non-compliant, could anyone please give some explanations?</span></span></span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Arial, Helvetica, sans-serif;" class="mycode_font"><br />
<span style="color: #555555;" class="mycode_color"><span style="color: #555555;" class="mycode_color">Thank you very much!</span></span></span></span>]]></description>
			<content:encoded><![CDATA[<span style="color: #222222;" class="mycode_color"><span style="font-size: medium;" class="mycode_size"><span style="font-family: Arial, Helvetica, sans-serif;" class="mycode_font"><span style="color: #555555;" class="mycode_color"><br />
Hi! I've questions about the examples of MISRA C++:2023 Rule 0.2.4 "Functions with limited visibility should be used at least once":</span><br />
</span></span></span><br />
<span style="color: #222222;" class="mycode_color"><span style="font-size: medium;" class="mycode_size"><span style="font-family: Arial, Helvetica, sans-serif;" class="mycode_font"><span style="color: #555555;" class="mycode_color">namespace B<br />
{<br />
  struct C2 {};<br />
  static void swap( C2 &amp;, C2 &amp; ); // Non-compliant<br />
}</span></span></span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Arial, Helvetica, sans-serif;" class="mycode_font"><br />
<span style="color: #555555;" class="mycode_color"><span style="color: #555555;" class="mycode_color">B:<img src="https://forum.misra.org.uk/images/smilies/confused.png" alt="Confused" title="Confused" class="smilie smilie_13" />wap() is marked as non-compliant, could anyone please give some explanations?</span></span></span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Arial, Helvetica, sans-serif;" class="mycode_font"><br />
<span style="color: #555555;" class="mycode_color"><span style="color: #555555;" class="mycode_color">Thank you very much!</span></span></span></span>]]></content:encoded>
		</item>
	</channel>
</rss>