From: Alan Mackenzie <acm@muc.de>
To: Herman@acm.muc.de, Géza <geza.herman@gmail.com>
Cc: acm@muc.de, 69293@debbugs.gnu.org
Subject: bug#69293: 30.0.50; cc-mode doesn't support "if consteval"
Date: Fri, 22 Mar 2024 13:34:24 +0000 [thread overview]
Message-ID: <Zf2I4Pc7TdVIq5au@ACM> (raw)
In-Reply-To: <877ciyga48.fsf@gmail.com>
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).
next prev parent reply other threads:[~2024-03-22 13:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-20 20:21 bug#69293: 30.0.50; cc-mode doesn't support "if consteval" Herman, Géza
2024-02-22 13:18 ` Eli Zaretskii
2024-02-25 16:52 ` Alan Mackenzie
2024-03-22 13:34 ` Alan Mackenzie [this message]
2024-03-25 9:37 ` Herman, Géza
2024-03-26 21:12 ` Alan Mackenzie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zf2I4Pc7TdVIq5au@ACM \
--to=acm@muc.de \
--cc=69293@debbugs.gnu.org \
--cc=Herman@acm.muc.de \
--cc=geza.herman@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).