@@ -1682,6 +1682,7 @@ static int hier2(value *lval)
1682
1682
swdefault = FALSE;
1683
1683
firstcase = TRUE;
1684
1684
do {
1685
+ int got_cseval = FALSE; /* true if the case value gets misinterpreted by lex() as a label */
1685
1686
needtoken (tTERM );
1686
1687
ident = lex (& val ,& st );
1687
1688
if (ident == ')' )
@@ -1695,15 +1696,29 @@ static int hier2(value *lval)
1695
1696
error (16 ); /* multiple defaults in switch */
1696
1697
swdefault = TRUE;
1697
1698
} else {
1698
- if (ident != tLABEL )
1699
+ if (ident != tLABEL ) {
1699
1700
lexpush ();
1700
- else
1701
- error (220 ); /* expression with tag override must appear between parentheses */
1701
+ } else {
1702
+ symbol * csesym = findloc (st );
1703
+ if (csesym == NULL )
1704
+ csesym = findglb (st ,sGLOBAL );
1705
+ if (csesym != NULL ) {
1706
+ markusage (csesym ,uREAD );
1707
+ ident = csesym -> ident ;
1708
+ val = csesym -> addr ;
1709
+ csetag = csesym -> tag ;
1710
+ got_cseval = TRUE;
1711
+ } else {
1712
+ error (220 ); /* expression with tag override must appear between parentheses */
1713
+ } /* if */
1714
+ } /* if */
1702
1715
if (swdefault != FALSE)
1703
1716
error (15 ); /* "default" case must be last in switch statement */
1704
1717
do {
1705
- stgget (& index ,& cidx ); /* mark position in code generator */
1706
- ident = expression (& val ,& csetag ,NULL ,TRUE);
1718
+ if (!got_cseval ) {
1719
+ stgget (& index ,& cidx ); /* mark position in code generator */
1720
+ ident = expression (& val ,& csetag ,NULL ,TRUE);
1721
+ } /* if */
1707
1722
/* if the next token is ";" or ")", then this must be an implicit default case */
1708
1723
if (matchtoken (';' ) || matchtoken (')' )) {
1709
1724
lexpush ();
@@ -1715,7 +1730,8 @@ static int hier2(value *lval)
1715
1730
goto skip_impl_default ;
1716
1731
} /* if */
1717
1732
casecount ++ ;
1718
- stgdel (index ,cidx ); /* scratch generated code */
1733
+ if (!got_cseval )
1734
+ stgdel (index ,cidx ); /* scratch generated code */
1719
1735
if (ident != iCONSTEXPR )
1720
1736
error (8 ); /* must be constant expression */
1721
1737
check_tagmismatch (swtag ,csetag ,TRUE,-1 );
@@ -1740,7 +1756,7 @@ static int hier2(value *lval)
1740
1756
newval = insert_constval (csp ,cse ,itoh (lbl_case ),val ,0 );
1741
1757
if (csp == NULL )
1742
1758
caselist .first = newval ;
1743
- if (matchtoken (tDBLDOT )) {
1759
+ if (! got_cseval && matchtoken (tDBLDOT )) {
1744
1760
cell end ;
1745
1761
stgget (& index ,& cidx ); /* mark position in code generator */
1746
1762
ident = expression (& end ,& csetag ,NULL ,TRUE);
@@ -1761,7 +1777,8 @@ static int hier2(value *lval)
1761
1777
} /* while */
1762
1778
} /* if */
1763
1779
} while (matchtoken (',' ));
1764
- needtoken (':' ); /* ':' ends the case */
1780
+ if (!got_cseval )
1781
+ needtoken (':' ); /* ':' ends the case */
1765
1782
} /* if */
1766
1783
sc_allowtags = bck_allowtags ; /* reset */
1767
1784
ident = expression (NULL ,& exprtag ,NULL ,FALSE);
0 commit comments