https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84436

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |WAITING

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Confirmed. Note that in GCC 8 we generate a better code:

g++ pr84436.C -O2 -c -S -o/dev/stdout

_Z3foo1E:
.LFB0:
        movl    %edi, %edi
        movl    CSWTCH.0(,%rdi,4), %eax
        ret
.LFE0:
        .size   _Z3foo1E, .-_Z3foo1E
        .section        .rodata
        .align 8
        .type   CSWTCH.0, @object
        .size   CSWTCH.0, 12
CSWTCH.0:
        .long   0
        .long   1
        .long   2

It's clear that it's optimization opportunity. My question is why you don't
simple do:

   enum class E
    {
        A = 0, B, C,
    };

    int foo(E e)
    {
      return (int)e;
    }

? Is it reduced from a bigger code base?

Reply via email to