]> git.eshelyaron.com Git - emacs.git/commitdiff
CC Mode: Fontify correctly a brace list element followed only by syntactic WS
authorAlan Mackenzie <acm@muc.de>
Fri, 26 Aug 2022 15:51:21 +0000 (15:51 +0000)
committerAlan Mackenzie <acm@muc.de>
Fri, 26 Aug 2022 15:51:21 +0000 (15:51 +0000)
This fixes a regression introduced in the fix for bug #56841 on 2022-08-24.

* lisp/progmodes/cc-engine (c-forward-declarator): Allow point to be at EOB
after the call to c-forward-name, rather than rejecting it as an invalid
declarator.  Also reindent a section of this function.

lisp/progmodes/cc-engine.el

index 1139423a45512ba1836d86d5ba4573af5ffec9ae..b2d1f15d39835cace3aedad03021e41a0de8ad79 100644 (file)
@@ -9459,7 +9459,8 @@ point unchanged and return nil."
 
 (defun c-forward-declarator (&optional limit accept-anon)
   ;; Assuming point is at the start of a declarator, move forward over it,
-  ;; leaving point at the next token after it (e.g. a ) or a ; or a ,).
+  ;; leaving point at the next token after it (e.g. a ) or a ; or a ,), or at
+  ;; end of buffer if there is no such token.
   ;;
   ;; Return a list (ID-START ID-END BRACKETS-AFTER-ID GOT-INIT DECORATED),
   ;; where ID-START and ID-END are the bounds of the declarator's identifier,
@@ -9499,44 +9500,44 @@ point unchanged and return nil."
           ;; of the while.  These are, e.g. "*" in "int *foo" or "(" and
           ;; "*" in "int (*foo) (void)" (Note similar code in
           ;; `c-forward-decl-or-cast-1'.)
-             (while
-                 (cond
-                  ((looking-at c-decl-hangon-key)
-                   (c-forward-keyword-clause 1))
-                  ((and c-opt-cpp-prefix
-                        (looking-at c-noise-macro-with-parens-name-re))
-                   (c-forward-noise-clause))
-                  ((and (looking-at c-type-decl-prefix-key)
-                        (if (and (c-major-mode-is 'c++-mode)
-                                 (match-beginning 4)) ; Was 3 - 2021-01-01
-                            ;; If the third submatch matches in C++ then
-                            ;; we're looking at an identifier that's a
-                            ;; prefix only if it specifies a member pointer.
-                            (progn
-                              (setq id-start (point))
-                              (c-forward-name)
-                              (if (save-match-data
-                                    (looking-at "\\(::\\)"))
-                                  ;; We only check for a trailing "::" and
-                                  ;; let the "*" that should follow be
-                                  ;; matched in the next round.
-                                  t
-                                ;; It turned out to be the real identifier,
-                                ;; so flag that and stop.
-                                (setq got-identifier t)
-                                nil))
-                          t))
-                   (if (save-match-data
-                         (looking-at c-type-decl-operator-prefix-key))
-                       (setq decorated t))
-                   (if (eq (char-after) ?\()
-                       (progn
-                         (setq paren-depth (1+ paren-depth))
-                         (forward-char))
-                     (goto-char (or (match-end 1)
-                                    (match-end 2))))
-                   (c-forward-syntactic-ws)
-                   t)))
+          (while
+              (cond
+               ((looking-at c-decl-hangon-key)
+                (c-forward-keyword-clause 1))
+               ((and c-opt-cpp-prefix
+                     (looking-at c-noise-macro-with-parens-name-re))
+                (c-forward-noise-clause))
+               ((and (looking-at c-type-decl-prefix-key)
+                     (if (and (c-major-mode-is 'c++-mode)
+                              (match-beginning 4)) ; Was 3 - 2021-01-01
+                         ;; If the third submatch matches in C++ then
+                         ;; we're looking at an identifier that's a
+                         ;; prefix only if it specifies a member pointer.
+                         (progn
+                           (setq id-start (point))
+                           (c-forward-name)
+                           (if (save-match-data
+                                 (looking-at "\\(::\\)"))
+                               ;; We only check for a trailing "::" and
+                               ;; let the "*" that should follow be
+                               ;; matched in the next round.
+                               t
+                             ;; It turned out to be the real identifier,
+                             ;; so flag that and stop.
+                             (setq got-identifier t)
+                             nil))
+                       t))
+                (if (save-match-data
+                      (looking-at c-type-decl-operator-prefix-key))
+                    (setq decorated t))
+                (if (eq (char-after) ?\()
+                    (progn
+                      (setq paren-depth (1+ paren-depth))
+                      (forward-char))
+                  (goto-char (or (match-end 1)
+                                 (match-end 2))))
+                (c-forward-syntactic-ws)
+                t)))
 
           ;; If we haven't passed the identifier already, do it now.
           (unless got-identifier
@@ -9557,7 +9558,8 @@ point unchanged and return nil."
         (or (= paren-depth 0)
             (c-safe (goto-char (scan-lists (point) 1 paren-depth))))
 
-        (< (point) limit)
+        (or (eq (point) (point-max))   ; No token after identifier.
+            (< (point) limit))
 
         ;; Skip over any trailing bit, such as "__attribute__".
         (progn