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: 85920 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 284AE3858436 for ; Sat, 17 Feb 2024 09:50:28 +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+patchwork=sourceware.org@gcc.gnu.org --- 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.