From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) by sourceware.org (Postfix) with ESMTP id 1965D3860753 for ; Sat, 17 Feb 2024 21:34:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1965D3860753 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gentoo.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gentoo.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1965D3860753 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=140.211.166.183 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708205678; cv=none; b=WaTO2UF4gkcmsKzSxqEfTnaqXZW5o1DZ3DhZwsoOZXULAkpwkJwQBF+volax9pAF3FsyGLlJEh/XJCZWuxDySocHSf+04xZIdLI2+supvHXr7AwLJOpeKT8QTwZFNqXdhrAwBy80DfMjq4MfbjVD6xan9B1FZ2RqxLSruGAN8cY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708205678; c=relaxed/simple; bh=ok6NdcNja1/tbidkF+E4scGylbCaT2A2aboU0yEL8LY=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=XLnLwJmvHRvLDVy8CZki7EeRyr2UVGrwvfGj2KGwqrtN/S9POQVEGSz0dpceDkfj2XeOv7I51cIVdImRMQxeMZIg1xRUF0IqdhozIFA/mu0ytzsbRuYW1ygIESAE+bB8XVVFf/O2Eya80Mg+BiRWOgNIGjhRz6JHBPgJbNQs8UI= ARC-Authentication-Results: i=1; server2.sourceware.org References: <87ttm74dz4.fsf@oldenburg.str.redhat.com> User-agent: mu4e 1.10.8; emacs 30.0.50 From: Sam James To: Florian Weimer Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH wwwdocs] gcc-14: Add code examples for -Wreturn-mismatch Date: Sat, 17 Feb 2024 21:33:56 +0000 Organization: Gentoo In-reply-to: <87ttm74dz4.fsf@oldenburg.str.redhat.com> Message-ID: <87y1bikc5y.fsf@gentoo.org> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Florian Weimer 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 voi= d, or > return statements without expressions for functions > returning a non-void type. >=20=20 > +

> +Both function definitions below contain -Wreturn-mismatch > +errors: > + > +

> +void
> +do_something (int flag)
> +{
> +  if (!flag)
> +    return -1;
> +  do_something_else ();
> +}
> +
> +int
> +unimplemented_function (void)
> +{
> +  puts ("unimplemented function foo called");
> +}
> +
> + > + >

> To address this, remove the incorrect expression (or turn it into a > statement expression immediately prior to the return > 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. > + > +

> +void
> +do_something (int flag)
> +{
> +  if (!flag)
> +    return -1;
> +  do_something_else ();
> +}
> +
> +int
> +unimplemented_function (void)
> +{
> +  puts ("unimplemented function foo called");
> +  return 0;
> +}
> +
> + > +If there is no suitable dummy return value, further changes may be > +needed to implement appropriate error handling. LGTM. >=20=20 >

> Previously, these mismatches were diagnosed as > a -Wreturn-type 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 } of function that does not > +brace } of a function that does not > return void. >=20=20 >

> > base-commit: 5ef0adf3098478600f0c108e07e568d864b4c731 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iOUEARYKAI0WIQQlpruI3Zt2TGtVQcJzhAn1IN+RkAUCZdEmaV8UgAAAAAAuAChp c3N1ZXItZnByQG5vdGF0aW9ucy5vcGVucGdwLmZpZnRoaG9yc2VtYW4ubmV0MjVB NkJCODhERDlCNzY0QzZCNTU0MUMyNzM4NDA5RjUyMERGOTE5MA8cc2FtQGdlbnRv by5vcmcACgkQc4QJ9SDfkZBN3AEA2o0epUqcWxZnfbeWSWC+owsaP+feLc1NuGZ1 bK75Qx0A/jk6pCHGKGfoFbctyVMnivo6QrVm82DLiEZ/JLodCsgD =/WYM -----END PGP SIGNATURE----- --=-=-=--