]> git.eshelyaron.com Git - emacs.git/commitdiff
CC Mode: Handle C++20's if consteval
authorAlan Mackenzie <acm@muc.de>
Tue, 26 Mar 2024 20:59:43 +0000 (20:59 +0000)
committerEshel Yaron <me@eshelyaron.com>
Wed, 27 Mar 2024 20:38:47 +0000 (21:38 +0100)
* 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.

(cherry picked from commit ed85132740b39c147647be1831abb64a3f514d57)

lisp/progmodes/cc-engine.el
lisp/progmodes/cc-langs.el

index ea4ee3d7b7c89db5e0026e58dc96842ca8da9bef..8c505e9556a944bebe686bb6ed2b465335a842c6 100644 (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)
index ae2389c75c2d021925dd6143cc853804e3760660..06b919f26fd8e2ce38b92d29cf784fe62b46f90b 100644 (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")