bug#58537: CC Mode 5.35.1 (C/*l); Keywords being fontified as types at random

Po Lu via CC-Mode-help <[email protected]> Mon, 17 Oct 2022 14:24:59 +0800
Newsgroups gmane.emacs.cc-mode.general
Message-ID <[email protected]>
Alan Mackenzie <[email protected]> writes:

> diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
> index 2003b09ded..fc4e46633b 100644
> --- a/lisp/progmodes/cc-mode.el
> +++ b/lisp/progmodes/cc-mode.el
> @@ -2080,13 +2080,14 @@ c-after-change-fix-comment-escapes
>  (defun c-update-new-id (end)
>    ;; Note the bounds of any identifier that END is in or just after, in
>    ;; `c-new-id-start' and `c-new-id-end'.  Otherwise set these variables to
> -  ;; nil.
> +  ;; nil.  Set `c-new-id-is-type' unconditionally to nil.
>    (save-excursion
>      (goto-char end)
>      (let ((id-beg (c-on-identifier)))
>        (setq c-new-id-start id-beg
>  	    c-new-id-end (and id-beg
> -			      (progn (c-end-of-current-token) (point)))))))
> +			      (progn (c-end-of-current-token) (point)))
> +	    c-new-id-is-type nil))))
>  
>  (defun c-post-command ()
>    ;; If point was inside of a new identifier and no longer is, record that

BTW, there is still another case that isn't fixed: place the following
text in a C mode buffer:

{
  Data *tem;

  for (tem = surface->items; tem; tem = tem->next)
    {
      if (tem->type == tem)
	return tem;
    }

  /* Next, allocate some new client data.  */

  test->a = b;
}

and move point to the line above "test->a = b", and type

  TAB t e m SPC = SPC foo ;

"tem" will become fontified as a type, and will also be stuck that way.

Thanks.