From patchwork Wed Feb 6 16:51:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1037627 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-495391-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="pxC/SZfu"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="pIyNqi/Y"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43vnYD2cLlz9s7h for ; Thu, 7 Feb 2019 03:52:13 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=NrQcbI/7No0eNaLQ3pcBVE42yccRvab9nWuXxlFPiPUPvYI+21 WsKMdUO+1lqTFPNxRDXpTQ9u3n7E+lUg2sK4wIkKsnVLCagyfVYaMFcavhCvBc96 ASknOMOutN82/wpOGuqf/vp9uglyjMeyI3pUeEdKwGqugcrTWnwN6fNts= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=Ejt/RoFIFqYDWLH5A+9BeZH+AlE=; b=pxC/SZfu35iRe5itM2aW EX3Eryjgp8MJQA+lJdaAXv6+weUlcIjgi4NagSIRQ3C/LS1VLwqOL+sHANRjWcfR GuITVaOTJVUMiqMs+a/RKdi43bulEpAwT0FUl4pfncZhOx6zFTMR77YsKSq4/M6s tRHRkyjgLoUYjSQSJ5eMy6I= Received: (qmail 19568 invoked by alias); 6 Feb 2019 16:52:06 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 19560 invoked by uid 89); 6 Feb 2019 16:52:06 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=AKA, states, documents X-HELO: mail-qk1-f172.google.com Received: from mail-qk1-f172.google.com (HELO mail-qk1-f172.google.com) (209.85.222.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 06 Feb 2019 16:52:05 +0000 Received: by mail-qk1-f172.google.com with SMTP id y140so4645522qkb.9 for ; Wed, 06 Feb 2019 08:52:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=4Ym/wHv8GI3Dzovq0EZN6iaJAdaiptck6YSpF26D4Pg=; b=pIyNqi/YbfZyk/8991EBnhOENjScsZPh6185U6/ILNjRC1WZedb9ArWaFftnpw2Oat gC6mDrNoeVkU8G8LMNVzC11r0c7cq0vJXd/9qRaOF8/ZYr43B8wCBZLYgqiymHpjVu3L 21ooTcChlH/nccZh4057Xb+ORgZNIYtQhp/DKR3Vft7UQisNDeYNVvVbipvXr5inuJYY Uay2Pkd5YD7EpW+CDBT6GhpfVYjsZecZc4AgkrKVWXpKyKOuEsKRGmuhRDCtTr+R7UZ9 pjjylRenSgun8KhzqIsMpZOMkpRZP5kn+xJIHGaXNctdVzY+Al4/8r8DvjYPeDXbhGtL 9+iQ== Received: from [192.168.0.106] (97-118-121-10.hlrn.qwest.net. [97.118.121.10]) by smtp.gmail.com with ESMTPSA id x39sm2853887qtj.12.2019.02.06.08.52.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Feb 2019 08:52:00 -0800 (PST) To: "gcc-patches@gcc.gnu.org" From: Martin Sebor Subject: [PATCH doc] correct/expand -Wreturn-type Message-ID: Date: Wed, 6 Feb 2019 09:51:59 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 X-IsSubscribed: yes A recent flurry of bug reports about wrong code in C++ due to flowing (AKA falling) off the end of a function prompted me to look at what the manual has to say about the undefined behavior that the warning is meant to point out. It turns out that the manual not only doesn't mention it, but it also incorrectly states that in C++, -Wreturn-type cannot be suppressed by -Wno-return-type. The attached patch documents the undefined behavior and removes the statement about -Wno-return-type having no effect in C++. Martin PS The C++ standard uses the term "flow of the end" so I used that in the new text even though the C paragraph refers to it as "falling off the end." gcc/ChangeLog: * doc/invoke.texi (-Wreturn-type): Correct and expand. Index: gcc/doc/invoke.texi =================================================================== --- gcc/doc/invoke.texi (revision 268583) +++ gcc/doc/invoke.texi (working copy) @@ -5261,13 +5261,15 @@ without a value). For C only, warn about a @code{return} statement with an expression in a function whose return type is @code{void}, unless the expression type is also @code{void}. As a GNU extension, the latter case is accepted -without a warning unless @option{-Wpedantic} is used. +without a warning unless @option{-Wpedantic} is used. Attempting +to use the return value of a non-@code{void} function other than @code{main} +that flows off the end by reaching the closing curly brace that terminates +the function is undefined. -For C++, a function without return type always produces a diagnostic -message, even when @option{-Wno-return-type} is specified. The only -exceptions are @code{main} and functions defined in system headers. +For C++, calling a non-@code{void} function other than @code{main} that flows +off the end is undefined even if the value of the function is not used. -This warning is enabled by default for C++ and is enabled by @option{-Wall}. +This warning is enabled by default in C++ and by @option{-Wall} otherwise. @item -Wshift-count-negative @opindex Wshift-count-negative