From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mengyan1223.wang (mengyan1223.wang [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 2B9723858D3C for ; Sun, 23 Jan 2022 10:02:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2B9723858D3C Received: from localhost.localdomain (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@mengyan1223.wang) by mengyan1223.wang (Postfix) with ESMTPSA id 8E40065A9A; Sun, 23 Jan 2022 05:02:49 -0500 (EST) Message-ID: Subject: Re: Pure/const function not getting executed as the first operand to logical OR ( || ) (C++) From: Xi Ruoyao To: Vishal Subramanyam Cc: gcc-help@gcc.gnu.org Date: Sun, 23 Jan 2022 18:02:46 +0800 In-Reply-To: References: <7107aa063c391c0c3dd9e1b9641f7e5a5df9aa31.camel@mengyan1223.wang> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.3 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3031.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, JMQ_SPF_NEUTRAL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Jan 2022 10:02:52 -0000 On Sun, 2022-01-23 at 09:56 +0000, Vishal Subramanyam wrote: > This still doesn't explain why an O1 level optimization can violate > the standard by not evaluating the first operand. It's not violating the standard. The standard says division-by-zero is an undefined behavior, so the compiler can do anything. > What optimization is my code triggering with -fno-inline? My function > clearly has a return value, so how did the compiler > decide that the return value doesn't matter? -- Xi Ruoyao School of Aerospace Science and Technology, Xidian University