From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id EBD1C393BC37 for ; Mon, 31 Jan 2022 15:54:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EBD1C393BC37 Received: by mail-wr1-x42f.google.com with SMTP id c23so26297803wrb.5 for ; Mon, 31 Jan 2022 07:54:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=fgrn8Nvw4+UxZ8bGXVmLwoO8A87fiaNXw1oOqwzHzjs=; b=4jH70rCK5L/4sn/p3T6yjJMtQ25keSVIXbdHwkYrKjb+VgaJYhSbKtSu6h/FXYC3e7 bQpaEx3HBjzSZ5+jclK2J+pBiinVsOAnk3HaH8qHcCssPUITn7KT7bcFy5VU6DGRpZKc 8Cbdgx+kA/MBk5nqUvLQPe0OWiU6KWvHdXddfsQcLL39oo+CP5k/Pp9ZUoO39Rke/j1W mKUhAha8lrRYjKuI4pdcvQmquShOditHnhyXqAfgeN3Xrdxw8wUvclW6fkPwC3Bpuh3n XpEHeHLM8PYim2Od+XVwrFxs++LX6470CxmS4r0zR3vPi6ORwRuwcMym7HY4Xf9DBLZe Dxmg== X-Gm-Message-State: AOAM530CWcPPzKHuFrx3+laQ9utCYN0MoIylnKTij7t4xaS7U4h30jF0 ndoBLxh1lKGaWSwIbGODzIrDAM7jQJAsjCdbRFbPu//aI/4= X-Google-Smtp-Source: ABdhPJxMgwVcwc4ylk1otOkqpL+na08q5J2B0VtQ6K13kRrNju5wLEvEJlqQ1LhiQ5g85JlFGNoILU+xVW2zSK0Ugwc= X-Received: by 2002:adf:d1ed:: with SMTP id g13mr18331430wrd.477.1643644481500; Mon, 31 Jan 2022 07:54:41 -0800 (PST) MIME-Version: 1.0 From: Hirrolot Date: Mon, 31 Jan 2022 21:54:30 +0600 Message-ID: Subject: Prohibit use of break/continue in a statement To: gcc-help@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Jan 2022 15:54:47 -0000 I have a macro that expands to a for-loop. It is used as follows: MACRO(...) { // User code } The for-loop is used to open a new scope with a new variable; thus, `MACRO(...) { ... }` would be a proper C statement. The loop itself is executed only once. The problem is that if a user uses `break` or `continue` like this: while (i < 10) { MACRO(...) { break; // User code... } } Then that `break` will apply to the for-loop generated by `MACRO`, not to the outer while-loop. The same holds for `continue`. This is unexpected behaviour, and I would like to prohibit the use of the `break`/`continue` statements in a user statement placed after `MACRO`. Ideally, this should somehow trigger a compilation error/warning. It should be clarified that `MACRO` is not of a loop itself: it is not a for-each macro or something like this; using that for-loop is just an implementation detail. I would be also happy with getting rid of that for-loop but I have no idea how. If I just generate a variable like this: #define MACRO(...) int x; /* Some other stuff */ Then `MACRO(...) { ... }` will no longer be a single C statement. Moreover, two occurrences of `MACRO` calls in a single scope will result in a compilation error, which is also quite unfortunate. Is it possible to trigger a compilation warning/error for `break`/`continue` with GCC?