public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/116443] New: String values not accepted for case labels
@ 2024-08-21 12:41 rasmus.tempcache at gmail dot com
2024-08-21 14:06 ` [Bug c/116443] " redi at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: rasmus.tempcache at gmail dot com @ 2024-08-21 12:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116443
Bug ID: 116443
Summary: String values not accepted for case labels
Product: gcc
Version: 14.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: rasmus.tempcache at gmail dot com
Target Milestone: ---
String character values do not seem to be able to be evaluated in switch cases.
This gives the error "case label does not reduce to an integer constant".
Here's an example that works in clang but not in GCC:
static int function(int var)
{
switch (var)
{
case "str a"[0] + "str b"[2]:
return 0;
default:
return 1;
}
}
I'm currently using 14.1.0 and have been following for the changelogs for newer
releases but haven't noticed this mentioned in any of them.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/116443] String values not accepted for case labels
2024-08-21 12:41 [Bug c/116443] New: String values not accepted for case labels rasmus.tempcache at gmail dot com
@ 2024-08-21 14:06 ` redi at gcc dot gnu.org
2024-08-21 14:10 ` redi at gcc dot gnu.org
2024-08-21 14:13 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2024-08-21 14:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116443
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I don't think this is technically a bug. The C standard requires an integral
constant expression for a case label, and "str"[0] is not required to be an
integral constant expression. The C standard does allow implementations to be
flexible in what they consider to be integral constant expressions, so Clang is
allowed to accept this code, but it's not required to accept it.
So if GCC accepted this, it would be as a non-standard extension.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/116443] String values not accepted for case labels
2024-08-21 12:41 [Bug c/116443] New: String values not accepted for case labels rasmus.tempcache at gmail dot com
2024-08-21 14:06 ` [Bug c/116443] " redi at gcc dot gnu.org
@ 2024-08-21 14:10 ` redi at gcc dot gnu.org
2024-08-21 14:13 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2024-08-21 14:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116443
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Slight correction, the correct term is "integer constant expression", and C
requires a "constant expression" for a case label, not an integer constant
expression.
But the rest still stands, GCC is not required to accept this, but Clang is
allowed to accept it, see C17 6.6 "An implementation may accept other forms of
constant expressions."
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/116443] String values not accepted for case labels
2024-08-21 12:41 [Bug c/116443] New: String values not accepted for case labels rasmus.tempcache at gmail dot com
2024-08-21 14:06 ` [Bug c/116443] " redi at gcc dot gnu.org
2024-08-21 14:10 ` redi at gcc dot gnu.org
@ 2024-08-21 14:13 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-08-21 14:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116443
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |DUPLICATE
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup.
*** This bug has been marked as a duplicate of bug 89408 ***
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-08-21 14:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-21 12:41 [Bug c/116443] New: String values not accepted for case labels rasmus.tempcache at gmail dot com
2024-08-21 14:06 ` [Bug c/116443] " redi at gcc dot gnu.org
2024-08-21 14:10 ` redi at gcc dot gnu.org
2024-08-21 14:13 ` pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).