From patchwork Sat Feb 17 09:49:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 202593 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp237359dyc; Sat, 17 Feb 2024 01:50:41 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXfIqvbNviiGK/YVg1R1+wOjxAqpyCu7Po5TW6U7xnsxFcRu4rn8Lq2wvNwgGsX8PW8iljMMQBHrBn2x5AmHXzkeDp8LA== X-Google-Smtp-Source: AGHT+IGwm5OGfq4SyqCxypNKprkkAx7aexQbrQ4AaXUMKhV8dhr0XMZBRtrDQxE1gMWHZ9rbBgUU X-Received: by 2002:a05:622a:174a:b0:42d:e964:be55 with SMTP id l10-20020a05622a174a00b0042de964be55mr4262246qtk.19.1708163441037; Sat, 17 Feb 2024 01:50:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708163441; cv=pass; d=google.com; s=arc-20160816; b=kRixaBTYd1bQtBOa61X1TwgTfyGXdCJXn8KlE3Dr7vF8Uci8EMFEWlSJtMO2vpy8KJ 0aZjQVfQGdOmQhiuXviVC4jCroLxuZ+i626ZWMG7PNEYT75NkDa0oos2ECGIhFaa4OsX Hk4FpTU188rmpac+jc813fVa3dzfre/tbdaCMxodGw4ZsB/s49AAvCgdgxpLpPA/FGXj uREB4LyNB/K3Qa/rVsT9YVMfsRpXm41XJm983uBpZHF+ATzfCXScPFDjYQ2ja/tcPW5r CCGeGb/WYJhQ6la+u8qA6rUyi5uKpw0w8XXrk0Q7mFCcDA5iQQSTmVkaUC4xkt75dTQQ RXaw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:message-id:date :subject:to:from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=Gvjl+xZMxST5tv/kiW9ZV7SwQIiNKMZzXx4TyGcUsGc=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=G2e1x+V3w6CMmiqypyNHELN2JF264N+YfktFM1LssDDH7fEMMztm38ptFV/aIfeQeM sCouPO4Youa7ki7s/8mrtQ+/AOw+12TmzJ0BJD7IYevpAanHY9BVkPqR04SQeWHAlxBl YGa3gEIHZOU5vzasbLBK3LiQ2DB02xTBQbfd8kpflYzPZv71XBmHpcBkrTceaoOrXX/f oigiqNtKv3RHiK+Z6oz7u46Ux304mDPVnpvBOpb188NfeEk/7Bse7X2CoBlG/n1DW2Og 1EQjwLzZcRDvM1I/HeA02HJeYxwoDqZrVJhKoy3OlX//7YueaS0RLYifrCQPdXgHUD0d 8RpQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LnCoPVGF; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id c2-20020ac87dc2000000b0042a2aef2a52si1899608qte.439.2024.02.17.01.50.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Feb 2024 01:50:41 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LnCoPVGF; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B8F20385DC09 for ; Sat, 17 Feb 2024 09:50:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 99BD43858D33 for ; Sat, 17 Feb 2024 09:49:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 99BD43858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 99BD43858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708163400; cv=none; b=x3jzVB3pAgf8FQiDwKxdr7iQc/AJR9bBtpw/kaR9bKs7HY9jERPU+fIa0PzlgGUvdm863SjzwPYdkwAf9FoPt6V/xydf4tJmK7v3CoDtFCaJzx4pI+MvcgsK9pGKpu29rOGZERpHHvxMfDdLZdNUaz5SNx7Y9eNdon9FcJG/yjE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708163400; c=relaxed/simple; bh=SAd47OaTw5ULyinhygidkpsN8hQFbmnIqu8qToIGOqY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=iC9hll8/5ewJ8E3C5JAua0EycsPbatfhVgAakU9ASIkdF3z7c97OiJjSi1Q636mWtA8yUqi2sWhk5y8Z9hqnwgN84GuxWQLRXnhQVjUAczNeXy78um/cA2Xf7DnwJOmTseAGAAFgMWxL6cVhKyqXiOW+koexJZ9aH+gZxnQabj0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708163395; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=Gvjl+xZMxST5tv/kiW9ZV7SwQIiNKMZzXx4TyGcUsGc=; b=LnCoPVGFktq01lYb8gu/nE8dF42cOwgCBdsyM/S364wHQ27HtebW7zIMz13EuvOYMDSNda f4Bifval5kYNC0ex6cuFnCDuibl74nG5wH8+qRlHm9jBjsKjkBrhTH5eWpFja5nxD3pK3f sBr/W8WWNGaeRNlFQcAkPsEHjs9visg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-690-olaKq4OxMr-6dFKpbbBqig-1; Sat, 17 Feb 2024 04:49:53 -0500 X-MC-Unique: olaKq4OxMr-6dFKpbbBqig-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 93A2A101A52A for ; Sat, 17 Feb 2024 09:49:53 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EE0EF2166B33 for ; Sat, 17 Feb 2024 09:49:52 +0000 (UTC) From: Florian Weimer To: gcc-patches@gcc.gnu.org Subject: [PATCH wwwdocs] gcc-14: Add code examples for -Wreturn-mismatch Date: Sat, 17 Feb 2024 10:49:51 +0100 Message-ID: <87ttm74dz4.fsf@oldenburg.str.redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791139188054955817 X-GMAIL-MSGID: 1791139188054955817 --- htdocs/gcc-14/porting_to.html | 46 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) base-commit: 5ef0adf3098478600f0c108e07e568d864b4c731 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 void, or return statements without expressions for functions returning a non-void type. +

+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.

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.