From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id DFC903858D28 for ; Sun, 30 Jan 2022 11:17:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DFC903858D28 Received: by mail-wr1-x432.google.com with SMTP id e8so19986072wrc.0 for ; Sun, 30 Jan 2022 03:17:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=qWl4Z4QrqUyYboDHkdG8ZWWYKitUKz20T7v/SrUjeuM=; b=ZhPIHwrPjWjN4GYWqeorU5CGruSy3pkix06tzfyWd8Ev1dtkVLTQ/flkDs9mXYVFAl +VFNJymjr7WKbM5+dPrNWwPoFp+N1MiofabdcgWxHTs70jH3ggXOHfqGFJTqanQAwLQ4 VS6PLlhs+KMgI1IwAQC8bf38QFhpEWzdg9IhKK8Ip9RWRAlFIuo5wKkyxlwcvhFi4erc M4qoU6WS4/SXHditriSB5IAhQ/a7ILHMLCFSCUqGSfbw3zp3QaLGlP1wrx3PPlx9Np/X eaqZTn8+GwZe7d2Wx06sPOS8bSAddCPu6t9z/kSt66pQKiJcI6TK9DZk18MrgE9zlxeC rKUA== X-Gm-Message-State: AOAM530OVKDTcaqVht2bkEelvHo+dbMBnTJR2OmL45IYSwrQXPiW9gQL eakj/YPg4jgvRCLB3sjus3FXIrR6iTu4/0LxhNU= X-Google-Smtp-Source: ABdhPJxPfnT88gz+xG3WFij4cj4GOJz5FNjiPFt8+6a5GehxiqjLkETFREgNhSo2mHWNVxhbIkyUkREqDMUNUO2LLGE= X-Received: by 2002:a5d:4c81:: with SMTP id z1mr13329676wrs.568.1643541451955; Sun, 30 Jan 2022 03:17:31 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Sun, 30 Jan 2022 11:17:17 +0000 Message-ID: Subject: Re: Enquiry To: Theodore Papadopoulo Cc: "gcc@gcc.gnu.org" X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 30 Jan 2022 11:17:34 -0000 Meta-comment: a subject line of "Enquiry" is very vague, and most commonly used by spammers and phishers. Your enquiry is about undefined behaviour due to a missing return, which would have been a much better subject. On Sun, 30 Jan 2022, 09:48 Theodore Papadopoulo, < Theodore.Papadopoulo@inria.fr> wrote: > Before creating a bug report, I want to check with the GCC community > (all the more that checking that the problem has not yet been reported > is complicated at leat for me). > > The following (admitedly buggy) program generates a segmentation > violation on fedora 35 (this is with g++ 11.2.1 20211203 (Red Hat > 11.2.1-7) (GCC)) > when compiled with -O3 (other versions replacing unisgned by std::string > may trigger the exception instead of the segv) > > bool assert_sthg(const unsigned s) { > if (s==123) > throw 1; > } > > int main() { > assert_sthg(0); > return 0; > } > > When compiling, we indeed get a warning: > > test.C:4:1: warning: control reaches end of non-void function > [-Wreturn-type] > > I can well understand that the program being buggy that the optimizer is > allowed to do anything including the observed segmentation violation. > Yet the result is quite surprising.... > The question is, in that case, wouldn't it be better to turn the warning > into an error at -O3 ? > > Thank's for any input. > > Theo. > >