GNOME Bugzilla – Bug 585292
static const's dynamically generated cannot be used as case labels
Last modified: 2009-06-26 06:27:49 UTC
Please describe the problem: If a static const variable is generated at initialization time via code, it can't be used as a case label as expected. It appears this is because the .c code is a macro, so the case label expands to a line of code. Steps to reproduce: static const int ONE = "1".to_int(); static const int TWO = "2".to_int(); void main() { int foo = 1; switch (foo) { case ONE: stdout.printf("one\n"); break; case TWO: stdout.printf("two\n"); break; default: stdout.printf("unknown\n"); break; } } Note that because of the macro technique, this *does* work in place of the switch block: if (foo == ONE) { stdout.printf("one\n"); } else if (foo == TWO) { stdout.printf("two\n"); } else { stdout.printf("unknown\n"); } Actual results: The above code produces the compiler error "case label does not reduce to an integer constant". Expected results: Does this happen every time? Other information:
The constant initializer in your example is invalid, only constant expressions are supported.
Thanks for the bug report. This particular bug has already been reported into our bug tracking system, but please feel free to report any further bugs you find. *** This bug has been marked as a duplicate of 575628 ***