From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (wildebeest.demon.nl [212.238.236.112]) by sourceware.org (Postfix) with ESMTPS id CB741384607B for ; Tue, 29 Jun 2021 09:10:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CB741384607B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: from reform (deer0x00.wildebeest.org [172.31.17.130]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 3D9993000ADC; Tue, 29 Jun 2021 11:10:25 +0200 (CEST) Received: by reform (Postfix, from userid 1000) id B034B2E80E5F; Tue, 29 Jun 2021 11:10:24 +0200 (CEST) Date: Tue, 29 Jun 2021 11:10:24 +0200 From: Mark Wielaard To: Marc Cc: gcc-rust@gcc.gnu.org Subject: Re: [PATCH] Suppress warning in rust-ast-lower-type.h ASTLowerGenericParam.visit. Message-ID: References: <20210628214147.256049-1-mark@klomp.org> <87pmw53apr.fsf@arrakis.kataplop.net> <87lf6t2nh8.fsf@arrakis.kataplop.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87lf6t2nh8.fsf@arrakis.kataplop.net> X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-rust@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: gcc-rust mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Jun 2021 09:10:28 -0000 Hi Marc, On Tue, Jun 29, 2021 at 08:28:51AM +0200, Marc wrote: > Mark Wielaard writes: > > I just tried to make LifetimeType an enum class and that doesn't help. > > So I was wrong. I don't know why the compiler doesn't see this? It > > should know since if not all switch cases were covered, -Wswitch > > (enabled by -Wall) gives us a warning... So, I don't fully understand > > why gcc needs the default gcc_unreachable case. It is what is used in > > the rest of the code though. > > I thought maybe that's a C++ vs C diff, or something caused by the > Lifetime being returned by a function call, but I can't reproduce it, so > that must be something else: > > https://godbolt.org/z/sjbcWEqdj Try using the result of the function and using -O2 enum LifetimeType { NAMED, // corresponds to LIFETIME_OR_LABEL STATIC, // corresponds to 'static WILDCARD // corresponds to '_ }; int g(int i); LifetimeType toto(); int t () { int t; switch(toto()){ case NAMED: t=4; break; case STATIC: t=5; break; case WILDCARD: t=8; break; } return g(t); } gcc -O2 -Wall : In function 'int t()': :24:15: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized] 24 | return g(t); | ~^~~ > Anyway, Philipp wants to have these enum shared between AST and HIR, so > this kind of 'if(AST::Foo) t=HIR::Foo' can be removed. That might be a good idea if the LifetimeType has the same values and semantics between AST and HIR. But till that happend I think it is a good idea to suppress warnings like this. Cheers, Mark