public inbox for gcc-rust@gcc.gnu.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: Marc <dkm@kataplop.net>
Cc: gcc-rust@gcc.gnu.org
Subject: Re: [PATCH] Suppress warning in rust-ast-lower-type.h ASTLowerGenericParam.visit.
Date: Tue, 29 Jun 2021 11:10:24 +0200	[thread overview]
Message-ID: <YNrjgGFuvvjfhYsv@wildebeest.org> (raw)
In-Reply-To: <87lf6t2nh8.fsf@arrakis.kataplop.net>

Hi Marc,

On Tue, Jun 29, 2021 at 08:28:51AM +0200, Marc wrote:
> Mark Wielaard <mark@klomp.org> 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

<source>: In function 'int t()':
<source>: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


      reply	other threads:[~2021-06-29  9:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-28 21:41 Mark Wielaard
2021-06-28 22:06 ` Marc
2021-06-28 22:47   ` Mark Wielaard
2021-06-28 23:41     ` Mark Wielaard
2021-06-29  6:28       ` Marc
2021-06-29  9:10         ` Mark Wielaard [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YNrjgGFuvvjfhYsv@wildebeest.org \
    --to=mark@klomp.org \
    --cc=dkm@kataplop.net \
    --cc=gcc-rust@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).