commit 9e29fc687fadb6d0ef18e986825c1b788ddd7284
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Sat Nov 28 16:12:53 2015 +0100
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Sat Nov 28 16:20:29 2015 +0100

    Avoid multiple message errors in Case()
    
    It is anonnying to get a full page of the same error,
    so it is a good idea to mark the error like already
    printed. There is no problems with the value of nr,
    since this field is only used to generate this error.

diff --git a/cc1/stmt.c b/cc1/stmt.c
index 244aabd..65a0a15 100644
--- a/cc1/stmt.c
+++ b/cc1/stmt.c
@@ -242,15 +242,17 @@ Case(Symbol *lbreak, Symbol *lcont, Caselist *lswitch)
        if ((np = iconstexpr()) == NULL)
                errorp("case label does not reduce to an integer constant");
        expect(':');
-       if (lswitch) {
-               pcase = xmalloc(sizeof(*pcase));
-               pcase->expr = np;
-               pcase->next = lswitch->head;
-               emit(OLABEL, pcase->label = newlabel());
-               lswitch->head = pcase;
-               if (++lswitch->nr == NR_SWITCH)
+       if (lswitch && lswitch->nr >= 0) {
+               if (++lswitch->nr == NR_SWITCH) {
                        errorp("too case labels for a switch statement");
-               /* TODO: Avoid repetion of this error for the same switch */
+                       lswitch->nr = -1;
+               } else {
+                       pcase = xmalloc(sizeof(*pcase));
+                       pcase->expr = np;
+                       pcase->next = lswitch->head;
+                       emit(OLABEL, pcase->label = newlabel());
+                       lswitch->head = pcase;
+               }
        }
        stmt(lbreak, lcont, lswitch);
 }

Reply via email to