<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en" style='--code-editor-font: var(--default-mono-font, "GitLab Mono"), JetBrains Mono, Menlo, DejaVu Sans Mono, Liberation Mono, Consolas, Ubuntu Mono, Courier New, andale mono, lucida console, monospace;'>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>
GitLab
</title>
<style data-premailer="ignore" type="text/css">
a { color: #1068bf; }
</style>
<style>img {
max-width: 100%; height: auto;
}
body {
font-size: .875rem;
}
body {
-webkit-text-shadow: rgba(255,255,255,.01) 0 0 1px;
}
body {
font-family: "GitLab Sans",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans",Ubuntu,Cantarell,"Helvetica Neue",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji"; font-size: inherit;
}
</style>
</head>
<body style='font-size: inherit; -webkit-text-shadow: rgba(255,255,255,.01) 0 0 1px; font-family: "GitLab Sans",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans",Ubuntu,Cantarell,"Helvetica Neue",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";'>
<div class="content">
<p style="color: #777777;">
<a href="https://gitlab.rtems.org/joel">Joel Sherrill</a>
commented on a
discussion on <a href="https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/803#note_135132">cpukit/libdebugger/rtems-debugger-aarch64.c</a>:
</p>
<table class="code gl-mb-5" style="border-spacing: 0; margin-bottom: 1rem; border-collapse: collapse; width: auto; font-family: monospace; font-size: 90%;" bgcolor="#ffffff" width="100%" cellpadding="0" cellspacing="0">
<tr class="line_holder" style="line-height: 1.6;">
<td class="old_line diff-line-num" data-linenumber="1027" style="width: 35px; color: rgba(5,5,6,.24); border-right-width: 1px; border-right-color: #ececef; border-right-style: solid; padding: inherit;" align="right" bgcolor="#fbfafd">
1027
</td>
<td class="new_line diff-line-num" data-linenumber="1027" style="width: 35px; color: rgba(5,5,6,.24); border-right-width: 1px; border-right-color: #ececef; border-right-style: solid; padding: inherit;" align="right" bgcolor="#fbfafd">
1027
</td>
<td class="line_content" style="padding: inherit;"><pre style='display: block; font-size: 14px; color: #3a383f; position: relative; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: break-all; word-wrap: break-word; background-color: inherit; border-radius: 2px; margin: 0; padding: 0; border: inherit solid #dcdcde;'> <span class="line" data-lang="c"> <span class="n" style="color: #333333;">memcpy</span><span class="p">(</span> <span class="o" style="font-weight: 600;">&</span><span class="kr" style="font-weight: 600;">thread</span><span class="o" style="font-weight: 600;">-></span><span class="n" style="color: #333333;">registers</span><span class="p">[</span> <span class="n" style="color: #333333;">offset</span> <span class="p">],</span> <span class="o" style="font-weight: 600;">&</span><span class="n" style="color: #333333;">value</span><span class="p">,</span> <span class="k" style="font-weight: 600;">sizeof</span><span class="p">(</span> <span class="kt" style="color: #445588; font-weight: 600;">uint64_t</span> <span class="p">)</span> <span class="p">);</span></span>
</pre></td>
</tr>
<tr class="line_holder" style="line-height: 1.6;">
<td class="old_line diff-line-num" data-linenumber="1028" style="width: 35px; color: rgba(5,5,6,.24); border-right-width: 1px; border-right-color: #ececef; border-right-style: solid; padding: inherit;" align="right" bgcolor="#fbfafd">
1028
</td>
<td class="new_line diff-line-num" data-linenumber="1028" style="width: 35px; color: rgba(5,5,6,.24); border-right-width: 1px; border-right-color: #ececef; border-right-style: solid; padding: inherit;" align="right" bgcolor="#fbfafd">
1028
</td>
<td class="line_content" style="padding: inherit;"><pre style='display: block; font-size: 14px; color: #3a383f; position: relative; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: break-all; word-wrap: break-word; background-color: inherit; border-radius: 2px; margin: 0; padding: 0; border: inherit solid #dcdcde;'> <span class="line" data-lang="c"><span class="p">}</span></span>
</pre></td>
</tr>
<tr class="line_holder" style="line-height: 1.6;">
<td class="old_line diff-line-num" data-linenumber="1029" style="width: 35px; color: rgba(5,5,6,.24); border-right-width: 1px; border-right-color: #ececef; border-right-style: solid; padding: inherit;" align="right" bgcolor="#fbfafd">
1029
</td>
<td class="new_line diff-line-num" data-linenumber="1029" style="width: 35px; color: rgba(5,5,6,.24); border-right-width: 1px; border-right-color: #ececef; border-right-style: solid; padding: inherit;" align="right" bgcolor="#fbfafd">
1029
</td>
<td class="line_content" style="padding: inherit;"><pre style='display: block; font-size: 14px; color: #3a383f; position: relative; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: break-all; word-wrap: break-word; background-color: inherit; border-radius: 2px; margin: 0; padding: 0; border: inherit solid #dcdcde;'> <span class="line" data-lang="c"></span>
</pre></td>
</tr>
<tr class="line_holder old" style="line-height: 1.6;">
<td class="old_line diff-line-num old" data-linenumber="1030" style="width: 35px; color: rgba(5,5,6,.24); border-right-width: 1px; border-right-color: #fac5cd; border-right-style: solid; padding: inherit;" align="right" bgcolor="#f9d7dc">
1030
</td>
<td class="new_line diff-line-num old" data-linenumber="1030" style="width: 35px; color: rgba(5,5,6,.24); border-right-width: 1px; border-right-color: #fac5cd; border-right-style: solid; padding: inherit;" align="right" bgcolor="#f9d7dc">
</td>
<td class="line_content old" style="padding: inherit;" bgcolor="#fbe9eb"><pre style='display: block; font-size: 14px; color: #3a383f; position: relative; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: break-all; word-wrap: break-word; background-color: inherit; border-radius: 2px; margin: 0; padding: 0; border: inherit solid #dcdcde;'>-<span class="line" data-lang="c"><span class="k" style="font-weight: 600;">static</span> <span class="k" style="font-weight: 600;"><span class="idiff left deletion" style="background-color: #fac5cd;">const</span></span><span class="idiff right deletion" style="background-color: #fac5cd;"> </span><span class="kt" style="color: #445588; font-weight: 600;">uint64_t</span> <span class="nf" style="color: #990000; font-weight: 600;">rtems_debugger_get_int_reg</span><span class="p">(</span></span>
</pre></td>
</tr>
<tr class="line_holder new" style="line-height: 1.6;">
<td class="old_line diff-line-num new" data-linenumber="1031" style="width: 35px; color: rgba(5,5,6,.24); border-right-width: 1px; border-right-color: #c7f0d2; border-right-style: solid; padding: inherit;" align="right" bgcolor="#ddfbe6">
</td>
<td class="new_line diff-line-num new" data-linenumber="1030" style="width: 35px; color: rgba(5,5,6,.24); border-right-width: 1px; border-right-color: #c7f0d2; border-right-style: solid; padding: inherit;" align="right" bgcolor="#ddfbe6">
1030
</td>
<td class="line_content new" style="padding: inherit;" bgcolor="#ecfdf0"><pre style='display: block; font-size: 14px; color: #3a383f; position: relative; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: break-all; word-wrap: break-word; background-color: inherit; border-radius: 2px; margin: 0; padding: 0; border: inherit solid #dcdcde;'>+<span class="line" data-lang="c"><span class="k" style="font-weight: 600;">static</span> <span class="kt" style="color: #445588; font-weight: 600;">uint64_t</span> <span class="nf" style="color: #990000; font-weight: 600;">rtems_debugger_get_int_reg</span><span class="p">(</span></span>
</pre></td>
</tr>
</table>
<div class="md" style="position: relative; z-index: 1; color: #3a383f; word-wrap: break-word;">
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">Starting with the GCC documentation on the -Wignored-qualifiers option, specifying const on a function that returns a scalar type is meaningless. In C, it is enforced as an attribute of returned pointers.</p>
<blockquote dir="auto" style="font-size: inherit; color: #626168; border-left-style: solid; margin: 0.5rem 0; padding: 0.5rem 0 0.5rem 1rem; border-color: #bfbfc3; border-width: 0 0 0 4px;" align="initial">
<p style="color: inherit; line-height: 1.5; margin: 0 0 1rem;">'-Wignored-qualifiers (C and C++ only)'
Warn if the return type of a function has a type qualifier such as
'const'. For ISO C such a type qualifier has no effect, since the
value returned by a function is not an lvalue. For C++, the
warning is only emitted for scalar types or 'void'. ISO C
prohibits qualified 'void' return types on function definitions, so
such return types always receive a warning even without this
option.</p>
<div class="gl-relative markdown-code-block js-markdown-code">
<pre class="code highlight js-syntax-highlight language-plaintext" v-pre="true" style="display: block; font-size: 90%; color: #3a383f; line-height: 1.6em; overflow-x: auto; border-radius: .25rem; position: relative; font-family: monospace; font-variant-ligatures: none; word-break: break-all; word-wrap: break-word; background-color: #ffffff; -premailer-cellpadding: 0; -premailer-cellspacing: 0; -premailer-width: 100%; margin: 0 0 1rem; padding: 12px; border: 1px solid #dcdcde;"><code style='font-size: inherit; color: inherit; word-wrap: normal; word-break: keep-all; border-radius: .25rem; background-color: inherit; white-space: pre; margin-top: 0; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; overflow-wrap: normal; padding: unset;'><span id="LC1" class="line" lang="plaintext" style="margin-top: 0;"> This warning is also enabled by '-Wextra'.</span></code></pre>
<copy-code></copy-code><insert-code-snippet></insert-code-snippet>
</div>
</blockquote>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">I found a <a href="https://stackoverflow.com/questions/1134237/pedantic-gcc-warning-type-qualifiers-on-function-return-type" rel="nofollow noreferrer noopener" target="_blank" style="margin-top: 0;">Stack Overflow discussion</a> on this but it does not seem to add much. Someone noted that having the const on the function return value and it being meaningless could result in a programmer thinking there is some guarantee being checked on the function where there simply is none. I found this statement at <a href="https://www.eevblog.com/forum/programming/c-functions-with-volatile-return-types-what-does-it-mean/" rel="nofollow noreferrer noopener" target="_blank">EEVBlog Electronics</a> which aligns with "you can type it, but it is meaningless".</p>
<blockquote dir="auto" style="font-size: inherit; color: #626168; border-left-style: solid; margin: 0.5rem 0; padding: 0.5rem 0 0.5rem 1rem; border-color: #bfbfc3; border-width: 0 0 0 4px;" align="initial">
<p style="color: inherit; line-height: 1.5; margin: 0 0 1rem;">In C language it means absolutely nothing. In C the return value is an rvalue and C does not support cv-qualification of rvalues. Meaning that you can legally apply such qualification in the source code, but it will be ignored anyway.</p>
<p style="color: inherit; line-height: 1.5; margin: 0;">It is all natural aside from one corner case, which exists since C99: when the returned object is a struct with an array inside.</p>
</blockquote>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">This reminds me of a line from <em style="margin-top: 0;">The Princess Bride</em> where Inigo Montoya says "You keep saying that word. I do not think it means what you think it means."</p>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">I have asked a contact at one of the companies that makes a static analyzer that includes checking against various coding standards including MISRA. Hopefully they can add some more to the rationale.</p>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">Beyond that, this warning only flagged these cases. How do you think this comment should be resolved?</p>
<ol dir="auto" style="text-align: initial; margin: 0 0 1rem; padding: 0;">
<li style="margin-top: 0; line-height: 1.6em; margin-left: 25px; padding-left: 3px;">One option add this information to the Coding Guidelines in the Software Engineering Guide.</li>
<li style="line-height: 1.6em; margin-left: 25px; padding-left: 3px;">Another is to consider this discussion sufficient.</li>
<li style="line-height: 1.6em; margin-left: 25px; padding-left: 3px;">Disable this warning even though this pattern is rare in the code base. This MR addresses all cases.</li>
</ol>
<p dir="auto" style="color: #3a383f; margin: 0;" align="initial">What's your preference? It is involves documentation, resolve with an issue in rtems-docs to address this.</p>
</div>
</div>
<div class="footer" style="margin-top: 10px;">
<p style="font-size: small; color: #626168;">
—
<br>
<a href="https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/803#note_135132">View it on GitLab</a>.
<br>
You're receiving this email because of your account on <a target="_blank" rel="noopener noreferrer" href="https://gitlab.rtems.org">gitlab.rtems.org</a>. <a href="https://gitlab.rtems.org/-/sent_notifications/b63f1e2d3ec928e6e6c937c33031d9e6/unsubscribe" target="_blank" rel="noopener noreferrer">Unsubscribe</a> from this thread · <a href="https://gitlab.rtems.org/-/profile/notifications" target="_blank" rel="noopener noreferrer" class="mng-notif-link">Manage all notifications</a> · <a href="https://gitlab.rtems.org/help" target="_blank" rel="noopener noreferrer" class="help-link">Help</a>
<span style="color: transparent; font-size: 0; display: none; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0;">
Notification message regarding https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/803#note_135132 at 1760711687
</span>
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Merge request","url":"https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/803#note_135132"}}</script>
</p>
</div>
</body>
</html>