CC Mode: Handle C++20's if consteval

* lisp/progmodes/cc-engine.el (c-after-conditional): Handle the
new keyword in place of a paren sexp after `if'.

* lisp/progmodes/cc-langs.el (c-negation-op-re)
(c-paren-clause-kwds, c-paren-clause-key)
(c-block-stmt-with-kwds, c-block-stmt-with-key): New
lang-consts/vars.

* if-11.cc, if-11.res: New test files.
This commit is contained in:
Alan Mackenzie 2024-03-26 20:59:43 +00:00
parent 004f2493a5
commit ed85132740
2 changed files with 45 additions and 7 deletions

View file

@ -12346,13 +12346,21 @@ comment at the start of cc-engine.el for more info."
(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)

View file

@ -1599,6 +1599,12 @@ operators."
(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.
@ -3163,6 +3169,30 @@ Keywords here should also be in `c-block-stmt-1-kwds'."
(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")