bug#59051: CC Mode 5.35.1 (C/*l); "Window scroll_bar" fontified as type

Alan Mackenzie <[email protected]> Fri, 18 Nov 2022 21:09:29 +0000
Newsgroups gmane.emacs.cc-mode.general
Message-ID <Y3f0ifKa+xFQmegl@ACM>
Hello, Po.

It's been some while since you submitted this bug report, but I now have
a patch for it.

On Sat, Nov 05, 2022 at 20:34:46 +0800, Po Lu via CC-Mode-help wrote:
> Package: cc-mode

> Go to src/xterm.c in the Emacs source code.  Then, type M-> and keep
> pressing M-v until the beginning of the buffer is reached.  Afterwards,
> go to line 14458, around which will be the following function
> definition:

> MAYBE_UNUSED static void
> xi_select_scroll_bar_events (struct x_display_info *dpyinfo,
> 			     Window scroll_bar)
> {
>   XIEventMask mask;
>   unsigned char *m;
>   ptrdiff_t length;

>   length = XIMaskLen (XI_LASTEVENT);
>   mask.mask = m = alloca (length);
>   memset (m, 0, length);
>   mask.mask_len = length;

> "scroll_bar" in "Window scroll_bar" will be fontified as a type!

What happens here is there's a macro invocation with the type "struct
scroll_bar" as one of the arguments.  This is in function
x_scroll_bar_create, and the code there looks like:

  struct scroll_bar *bar = ALLOCATE_PSEUDOVECTOR (struct scroll_bar, prev,
                                                  PVEC_OTHER);

..  This argument was enough to derail the fontification of scroll_bar
throughout the buffer.

Would you please do the usual with the attached patch, and let me know
whether there are still problems with this bug.  Thanks!

> Emacs  : GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu)
>  of 2022-10-29
> Package: CC Mode 5.35.1 (C/*l)
> Buffer Style: GNU
> c-emacs-features: (pps-extended-state col-0-paren posix-char-classes gen-string-delim gen-comment-delim syntax-properties category-properties 1-bit)

[ .... ]

-- 
Alan Mackenzie (Nuremberg, Germany).
diff.20221118.diff (text/plain, 413 B)
diff -r d37a87d7240d cc-engine.el
--- a/cc-engine.el	Thu Nov 17 10:20:00 2022 +0000
+++ b/cc-engine.el	Fri Nov 18 21:00:25 2022 +0000
@@ -10697,6 +10697,8 @@
 	(c-forward-syntactic-ws))
 
       (when (and (not got-identifier)
+		 (or backup-at-type
+		     (not (memq context '(arglist decl))))
 		 (or (and new-style-auto
 			  (looking-at c-auto-ops-re))
 		     (and (or maybe-typeless backup-maybe-typeless)