Euphoria Ticket #744: case statements with multiple values

Case statements with multiple values should be resolved such that multiple cases with the same value do not appear in the C source file. I consider this a bug because perfectly valid EUPHORIA can produce invalid C code.

Consider:

			case C_SIZE_T, C_POINTER, C_FLOAT then 
				case C_DOUBLE, C_DWORDLONG, C_LONGLONG then 
				return 8 

Now, some of the values are redundant for they happen to be the same value. Yet it runs fine. We end up with the following in C:

        case 50331656: 
        case 50331650: 
        case 50331650: 
 
        /** dll.e:546					return 8*/ 
        return 8;    

This is an error in C.

Details

Type: Bug Report Severity: Normal Category: Front End
Assigned To: mattlewis Status: Fixed Reported Release: 4.1.0
Fixed in SVN #: View VCS: none Milestone: 4.1.0

1. Comment by mattlewis Jan 27, 2012

I guess it's also a question of whether we should allow this sort of thing at all. I guess that we're currently only looking for duplicate symbols, not at the values.

When they're in the same case block, there is no problem, though maybe not desirable from a purist perspective. When they're in different cases, however, this is definitely a bug.

We also would need to test for this at runtime for those switch statements where we have cases that cannot be resolved at parse time.

2. Comment by mattlewis May 21, 2012

See: hg:euphoria/rev/504025824dd6

changeset: 5562:504025824dd6 tag: tip user: Matt Lewis date: Mon May 21 18:17:27 2012 -0400 files: docs/refman_2.txt docs/release/4.1.0.txt source/backend.e source/be_execute.c source/be_execute.h source/be_machine.c source/be_machine.h source/be_runtime.c source/compile.e source/parser.e tests/t_c_switch_dup.d/control.err tests/t_c_switch_dup.e tests/t_c_switch_rt_dup.d/control.err tests/t_c_switch_rt_dup.e tests/t_switch.e description:

  • check for duplicate case values in a switch
  • ticket 744

3. Comment by SDPringle Jun 06, 2012

See: hg:euphoria/rev/e1d8f02cd376

changeset: 5580:e1d8f02cd376 branch: 4.0 tag: tip parent: 5560:cbdc7d2e4930 user: Shawn Pringle <shawn.pringle@gmail.com> date: Wed Jun 06 20:10:51 2012 -0300 files: docs/release/4.0.5.txt source/compile.e tests/t_dup_case.e description:

  • duplicate case values in a switch block no longer results in a failed compile after translation.
  • fixes ticket 744

Search



Quick Links

User menu

Not signed in.

Misc Menu