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

--- Comment #3 from Halalaluyafail3 <luigighiron at gmail dot com> ---
(In reply to uecker from comment #2)
> Actually, I think this is invalid code. The type is the previously declared
> type is "unsigned int". Only during the construction of the previous
> declaration that type is temporarily "int", but this is not the case in the
> redeclaration.
> 
> enum E { A = 1, B = _Generic(A, int: -1U) };
> static_assert(_Generic(A, unsigned int: true));
> 
> enum E { A = 1, B = _Generic(A, unsigned int: -1U) };
> 
> https://godbolt.org/z/vGe8nY5zn
> 
> So I would say this is correct as implemented.
How else do you interpret "the previously declared type" then? The type of A
during the processing of each enumeration constant was int, so it should be int
again as far as I understand. Also, it should be noted that the type of A is
actually enum E is that static assertion. For example:

enum E{A=1,B=_Generic(A,int:-1U,default:1U)};
enum Q:unsigned{C=1};
enum E{A=1,B=_Generic(A,enum Q:-1U,default:1U)};
#include<stdio.h>
int main(){
    printf("%u\n",B);
    printf("%u\n",_Generic(A,enum Q:-1U,default:1U));
}

This prints 4294967295 then 1 with GCC currently assuming int is 32 bits. So
GCC clearly is not using the same type as outside of the redeclaration. If you
think "the previously declared type" refers to the underlying type of the
enumerated type, then I will make an issue for that since I do not think that
is the intent.

Reply via email to