public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH wwwdocs] gcc-14: Add code examples for -Wreturn-mismatch
@ 2024-02-17  9:49 Florian Weimer
  2024-02-17 21:33 ` Sam James
  0 siblings, 1 reply; 2+ messages in thread
From: Florian Weimer @ 2024-02-17  9:49 UTC (permalink / raw)
  To: gcc-patches

---
 htdocs/gcc-14/porting_to.html | 46 ++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 43 insertions(+), 3 deletions(-)

diff --git a/htdocs/gcc-14/porting_to.html b/htdocs/gcc-14/porting_to.html
index bbbaa25a..123b5e9f 100644
--- a/htdocs/gcc-14/porting_to.html
+++ b/htdocs/gcc-14/porting_to.html
@@ -213,19 +213,59 @@ in functions which are declared to return <code>void</code>, or
 <code>return</code> statements without expressions for functions
 returning a non-<code>void</code> type.
 
+<p>
+Both function definitions below contain <code>-Wreturn-mismatch</code>
+errors:
+
+<pre>
+void
+do_something (int flag)
+{
+  if (!flag)
+    return -1;
+  do_something_else ();
+}
+
+int
+unimplemented_function (void)
+{
+  puts ("unimplemented function foo called");
+}
+</pre>
+
+
 <p>
 To address this, remove the incorrect expression (or turn it into a
 statement expression immediately prior to the <code>return</code>
 statements if the expression has side effects), or add a dummy return
-value, as appropriate.  If there is no suitable dummy return value,
-further changes may be needed to implement appropriate error handling.
+value, as appropriate.
+
+<pre>
+void
+do_something (int flag)
+{
+  if (!flag)
+    return<del> -1</del>;
+  do_something_else ();
+}
+
+int
+unimplemented_function (void)
+{
+  puts ("unimplemented function foo called");
+  <ins>return 0;</ins>
+}
+</pre>
+
+If there is no suitable dummy return value, further changes may be
+needed to implement appropriate error handling.
 
 <p>
 Previously, these mismatches were diagnosed as
 a <code>-Wreturn-type</code> warning.  This warning still exists, and
 is not treated as an error by default.  It now covers remaining
 potential correctness issues, such as reaching the closing
-brace <code>}</code> of function that does not
+brace <code>}</code> of a function that does not
 return <code>void</code>.
 
 <p>

base-commit: 5ef0adf3098478600f0c108e07e568d864b4c731


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH wwwdocs] gcc-14: Add code examples for -Wreturn-mismatch
  2024-02-17  9:49 [PATCH wwwdocs] gcc-14: Add code examples for -Wreturn-mismatch Florian Weimer
@ 2024-02-17 21:33 ` Sam James
  0 siblings, 0 replies; 2+ messages in thread
From: Sam James @ 2024-02-17 21:33 UTC (permalink / raw)
  To: Florian Weimer; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 2247 bytes --]


Florian Weimer <fweimer@redhat.com> writes:

> ---
>  htdocs/gcc-14/porting_to.html | 46 ++++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 43 insertions(+), 3 deletions(-)
>
> diff --git a/htdocs/gcc-14/porting_to.html b/htdocs/gcc-14/porting_to.html
> index bbbaa25a..123b5e9f 100644
> --- a/htdocs/gcc-14/porting_to.html
> +++ b/htdocs/gcc-14/porting_to.html
> @@ -213,19 +213,59 @@ in functions which are declared to return <code>void</code>, or
>  <code>return</code> statements without expressions for functions
>  returning a non-<code>void</code> type.
>  
> +<p>
> +Both function definitions below contain <code>-Wreturn-mismatch</code>
> +errors:
> +
> +<pre>
> +void
> +do_something (int flag)
> +{
> +  if (!flag)
> +    return -1;
> +  do_something_else ();
> +}
> +
> +int
> +unimplemented_function (void)
> +{
> +  puts ("unimplemented function foo called");
> +}
> +</pre>
> +
> +
>  <p>
>  To address this, remove the incorrect expression (or turn it into a
>  statement expression immediately prior to the <code>return</code>
>  statements if the expression has side effects), or add a dummy return
> -value, as appropriate.  If there is no suitable dummy return value,
> -further changes may be needed to implement appropriate error handling.
> +value, as appropriate.
> +
> +<pre>
> +void
> +do_something (int flag)
> +{
> +  if (!flag)
> +    return<del> -1</del>;
> +  do_something_else ();
> +}
> +
> +int
> +unimplemented_function (void)
> +{
> +  puts ("unimplemented function foo called");
> +  <ins>return 0;</ins>
> +}
> +</pre>
> +
> +If there is no suitable dummy return value, further changes may be
> +needed to implement appropriate error handling.

LGTM.

>  
>  <p>
>  Previously, these mismatches were diagnosed as
>  a <code>-Wreturn-type</code> warning.  This warning still exists, and
>  is not treated as an error by default.  It now covers remaining
>  potential correctness issues, such as reaching the closing
> -brace <code>}</code> of function that does not
> +brace <code>}</code> of a function that does not
>  return <code>void</code>.
>  
>  <p>
>
> base-commit: 5ef0adf3098478600f0c108e07e568d864b4c731


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 377 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-17 21:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-17  9:49 [PATCH wwwdocs] gcc-14: Add code examples for -Wreturn-mismatch Florian Weimer
2024-02-17 21:33 ` Sam James

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).