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

uecker at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|INVALID                     |---
             Status|RESOLVED                    |REOPENED
   Last reconfirmed|                            |2026-11-01
     Ever confirmed|0                           |1

--- Comment #4 from uecker at gcc dot gnu.org ---
(In reply to Halalaluyafail3 from comment #3)
> (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.

I don't think so. The enumerator was never explicitly declared as "int" and at
the end of the declaration it ends up enum E.  As I see it, the rule about
using the previously declared type makes sense only when it is meant to
directly set it to the final type it ends up after the first declaration,
because it is an alternative to the usual processing rules that it substitutes.

Alternatively, it would make sense to redo the processing from scratch and only
verify at the end that we end up with the same type. But then this rule should
not exist.

> 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.

No, you are right, it should be the original enum E. I will reopen the bug.

Reply via email to