This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/81845] const union's field doesn't interpret as const in switch/case
- From: "alenuke at yandex dot ru" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 16 Aug 2017 10:51:25 +0000
- Subject: [Bug c/81845] const union's field doesn't interpret as const in switch/case
- Auto-submitted: auto-generated
- References: <bug-81845-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81845
--- Comment #2 from Aleksandr Slobodeniuk <alenuke at yandex dot ru> ---
Sorry, I didn't really specify the standard (and mess c with c++).
C11 standard.
6.8.4.2 The switch statement.
> 3 The expression of each case label shall be an integer constant expression
> and no two of the case constant expressions in the same switch statement
> shall have the same value after conversion.
So, by C11 standard case label shall be a constant expression.
Fields of const-qualified structs and unions, that were initialized with const
literals ARE *constant expressions*, isn't it?
-----------------
Yes, the standard also says that uninitialized part of union is undefined, but
that's not that case if we have fields with the same size.
-----------------
Sorry for wasting your time.