From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#69293: 30.0.50; cc-mode doesn't support "if consteval" Date: Fri, 22 Mar 2024 13:34:24 +0000 Message-ID: References: <877ciyga48.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6330"; mail-complaints-to="usenet@ciao.gmane.io" Cc: acm@muc.de, 69293@debbugs.gnu.org To: Herman@acm.muc.de, =?UTF-8?Q?G=C3=A9za?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Mar 22 14:35:37 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rnf3Z-0001Sp-Ne for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 22 Mar 2024 14:35:37 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rnf3O-0001N8-3E; Fri, 22 Mar 2024 09:35:26 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rnf3K-0001Mg-Mt for bug-gnu-emacs@gnu.org; Fri, 22 Mar 2024 09:35:22 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rnf3J-0004S9-M5 for bug-gnu-emacs@gnu.org; Fri, 22 Mar 2024 09:35:22 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rnf3x-00060U-Qo for bug-gnu-emacs@gnu.org; Fri, 22 Mar 2024 09:36:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 22 Mar 2024 13:36:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69293 X-GNU-PR-Package: emacs Original-Received: via spool by 69293-submit@debbugs.gnu.org id=B69293.171111451522931 (code B ref 69293); Fri, 22 Mar 2024 13:36:01 +0000 Original-Received: (at 69293) by debbugs.gnu.org; 22 Mar 2024 13:35:15 +0000 Original-Received: from localhost ([127.0.0.1]:52723 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rnf3C-0005xl-DZ for submit@debbugs.gnu.org; Fri, 22 Mar 2024 09:35:15 -0400 Original-Received: from mail.muc.de ([193.149.48.3]:20438) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rnf3A-0005xO-Ea for 69293@debbugs.gnu.org; Fri, 22 Mar 2024 09:35:13 -0400 Original-Received: (qmail 90765 invoked by uid 3782); 22 Mar 2024 14:34:25 +0100 Original-Received: from acm.muc.de (p4fe15d8f.dip0.t-ipconnect.de [79.225.93.143]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Fri, 22 Mar 2024 14:34:25 +0100 Original-Received: (qmail 9763 invoked by uid 1000); 22 Mar 2024 13:34:24 -0000 Content-Disposition: inline In-Reply-To: <877ciyga48.fsf@gmail.com> X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:281939 Archived-At: Hello, Géza. Sorry it's taken a long time to respond. I've been unwell. On Tue, Feb 20, 2024 at 21:21:27 +0100, Herman wrote: > C++ has a new feature, "if consteval". So one can write code like > if consteval { > // do something > } else { > // do something else > } Yes, indeed. Maybe I'm the only person to think so, but I think it's a horrible distortion of C syntax. Anyway ... > The problem is that cc-mode doesn't recognize this construct, lines > are not indented correctly: the "// do something" and the "} else {" > receive an additional level of indentation. Would you please try out the patch below on your Emacs, then byte compile CC Mode in its entirety (there are new macros) then load it into a running Emacs (or restart Emacs). cc-mode is in .../lisp/progmodes. Then please let me know how well it fixes the bug. Thanks! > In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, cairo version > 1.18.0) of 2023-11-29 built on okoska > Repository revision: 47837b3863deba274f16960f1ee9fde4acb9d5a1 > Repository branch: my-modifications > Windowing system distributor 'The X.Org Foundation', version 11.0.12101008 > System Description: Debian GNU/Linux trixie/sid [ .... ] diff -r 779141971296 cc-engine.el --- a/cc-engine.el Sun Dec 31 10:45:58 2023 +0000 +++ b/cc-engine.el Fri Mar 22 12:54:39 2024 +0000 @@ -12365,13 +12365,21 @@ (zerop (c-backward-token-2 1 t lim)) t) (or (looking-at c-block-stmt-1-key) - (and (eq (char-after) ?\() - (zerop (c-backward-token-2 1 t lim)) - (if (looking-at c-block-stmt-hangon-key) - (zerop (c-backward-token-2 1 t lim)) - t) - (or (looking-at c-block-stmt-2-key) - (looking-at c-block-stmt-1-2-key)))) + (or + (and + (eq (char-after) ?\() + (zerop (c-backward-token-2 1 t lim)) + (if (looking-at c-block-stmt-hangon-key) + (zerop (c-backward-token-2 1 t lim)) + t) + (or (looking-at c-block-stmt-2-key) + (looking-at c-block-stmt-1-2-key))) + (and (looking-at c-paren-clause-key) + (zerop (c-backward-token-2 1 t lim)) + (if (looking-at c-negation-op-re) + (zerop (c-backward-token-2 1 t lim)) + t) + (looking-at c-block-stmt-with-key)))) (point)))) (defun c-after-special-operator-id (&optional lim) diff -r 779141971296 cc-langs.el --- a/cc-langs.el Sun Dec 31 10:45:58 2023 +0000 +++ b/cc-langs.el Fri Mar 22 12:54:39 2024 +0000 @@ -1583,6 +1583,12 @@ (c-lang-defvar c-assignment-op-regexp (c-lang-const c-assignment-op-regexp)) +(c-lang-defconst c-negation-op-re + ;; Regexp matching the negation operator. + t "!\\([^=]\\|$\\)") + +(c-lang-defvar c-negation-op-re (c-lang-const c-negation-op-re)) + (c-lang-defconst c-arithmetic-operators "List of all arithmetic operators, including \"+=\", etc." ;; Note: in the following, there are too many operators for AWK and IDL. @@ -3149,6 +3155,30 @@ (c-lang-const c-block-stmt-2-kwds))))) (c-lang-defvar c-opt-block-stmt-key (c-lang-const c-opt-block-stmt-key)) +(c-lang-defconst c-paren-clause-kwds + "Keywords which can stand in the place of paren sexps in conditionals. +This applies only to conditionals in `c-block-stmt-with-kwds'." + t nil + c++ '("consteval")) + +(c-lang-defconst c-paren-clause-key + ;; Regexp matching a keyword in `c-paren-clause-kwds'. + t (c-make-keywords-re t + (c-lang-const c-paren-clause-kwds))) +(c-lang-defvar c-paren-clause-key (c-lang-const c-paren-clause-key)) + +(c-lang-defconst c-block-stmt-with-kwds + "Statement keywords which can be followed by a keyword instead of a parens. +Such a keyword is a member of `c-paren-clause-kwds." + t nil + c++ '("if")) + +(c-lang-defconst c-block-stmt-with-key + ;; Regexp matching a keyword in `c-block-stmt-with-kwds'. + t (c-make-keywords-re t + (c-lang-const c-block-stmt-with-kwds))) +(c-lang-defvar c-block-stmt-with-key (c-lang-const c-block-stmt-with-key)) + (c-lang-defconst c-simple-stmt-kwds "Statement keywords followed by an expression or nothing." t '("break" "continue" "goto" "return") -- Alan Mackenzie (Nuremberg, Germany).