Patch: Add some semantic analysis to switch statements

Hello,

here's a patch that makes sure that that the switch condition expression has an integer type, and also that a switch doesn't have more than one default: label.

Anders

textmate stdin 2NXjY6.txt (7.98 KB)

Anders,

Thanks for the patch...looks great.

One comment and one question...

#1: Where is setSwitchStmt() called?

#2: Getters should be declared "const".

snaroff

17 jul 2007 kl. 17.35 skrev Steve Naroff:

Anders,

Thanks for the patch...looks great.

One comment and one question...

#1: Where is setSwitchStmt() called?

That was just some cruft, I've removed it.

#2: Getters should be declared "const".

Whoops, missed that. Here's a new patch.

Anders

textmate stdin b32ZBw.txt (7.7 KB)

Excellent. Please commit.

snaroff

Anders Carlsson wrote:-

Hello,

here's a patch that makes sure that that the switch condition
expression has an integer type, and also that a switch doesn't have

But that's not what the standard requires; it requires a scalar
type. You can download a copy of the revised standard from the
openstd website.

Neil.

17 jul 2007 kl. 19.14 skrev Neil Booth:

Anders Carlsson wrote:-

Hello,

here's a patch that makes sure that that the switch condition
expression has an integer type, and also that a switch doesn't have

But that's not what the standard requires; it requires a scalar
type. You can download a copy of the revised standard from the
openstd website.

Neil.

I'm reading that spec. It says:

6.8.4.2 The switch statement
Constraints
1 The controlling expression of a switch statement shall have integer type.

Am I missing something?

Anders

Neil Booth wrote:-

Anders Carlsson wrote:-

> Hello,
>
> here's a patch that makes sure that that the switch condition
> expression has an integer type, and also that a switch doesn't have

But that's not what the standard requires; it requires a scalar
type. You can download a copy of the revised standard from the
openstd website.

Apologies, I'm completely wrong. :slight_smile:

Neil.