<?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 - AUTOSAR C++:2014 rules]]></title>
		<link>https://forum.misra.org.uk/</link>
		<description><![CDATA[MISRA Discussion Forums - https://forum.misra.org.uk]]></description>
		<pubDate>Mon, 09 Nov 2026 19:53:38 +0000</pubDate>
		<generator>MyBB</generator>
		<item>
			<title><![CDATA[Does rule A2-10-5 apply to reusing an external identifier as a member identifier?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1777</link>
			<pubDate>Mon, 06 Jul 2026 12:23:34 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=5807">mstaron</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1777</guid>
			<description><![CDATA[Rule A2-10-5 states: Regardless of scope, no identifier with static storage duration should be reused across any source files in the project. Are cases where an identifier is reused as a member non-compliant with this rule? In particular, the case where an operator function is defined as a global and a member function.<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>struct S<br />
{<br />
&nbsp;&nbsp;void operator&lt;&lt;(S&amp;) {}<br />
&nbsp;&nbsp;void f1(int par) {}<br />
};<br />
<br />
namespace N<br />
{<br />
&nbsp;&nbsp;void operator&lt;&lt;(int i, S&amp;) {}&nbsp;&nbsp;// Is compliant or non-compliant?<br />
&nbsp;&nbsp;void f1(int par) {}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Is compliant or non-compliant?<br />
}</code></div></div>]]></description>
			<content:encoded><![CDATA[Rule A2-10-5 states: Regardless of scope, no identifier with static storage duration should be reused across any source files in the project. Are cases where an identifier is reused as a member non-compliant with this rule? In particular, the case where an operator function is defined as a global and a member function.<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>struct S<br />
{<br />
&nbsp;&nbsp;void operator&lt;&lt;(S&amp;) {}<br />
&nbsp;&nbsp;void f1(int par) {}<br />
};<br />
<br />
namespace N<br />
{<br />
&nbsp;&nbsp;void operator&lt;&lt;(int i, S&amp;) {}&nbsp;&nbsp;// Is compliant or non-compliant?<br />
&nbsp;&nbsp;void f1(int par) {}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Is compliant or non-compliant?<br />
}</code></div></div>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Is Fn4 example in AUTOSAR rule A7-5-2 correct?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1776</link>
			<pubDate>Thu, 02 Jul 2026 10:49:49 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=6775">limdor</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1776</guid>
			<description><![CDATA[<span style="font-family: 'Open Sans', sans-serif;" class="mycode_font">AUTOSAR rule A7-5-2 has the following example:</span><br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>std::int32_t Fn4(std::int32_t number) <br />
{ <br />
  if (number == 1) <br />
  {<br />
    number = number * Fn3(number - 1);  // Non-compliant <br />
  } &nbsp;&nbsp;<br />
  return number; <br />
}</code></div></div> <span style="font-family: 'Open Sans', sans-serif;" class="mycode_font">Fn3 is a recursive function and thus non-compliant. Fn4 is making a call to Fn3. However, in this line, the function is not calling itself. Why is this line Non-compliant? Is this an issue with the example?</span>]]></description>
			<content:encoded><![CDATA[<span style="font-family: 'Open Sans', sans-serif;" class="mycode_font">AUTOSAR rule A7-5-2 has the following example:</span><br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>std::int32_t Fn4(std::int32_t number) <br />
{ <br />
  if (number == 1) <br />
  {<br />
    number = number * Fn3(number - 1);  // Non-compliant <br />
  } &nbsp;&nbsp;<br />
  return number; <br />
}</code></div></div> <span style="font-family: 'Open Sans', sans-serif;" class="mycode_font">Fn3 is a recursive function and thus non-compliant. Fn4 is making a call to Fn3. However, in this line, the function is not calling itself. Why is this line Non-compliant? Is this an issue with the example?</span>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[AUTOSAR C++14 M5-2-10 for unique_ptr in combination with ++ operator]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1769</link>
			<pubDate>Fri, 08 May 2026 08:51:28 +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=1769</guid>
			<description><![CDATA[The AUTOSAR C++14 Guidelines  ("AUTOSAR Guidelines for the use of the C++14 language in critical and safety-related systems") contain the MISRA C++:2008 rule 5-2-10 as rule M5-2-2. M5-2-2 was modified to required but - AFAIK - nothing else was changed.<br />
<br />
<blockquote class="mycode_quote"><cite>Quote:</cite>Rule M5-2-10 (required, implementation, automated) <br />
The increment (++) and decrement ( ) operators shall not be mixed with other operators in an expression.</blockquote>
<br />
There is a similar MISRA C:2012/2023/2025 rule <br />
<blockquote class="mycode_quote"><cite>Quote:</cite>Rule 13.3 A full expression containing an increment (++) or decrement (--) operator should have no other potential side effects other than that caused by the increment or decrement operator</blockquote>
<br />
Also some examples are shared:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>u8a = ++u8b + u8c--;  // Non-compliant<br />
// The following sequence is clearer and therefore safer:<br />
++u8b;<br />
u8a = u8b + u8c;<br />
u8c--;</code></div></div><br />
<br />
While this makes makes sense for C and C++, there are differences between C and C. What about the following code:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#include &lt;cstdint&gt;<br />
#include &lt;memory&gt;<br />
<br />
<br />
struct Data {<br />
        std::int32_t member;<br />
};<br />
<br />
std::int32_t main(){<br />
        std::unique_ptr&lt;Data&gt; d = std::make_unique&lt;Data&gt;(12);<br />
        d-&gt;member++;  // Compliant ?<br />
}</code></div></div><br />
Shall a AUTOSAR C++14/MISRA C++:2008 checker report a violation for  "d-&gt;member++" or is that OK?]]></description>
			<content:encoded><![CDATA[The AUTOSAR C++14 Guidelines  ("AUTOSAR Guidelines for the use of the C++14 language in critical and safety-related systems") contain the MISRA C++:2008 rule 5-2-10 as rule M5-2-2. M5-2-2 was modified to required but - AFAIK - nothing else was changed.<br />
<br />
<blockquote class="mycode_quote"><cite>Quote:</cite>Rule M5-2-10 (required, implementation, automated) <br />
The increment (++) and decrement ( ) operators shall not be mixed with other operators in an expression.</blockquote>
<br />
There is a similar MISRA C:2012/2023/2025 rule <br />
<blockquote class="mycode_quote"><cite>Quote:</cite>Rule 13.3 A full expression containing an increment (++) or decrement (--) operator should have no other potential side effects other than that caused by the increment or decrement operator</blockquote>
<br />
Also some examples are shared:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>u8a = ++u8b + u8c--;  // Non-compliant<br />
// The following sequence is clearer and therefore safer:<br />
++u8b;<br />
u8a = u8b + u8c;<br />
u8c--;</code></div></div><br />
<br />
While this makes makes sense for C and C++, there are differences between C and C. What about the following code:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#include &lt;cstdint&gt;<br />
#include &lt;memory&gt;<br />
<br />
<br />
struct Data {<br />
        std::int32_t member;<br />
};<br />
<br />
std::int32_t main(){<br />
        std::unique_ptr&lt;Data&gt; d = std::make_unique&lt;Data&gt;(12);<br />
        d-&gt;member++;  // Compliant ?<br />
}</code></div></div><br />
Shall a AUTOSAR C++14/MISRA C++:2008 checker report a violation for  "d-&gt;member++" or is that OK?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[A3-3-2 Contradictory examples?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1731</link>
			<pubDate>Mon, 17 Mar 2025 09:58:14 +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=1731</guid>
			<description><![CDATA[In Rule A3-3-2, there's an example with "class A" which has a non-constexpr, user-defined constructor. <br />
<br />
On line 31, we have a compliant example:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>A instance{}; // Compliant - constant (value) initialization</code></div></div><br />
However, on line 37 it's no longer compliant:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>static A a{}; // Non-compliant - A’s default c’tor is not constexpr</code></div></div><br />
There seems to be a contradiction here. Either the code is doing value initialization, or it's calling a constructor, but not both. Which one is it?<br />
<br />
In other words, it seems like both examples are doing the same thing, so both should either be compliant or non-compliant. Would you agree?]]></description>
			<content:encoded><![CDATA[In Rule A3-3-2, there's an example with "class A" which has a non-constexpr, user-defined constructor. <br />
<br />
On line 31, we have a compliant example:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>A instance{}; // Compliant - constant (value) initialization</code></div></div><br />
However, on line 37 it's no longer compliant:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>static A a{}; // Non-compliant - A’s default c’tor is not constexpr</code></div></div><br />
There seems to be a contradiction here. Either the code is doing value initialization, or it's calling a constructor, but not both. Which one is it?<br />
<br />
In other words, it seems like both examples are doing the same thing, so both should either be compliant or non-compliant. Would you agree?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[A8-4-5: Should have an exception for move constructors]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1725</link>
			<pubDate>Wed, 05 Feb 2025 09:45:55 +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=1725</guid>
			<description><![CDATA[Our static analyzer is complaining about our move constructor because we are not moving the entire "oth" input. Instead, we are doing member-wise move, in compliance with A12-8-1:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>class B<br />
{<br />
public:<br />
&nbsp;&nbsp;B(B&amp;&amp; oth) : ptr(std::move(oth.ptr)) // Compliant<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp; oth.ptr = nullptr;<br />
&nbsp;&nbsp;}<br />
};</code></div></div><br />
Do you agree that A8-4-5 should explicitly clarify that the rule does <span style="font-weight: bold;" class="mycode_b">not </span>apply to move constructors?]]></description>
			<content:encoded><![CDATA[Our static analyzer is complaining about our move constructor because we are not moving the entire "oth" input. Instead, we are doing member-wise move, in compliance with A12-8-1:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>class B<br />
{<br />
public:<br />
&nbsp;&nbsp;B(B&amp;&amp; oth) : ptr(std::move(oth.ptr)) // Compliant<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp; oth.ptr = nullptr;<br />
&nbsp;&nbsp;}<br />
};</code></div></div><br />
Do you agree that A8-4-5 should explicitly clarify that the rule does <span style="font-weight: bold;" class="mycode_b">not </span>apply to move constructors?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[A7-2-1 Still relevant in C++14?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1724</link>
			<pubDate>Wed, 29 Jan 2025 10:03:31 +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=1724</guid>
			<description><![CDATA[Rule A7-2-1 seems copied verbatim from the MISRA C++ 2008 rules. However, there's a key difference: C++14 has scoped enums. There, it is <span style="font-weight: bold;" class="mycode_b">not</span> unspecified (nor undefined) to cast an integer to the enum type when it is not any of the enumerators, since the valid range for the enum is the range of the underlying type. <br />
<br />
Based on that, what would be the rationale for keeping A7-2-1 in the AUTOSAR C++14 rules?]]></description>
			<content:encoded><![CDATA[Rule A7-2-1 seems copied verbatim from the MISRA C++ 2008 rules. However, there's a key difference: C++14 has scoped enums. There, it is <span style="font-weight: bold;" class="mycode_b">not</span> unspecified (nor undefined) to cast an integer to the enum type when it is not any of the enumerators, since the valid range for the enum is the range of the underlying type. <br />
<br />
Based on that, what would be the rationale for keeping A7-2-1 in the AUTOSAR C++14 rules?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[A18-9-4]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1714</link>
			<pubDate>Tue, 15 Oct 2024 09:58:28 +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=1714</guid>
			<description><![CDATA[Hi!<br />
<br />
I wonder if this code example technically violates A18-9-4?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#include &lt;memory&gt;<br />
<br />
struct Foo<br />
{<br />
    explicit Foo(int);<br />
};<br />
<br />
int main()<br />
{<br />
    int val{};<br />
    auto x = std::make_unique&lt;Foo&gt;(val);<br />
    ++val; // non-compliant?<br />
}</code></div></div><br />
Since internally, std::make_unique takes the input arguments as "Args&amp;&amp;..." and std::forward's them into the constructor of the class.<br />
<br />
Thanks!]]></description>
			<content:encoded><![CDATA[Hi!<br />
<br />
I wonder if this code example technically violates A18-9-4?<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#include &lt;memory&gt;<br />
<br />
struct Foo<br />
{<br />
    explicit Foo(int);<br />
};<br />
<br />
int main()<br />
{<br />
    int val{};<br />
    auto x = std::make_unique&lt;Foo&gt;(val);<br />
    ++val; // non-compliant?<br />
}</code></div></div><br />
Since internally, std::make_unique takes the input arguments as "Args&amp;&amp;..." and std::forward's them into the constructor of the class.<br />
<br />
Thanks!]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[A8-4-5: are partial moves allowed?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1709</link>
			<pubDate>Tue, 01 Oct 2024 12:28:11 +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=1709</guid>
			<description><![CDATA[Are partial moves allowed by A8-4-5? If not, why not?<br />
<br />
For example, consider the following snippet from Effective Modern C++ (Meyers), Item 25, page 169:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>class Widget {<br />
 public:<br />
&nbsp;&nbsp; Widget(Widget&amp;&amp; rhs)<br />
&nbsp;&nbsp; : name(std::move(rhs.name)),<br />
&nbsp;&nbsp;&nbsp;&nbsp; p(std::move(rhs.p))<br />
&nbsp;&nbsp; { … }<br />
&nbsp;&nbsp; …<br />
<br />
// rhs is rvalue reference<br />
 private:<br />
&nbsp;&nbsp; std::string name;<br />
&nbsp;&nbsp; std::shared_ptr&lt;SomeDataStructure&gt; p;<br />
};</code></div></div>]]></description>
			<content:encoded><![CDATA[Are partial moves allowed by A8-4-5? If not, why not?<br />
<br />
For example, consider the following snippet from Effective Modern C++ (Meyers), Item 25, page 169:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>class Widget {<br />
 public:<br />
&nbsp;&nbsp; Widget(Widget&amp;&amp; rhs)<br />
&nbsp;&nbsp; : name(std::move(rhs.name)),<br />
&nbsp;&nbsp;&nbsp;&nbsp; p(std::move(rhs.p))<br />
&nbsp;&nbsp; { … }<br />
&nbsp;&nbsp; …<br />
<br />
// rhs is rvalue reference<br />
 private:<br />
&nbsp;&nbsp; std::string name;<br />
&nbsp;&nbsp; std::shared_ptr&lt;SomeDataStructure&gt; p;<br />
};</code></div></div>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[A27-0-1 Unclear scope of the rule]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1697</link>
			<pubDate>Tue, 20 Aug 2024 10:36:06 +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=1697</guid>
			<description><![CDATA[Hi,<br />
<br />
Rule A27-0-1 says:<br />
<br />
Rule A27-0-1 (required, implementation, non-automated)<br />
Inputs from independent components shall be validated.<br />
<br />
This is very abstract and vague:<br />
<br />
* What is the definition of "independent components"?<br />
* Validated, in what context? When doing what?<br />
<br />
The rule is in the section "Input/output library", and the code examples of this rule only talk about string manipulation/formatting functions. Can we therefore assume that this rule is only concerned with validating input passed to string manipulation/formatting functions?<br />
<br />
Thanks!]]></description>
			<content:encoded><![CDATA[Hi,<br />
<br />
Rule A27-0-1 says:<br />
<br />
Rule A27-0-1 (required, implementation, non-automated)<br />
Inputs from independent components shall be validated.<br />
<br />
This is very abstract and vague:<br />
<br />
* What is the definition of "independent components"?<br />
* Validated, in what context? When doing what?<br />
<br />
The rule is in the section "Input/output library", and the code examples of this rule only talk about string manipulation/formatting functions. Can we therefore assume that this rule is only concerned with validating input passed to string manipulation/formatting functions?<br />
<br />
Thanks!]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[A13-5-4 opposite operator clarification]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1683</link>
			<pubDate>Fri, 26 Apr 2024 15:34:38 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=6392">aromauld</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1683</guid>
			<description><![CDATA[We would like to get clarification on what "opposite operators" means.<br />
<br />
The referenced JSF guideline says (<span style="font-weight: bold;" class="mycode_b">such as == and !=</span>) which implies there are others, but there are no examples present other than "!= and ==". <br />
<br />
Presumably this includes relational operators, but it doesn't discuss how. This rule would seemingly imply that &lt;= should be implemented using &gt;=. But would this mean that it is considered non-compliant to implement it with operator &gt;?<br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>inline bool operator&lt;=(const X&amp; lhs, const X&amp; rhs) { return !(lhs &gt; rhs); }</code></div></div> <br />
Are relational operators allowed to call any other relational operators? Are there any other pairings that are considered opposites for this rule?]]></description>
			<content:encoded><![CDATA[We would like to get clarification on what "opposite operators" means.<br />
<br />
The referenced JSF guideline says (<span style="font-weight: bold;" class="mycode_b">such as == and !=</span>) which implies there are others, but there are no examples present other than "!= and ==". <br />
<br />
Presumably this includes relational operators, but it doesn't discuss how. This rule would seemingly imply that &lt;= should be implemented using &gt;=. But would this mean that it is considered non-compliant to implement it with operator &gt;?<br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>inline bool operator&lt;=(const X&amp; lhs, const X&amp; rhs) { return !(lhs &gt; rhs); }</code></div></div> <br />
Are relational operators allowed to call any other relational operators? Are there any other pairings that are considered opposites for this rule?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[cvalue and constant integral expression in generic context]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1675</link>
			<pubDate>Tue, 12 Mar 2024 12:17:35 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=6362">gerbor</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1675</guid>
			<description><![CDATA[We would like to have some clarification regarding cvalues and integral constant expressions when considering C++14.<br />
<br />
Main Question: Is N, which is an integral constant expression, a cvalue as defined in MISRA C++:2008?<br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>template &lt;typename T, int N&gt;<br />
constexpr auto fun()<br />
{<br />
    constexpr auto v = T{N};<br />
    <br />
    return /* something */;<br />
}</code></div></div><br />
<br />
Question 2: Does the use of {} or () have any affect on whether N is a cvalue?<br />
<br />
Question 3: Does it matter whether T is fundamental type or a class type? For example:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>template &lt;typename T&gt;<br />
struct CustomScalar final<br />
{<br />
    T val{};<br />
<br />
    constexpr CustomScalar() = default;<br />
    explicit constexpr CustomScalar(T x) : val{x} {}<br />
};<br />
<br />
int main()<br />
{<br />
    fun&lt;CustomScalar&lt;float&gt;, 2&gt;();<br />
}</code></div></div>]]></description>
			<content:encoded><![CDATA[We would like to have some clarification regarding cvalues and integral constant expressions when considering C++14.<br />
<br />
Main Question: Is N, which is an integral constant expression, a cvalue as defined in MISRA C++:2008?<br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>template &lt;typename T, int N&gt;<br />
constexpr auto fun()<br />
{<br />
    constexpr auto v = T{N};<br />
    <br />
    return /* something */;<br />
}</code></div></div><br />
<br />
Question 2: Does the use of {} or () have any affect on whether N is a cvalue?<br />
<br />
Question 3: Does it matter whether T is fundamental type or a class type? For example:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>template &lt;typename T&gt;<br />
struct CustomScalar final<br />
{<br />
    T val{};<br />
<br />
    constexpr CustomScalar() = default;<br />
    explicit constexpr CustomScalar(T x) : val{x} {}<br />
};<br />
<br />
int main()<br />
{<br />
    fun&lt;CustomScalar&lt;float&gt;, 2&gt;();<br />
}</code></div></div>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[A4-5-1 with overloading operator<<]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1664</link>
			<pubDate>Tue, 07 Nov 2023 14:12:13 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.misra.org.uk/member.php?action=profile&uid=6291">Jakob Klein</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.misra.org.uk/showthread.php?tid=1664</guid>
			<description><![CDATA[<span style="color: #333333;" class="mycode_color"><span style="font-size: small;" class="mycode_size"><span style="font-family: 'Open Sans', sans-serif;" class="mycode_font">Hi</span></span></span><br />
<br />
<span style="color: #333333;" class="mycode_color"><span style="font-size: small;" class="mycode_size"><span style="font-family: 'Open Sans', sans-serif;" class="mycode_font">A4-5-1 states:<br />
</span></span></span><br />
<blockquote class="mycode_quote"><cite>Quote:</cite><span style="color: #333333;" class="mycode_color"><span style="font-size: small;" class="mycode_size"><span style="font-family: 'Open Sans', sans-serif;" class="mycode_font">Expressions with type enum or enum class shall not be used as operands to built-in and overloaded operators other than the subscript operator [ ], the assignment operator =, the equality operators == and ! =, the unary &amp; operator, and the relational operators &lt;, &lt;=, &gt;, &gt;=.</span></span></span></blockquote>
<span style="color: #333333;" class="mycode_color"><span style="font-size: small;" class="mycode_size"><span style="font-family: 'Open Sans', sans-serif;" class="mycode_font">My understanding of the rule is that confusion should be avoided when using the underlying type arithmetically.</span></span></span><br />
<span style="color: #333333;" class="mycode_color"><span style="font-size: small;" class="mycode_size"><span style="font-family: 'Open Sans', sans-serif;" class="mycode_font">My use-case is overloading operator&lt;&lt; for convenient logging and printing of an unscoped enum:<br />
</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>inline std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, MyEnum const&amp; enum_value)<br />
{<br />
    switch (enum_value)<br />
    {<br />
        case MyEnum_Unknown:<br />
        {<br />
            return os &lt;&lt; "Unknown";<br />
        }<br />
        case MyEnum_Val1:<br />
        {<br />
            return os &lt;&lt; "Descriptive message... (MyEnum_Val1)";<br />
        }//...<br />
     }<br />
}</code></div></div><br />
Usage, where the warning is shown:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>LOG_WARNING &lt;&lt; "Could not perform action with " &lt;&lt; enum_value;</code></div></div><br />
<br />
<br />
So as long as the enum is not used in arithmetic context ie. bitwise operations (the enum is the left-hand operand) but with the streeam insertion operator I can not follow the rationale of the rule. Is this an oversight in the rule or is there a more specific reason behind this?]]></description>
			<content:encoded><![CDATA[<span style="color: #333333;" class="mycode_color"><span style="font-size: small;" class="mycode_size"><span style="font-family: 'Open Sans', sans-serif;" class="mycode_font">Hi</span></span></span><br />
<br />
<span style="color: #333333;" class="mycode_color"><span style="font-size: small;" class="mycode_size"><span style="font-family: 'Open Sans', sans-serif;" class="mycode_font">A4-5-1 states:<br />
</span></span></span><br />
<blockquote class="mycode_quote"><cite>Quote:</cite><span style="color: #333333;" class="mycode_color"><span style="font-size: small;" class="mycode_size"><span style="font-family: 'Open Sans', sans-serif;" class="mycode_font">Expressions with type enum or enum class shall not be used as operands to built-in and overloaded operators other than the subscript operator [ ], the assignment operator =, the equality operators == and ! =, the unary &amp; operator, and the relational operators &lt;, &lt;=, &gt;, &gt;=.</span></span></span></blockquote>
<span style="color: #333333;" class="mycode_color"><span style="font-size: small;" class="mycode_size"><span style="font-family: 'Open Sans', sans-serif;" class="mycode_font">My understanding of the rule is that confusion should be avoided when using the underlying type arithmetically.</span></span></span><br />
<span style="color: #333333;" class="mycode_color"><span style="font-size: small;" class="mycode_size"><span style="font-family: 'Open Sans', sans-serif;" class="mycode_font">My use-case is overloading operator&lt;&lt; for convenient logging and printing of an unscoped enum:<br />
</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>inline std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, MyEnum const&amp; enum_value)<br />
{<br />
    switch (enum_value)<br />
    {<br />
        case MyEnum_Unknown:<br />
        {<br />
            return os &lt;&lt; "Unknown";<br />
        }<br />
        case MyEnum_Val1:<br />
        {<br />
            return os &lt;&lt; "Descriptive message... (MyEnum_Val1)";<br />
        }//...<br />
     }<br />
}</code></div></div><br />
Usage, where the warning is shown:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>LOG_WARNING &lt;&lt; "Could not perform action with " &lt;&lt; enum_value;</code></div></div><br />
<br />
<br />
So as long as the enum is not used in arithmetic context ie. bitwise operations (the enum is the left-hand operand) but with the streeam insertion operator I can not follow the rationale of the rule. Is this an oversight in the rule or is there a more specific reason behind this?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[A3-9-1 exception for using "unsigned char" for storage?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1662</link>
			<pubDate>Mon, 30 Oct 2023 12:52:05 +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=1662</guid>
			<description><![CDATA[A3-9-1 forbids the use of char (and a recent question clarifies that it's intended for signed/unsigned char).<br />
<br />
However, how can we create storage in that case, since we don't have std::byte until C++17? We could use `std::uint8_t`, but that's not the type that is used in the Standard, and could potentially not be identical to "unsigned char" depending on platform.<br />
<br />
Example use case:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>alignas(T) unsigned char data[sizeof(T)];<br />
T* p = new (data) T();</code></div></div>]]></description>
			<content:encoded><![CDATA[A3-9-1 forbids the use of char (and a recent question clarifies that it's intended for signed/unsigned char).<br />
<br />
However, how can we create storage in that case, since we don't have std::byte until C++17? We could use `std::uint8_t`, but that's not the type that is used in the Standard, and could potentially not be identical to "unsigned char" depending on platform.<br />
<br />
Example use case:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>alignas(T) unsigned char data[sizeof(T)];<br />
T* p = new (data) T();</code></div></div>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[A6-4-1 What is the definition of a "case-clause"?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1659</link>
			<pubDate>Wed, 11 Oct 2023 07:17:58 +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=1659</guid>
			<description><![CDATA[Hi!<br />
<br />
Rule A6-4-1 says:<br />
<br />
Rule A6-4-1 (required, implementation, automated)<br />
A switch statement shall have at least two case-clauses, distinct from<br />
the default label.<br />
<br />
<br />
What is the definition of a "case-clause"? Is it a "case-clause <span style="font-weight: bold;" class="mycode_b">label</span>", or a "case-clause <span style="font-weight: bold;" class="mycode_b">block of code</span>"?<br />
<br />
Our static analyzer is warning about this code:<br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void foo(int i)<br />
{<br />
&nbsp;&nbsp;switch(i)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 3:<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 7: <br />
&nbsp;&nbsp;&nbsp;&nbsp;case 12:<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 25:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;doSomething();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;default:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;doSomethingElse();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;}<br />
}</code></div></div><br />
<br />
It warns because there is only one case "block of code" (doSomething), and it expects that there are at least 2 (distinct from default case). It then wants us to rewrite the code in a much less readable way, like:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>if (i == 3 || i == 7 || i == 12 || i == 25) <br />
{&nbsp;&nbsp;<br />
&nbsp;&nbsp;doSomething();<br />
}<br />
else<br />
{<br />
&nbsp;&nbsp;doSomethingElse()<br />
}</code></div></div><br />
<br />
Is our static analyzer correct in warning A6-4-1 in the above code?<br />
<br />
Please note: A6-4-1 inherits from HIC++ HIC++ v4.0 [9]: 6.1.4, which is more explicit than AUTOSAR, claiming that "at least two case <span style="font-weight: bold;" class="mycode_b">labels" </span>are needed. There's a big difference between "label" and "block".<br />
<br />
Furthermore, consider the documentation from Perforce about HIC++ 6.1.4:<br />
<br />
<a href="https://www.perforce.com/resources/qac/high-integrity-cpp-coding-standard/statements" target="_blank" rel="noopener" class="mycode_url">https://www.perforce.com/resources/qac/h...statements</a><br />
<br />
There, they claim that the following code is compliant (while not being compliant in AUTOSAR):<br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>// @@+ Compliant: 2 case labels distinct from the default label +@@<br />
switch (i)<br />
{<br />
&nbsp;&nbsp;case 0:<br />
&nbsp;&nbsp;case 1:<br />
&nbsp;&nbsp;&nbsp;&nbsp;doSomething ();<br />
&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;default:<br />
&nbsp;&nbsp;&nbsp;&nbsp;doSomethingElse ();<br />
&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
}</code></div></div><br />
Why should AUTOSAR change the meaning of the HIC++ rule?<br />
<br />
Thanks!]]></description>
			<content:encoded><![CDATA[Hi!<br />
<br />
Rule A6-4-1 says:<br />
<br />
Rule A6-4-1 (required, implementation, automated)<br />
A switch statement shall have at least two case-clauses, distinct from<br />
the default label.<br />
<br />
<br />
What is the definition of a "case-clause"? Is it a "case-clause <span style="font-weight: bold;" class="mycode_b">label</span>", or a "case-clause <span style="font-weight: bold;" class="mycode_b">block of code</span>"?<br />
<br />
Our static analyzer is warning about this code:<br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>void foo(int i)<br />
{<br />
&nbsp;&nbsp;switch(i)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 3:<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 7: <br />
&nbsp;&nbsp;&nbsp;&nbsp;case 12:<br />
&nbsp;&nbsp;&nbsp;&nbsp;case 25:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;doSomething();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;default:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;doSomethingElse();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;}<br />
}</code></div></div><br />
<br />
It warns because there is only one case "block of code" (doSomething), and it expects that there are at least 2 (distinct from default case). It then wants us to rewrite the code in a much less readable way, like:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>if (i == 3 || i == 7 || i == 12 || i == 25) <br />
{&nbsp;&nbsp;<br />
&nbsp;&nbsp;doSomething();<br />
}<br />
else<br />
{<br />
&nbsp;&nbsp;doSomethingElse()<br />
}</code></div></div><br />
<br />
Is our static analyzer correct in warning A6-4-1 in the above code?<br />
<br />
Please note: A6-4-1 inherits from HIC++ HIC++ v4.0 [9]: 6.1.4, which is more explicit than AUTOSAR, claiming that "at least two case <span style="font-weight: bold;" class="mycode_b">labels" </span>are needed. There's a big difference between "label" and "block".<br />
<br />
Furthermore, consider the documentation from Perforce about HIC++ 6.1.4:<br />
<br />
<a href="https://www.perforce.com/resources/qac/high-integrity-cpp-coding-standard/statements" target="_blank" rel="noopener" class="mycode_url">https://www.perforce.com/resources/qac/h...statements</a><br />
<br />
There, they claim that the following code is compliant (while not being compliant in AUTOSAR):<br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>// @@+ Compliant: 2 case labels distinct from the default label +@@<br />
switch (i)<br />
{<br />
&nbsp;&nbsp;case 0:<br />
&nbsp;&nbsp;case 1:<br />
&nbsp;&nbsp;&nbsp;&nbsp;doSomething ();<br />
&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;default:<br />
&nbsp;&nbsp;&nbsp;&nbsp;doSomethingElse ();<br />
&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
}</code></div></div><br />
Why should AUTOSAR change the meaning of the HIC++ rule?<br />
<br />
Thanks!]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[A7-1-2: Is it really intented to mark also functions as constexpr?]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1657</link>
			<pubDate>Mon, 28 Aug 2023 09:37:52 +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=1657</guid>
			<description><![CDATA[Hi,<br />
<br />
A7-1-2 says:<br />
The constexpr specifier shall be used for values that can be determined at compile time.<br />
<br />
So it only talks about "values", not "functions". However, in the example, it says the following code is not compliant, because the function Pow1 "can be" constexpr but is not marked as such:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>std::int32_t Pow1(std::int32_t number)<br />
{<br />
    return (number * number);<br />
}<br />
void Fn()<br />
{<br />
    const std::int32_t threeSquare = Pow1(3); // Non-compliant, possible run-time evaluation<br />
}</code></div></div><br />
On the other hand, examples are not normative - the title of the rule is.<br />
<br />
Therefore I ask:<span style="font-weight: bold;" class="mycode_b"> is rule A7-1-2 intended to mark every single function as constexpr if it _can_ be constexpr</span>?<br />
<br />
In my opinion, this has negative consequences. Constexpr-ness of a function should be a careful design decision, not something added blindly to comply with a static analysis tool. It limits the way an author can choose to implement a given function. Maybe today the function _can_ be constexpr, but tomorrow as an author I want to refactor the implementation to e.g. use more modern libraries from STL, which don't have constexpr support in C++14 (for example, a silly std::array::operator[] is not supported in constexpr functions). Changing the implementation would require removing constexpr and updating also all the clients (which could dramatically cascade into second-order functions and so on). Or the alternative would be to be locked into constexpr and have to resort to older-style code to implement it (e.g. use a C array instead of std::array), making the function ultimately less safe and violating other Autosar rules.<br />
<br />
Thanks!]]></description>
			<content:encoded><![CDATA[Hi,<br />
<br />
A7-1-2 says:<br />
The constexpr specifier shall be used for values that can be determined at compile time.<br />
<br />
So it only talks about "values", not "functions". However, in the example, it says the following code is not compliant, because the function Pow1 "can be" constexpr but is not marked as such:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>std::int32_t Pow1(std::int32_t number)<br />
{<br />
    return (number * number);<br />
}<br />
void Fn()<br />
{<br />
    const std::int32_t threeSquare = Pow1(3); // Non-compliant, possible run-time evaluation<br />
}</code></div></div><br />
On the other hand, examples are not normative - the title of the rule is.<br />
<br />
Therefore I ask:<span style="font-weight: bold;" class="mycode_b"> is rule A7-1-2 intended to mark every single function as constexpr if it _can_ be constexpr</span>?<br />
<br />
In my opinion, this has negative consequences. Constexpr-ness of a function should be a careful design decision, not something added blindly to comply with a static analysis tool. It limits the way an author can choose to implement a given function. Maybe today the function _can_ be constexpr, but tomorrow as an author I want to refactor the implementation to e.g. use more modern libraries from STL, which don't have constexpr support in C++14 (for example, a silly std::array::operator[] is not supported in constexpr functions). Changing the implementation would require removing constexpr and updating also all the clients (which could dramatically cascade into second-order functions and so on). Or the alternative would be to be locked into constexpr and have to resort to older-style code to implement it (e.g. use a C array instead of std::array), making the function ultimately less safe and violating other Autosar rules.<br />
<br />
Thanks!]]></content:encoded>
		</item>
	</channel>
</rss>