[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
-Wcase-enum improvements
From: |
Gaius Mulley |
Subject: |
-Wcase-enum improvements |
Date: |
Thu, 14 Sep 2023 21:49:43 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) |
Hello,
the singular/plural fix has been applied to -Wcase-enum and also it has
been extended to include subrange types. (Maybe the option should be
separated to: -Wcase-enum -Wcase-subrange (and -Wcase enabling both)?).
It could also check for any ordinal type (-Wcase-ordinal maybe), but I
was wondering if the ordinal case warnings might be too aggressive and
cause too much clutter?
regards,
Gaius
Here are the testcode and warning diagnostics in action:
MODULE calendar ;
TYPE
DayRange = [1..30] ;
PROCEDURE sept1752 (day: DayRange) : BOOLEAN ;
BEGIN
CASE day OF
1..2,
14..30: RETURN TRUE
END ;
RETURN FALSE
END sept1752 ;
BEGIN
IF sept1752 (4)
THEN
END
END calendar.
$ gm2 -Wcase-enum calendar.mod
calendar.mod:10:4: warning: In procedure 'sept1752': not all subrange
values in the CASE statements are specified, hint you either need to
specify each value of 'DayRange' or use an ELSE clause
10 | CASE day OF
| ^~~~
calendar.mod:10:4: warning: there are a total of 11 missing values in
the subrange, the CASE statement needs labels (or an ELSE statement) for
the following values: 3..13
MODULE missingclause ; (*!m2iso+gm2*)
TYPE
colour = (red, green, blue) ;
PROCEDURE init (c: colour) ;
BEGIN
CASE c OF
red,
blue: (* User forget green. *)
END
END init ;
VAR
rgb: colour ;
BEGIN
init (rgb)
END missingclause.
$ gm2 -Wcase-enum missingclause.mod
missingclause.mod:10:4: warning: In procedure 'init': not all
enumeration type values in the CASE statements are specified, hint
you either need to specify each value of 'colour' or use an ELSE
clause
10 | CASE c OF
| ^~~~
missingclause.mod:10:4: warning: the missing enumeration field is: green
MODULE subrangecase2 ; (*!m2iso+gm2*)
TYPE
DateRange = [1710..1720] ;
PROCEDURE init (d: DateRange) ;
BEGIN
CASE d OF
1711..1720: |
END
END init ;
VAR
year: DateRange ;
BEGIN
init (year)
END subrangecase2.
$ gm2 -Wcase-enum subrangecase2.mod
subrangecase2.mod:10:4: warning: In procedure 'init': not all subrange
values in the CASE statements are specified, hint you either need to
specify each value of 'DateRange' or use an ELSE clause
10 | CASE d OF
| ^~~~
subrangecase2.mod:10:4: warning: there is a total of 1 missing values in
the subrange, the CASE statement needs labels (or an ELSE statement) for
the following values: 1710
MODULE subrangecase3 ; (*!m2iso+gm2*)
TYPE
DateRange = [1710..1720] ;
PROCEDURE init (d: DateRange) ;
BEGIN
CASE d OF
1710: |
1712..1719: |
END
END init ;
VAR
year: DateRange ;
BEGIN
init (year)
END subrangecase3.
$ gm2 -Wcase-enum subrangecase3.mod
subrangecase3.mod:10:4: warning: In procedure 'init': not all subrange
values in the CASE statements are specified, hint you either need to
specify each value of 'DateRange' or use an ELSE clause
10 | CASE d OF
| ^~~~
subrangecase3.mod:10:4: warning: there are a total of 2 missing values
in the subrange, the CASE statement needs labels (or an ELSE statement)
for the following values: 1711 and 1720
MODULE subrangecase4 ; (*!m2iso+gm2*)
TYPE
DateRange = [1710..1720] ;
PROCEDURE init (d: DateRange) ;
BEGIN
CASE d OF
1710: |
1713..1718: |
END
END init ;
VAR
year: DateRange ;
BEGIN
init (year)
END subrangecase4.
$ gm2 -Wcase-enum subrangecase4.mod
subrangecase4.mod:10:4: warning: In procedure 'init': not all subrange
values in the CASE statements are specified, hint you either need to
specify each value of 'DateRange' or use an ELSE clause
10 | CASE d OF
| ^~~~
subrangecase4.mod:10:4: warning: there are a total of 4 missing values
in the subrange, the CASE statement needs labels (or an ELSE statement)
for the following values: 1711..1712 and 1719..1720
MODULE subrangecase5 ; (*!m2iso+gm2*)
TYPE
alphabet = ['a'..'z'] ;
PROCEDURE init (a: alphabet) ;
BEGIN
CASE a OF
'a',
'e'..'x':
END
END init ;
VAR
a: alphabet ;
BEGIN
init (a)
END subrangecase5.
$ gm2 -Wcase-enum subrangecase5.mod
subrangecase5.mod:10:4: warning: In procedure 'init': not all subrange
values in the CASE statements are specified, hint you either need to
specify each value of 'alphabet' or use an ELSE clause
10 | CASE a OF
| ^~~~
subrangecase5.mod:10:4: warning: there are a total of 5 missing values
in the subrange, the CASE statement needs labels (or an ELSE statement)
for the following values: 'b'..'d' and 'y'..'z'
MODULE subrangecase6 ; (*!m2iso+gm2*)
TYPE
alphabet = [MIN (CHAR)..MAX (CHAR)] ;
PROCEDURE init (a: alphabet) ;
BEGIN
CASE a OF
'a',
'e'..'x':
END
END init ;
VAR
a: alphabet ;
BEGIN
init (a)
END subrangecase6.
$ gm2 -Wcase-enum subrangecase6.mod
subrangecase6.mod:10:4: warning: In procedure 'init': not all subrange
values in the CASE statements are specified, hint you either need to
specify each value of 'alphabet' or use an ELSE clause
10 | CASE a OF
| ^~~~
subrangecase6.mod:10:4: warning: there are a total of 235 missing values
in the subrange, the CASE statement needs labels (or an ELSE statement)
for the following values: CHR (0)..'`', 'b'..'d' and 'y'..CHR (255)
MODULE subrangecase ; (*!m2iso+gm2*)
TYPE
DateRange = [1710..1720] ;
PROCEDURE init (d: DateRange) ;
BEGIN
CASE d OF
(* 1710: | *)
1711..1719: |
1720: |
END
END init ;
VAR
year: DateRange ;
BEGIN
init (year)
END subrangecase.
$ gm2 -Wcase-enum subrangecase.mod
subrangecase.mod:10:4: warning: In procedure 'init': not all subrange
values in the CASE statements are specified, hint you either need to
specify each value of 'DateRange' or use an ELSE clause
10 | CASE d OF
| ^~~~
subrangecase.mod:10:4: warning: there is a total of 1 missing values in
the subrange, the CASE statement needs labels (or an ELSE statement) for
the following values: 1710
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- -Wcase-enum improvements,
Gaius Mulley <=