<?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.16 Overloading]]></title>
		<link>https://forum.misra.org.uk/</link>
		<description><![CDATA[MISRA Discussion Forums - https://forum.misra.org.uk]]></description>
		<pubDate>Fri, 13 Nov 2026 11:06:22 +0000</pubDate>
		<generator>MyBB</generator>
		<item>
			<title><![CDATA[16.6.1 clarification]]></title>
			<link>https://forum.misra.org.uk/showthread.php?tid=1733</link>
			<pubDate>Wed, 26 Mar 2025 14:36: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=1733</guid>
			<description><![CDATA[Hi,<br />
<br />
Rule 16.6.1 marks this example as non-compliant:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>C operator+( int32_t rhs ) const;  // Non-compliant</code></div></div><br />
However it does not provide a compliant alternative. It's unclear if rule 16.6.1 wants us to:<br />
<br />
a) Duplicate the function and create 2 versions for each order of the parameters, in order to guarantee symmetry (even if it may not be useful for the user, potentially being dead code):<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>C operator+(C  &nbsp;&nbsp;&nbsp;&nbsp; lhs, int32_t rhs );<br />
C operator+(int32_t lhs, C  &nbsp;&nbsp;&nbsp;&nbsp; rhs );</code></div></div><br />
b) Implement only 1 overload, but as a non-member function. This still does not solve the problem of "operator+ must be symmetrical", i.e that "1 + c" and "c + 1" must be supported.<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>friend C operator+(C lhs, int32_t rhs );</code></div></div><br />
Could you clarify?<br />
<br />
Thanks!]]></description>
			<content:encoded><![CDATA[Hi,<br />
<br />
Rule 16.6.1 marks this example as non-compliant:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>C operator+( int32_t rhs ) const;  // Non-compliant</code></div></div><br />
However it does not provide a compliant alternative. It's unclear if rule 16.6.1 wants us to:<br />
<br />
a) Duplicate the function and create 2 versions for each order of the parameters, in order to guarantee symmetry (even if it may not be useful for the user, potentially being dead code):<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>C operator+(C  &nbsp;&nbsp;&nbsp;&nbsp; lhs, int32_t rhs );<br />
C operator+(int32_t lhs, C  &nbsp;&nbsp;&nbsp;&nbsp; rhs );</code></div></div><br />
b) Implement only 1 overload, but as a non-member function. This still does not solve the problem of "operator+ must be symmetrical", i.e that "1 + c" and "c + 1" must be supported.<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>friend C operator+(C lhs, int32_t rhs );</code></div></div><br />
Could you clarify?<br />
<br />
Thanks!]]></content:encoded>
		</item>
	</channel>
</rss>