Hi Marc,

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

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust

Reply via email to