Subject: bug#59427: CC Mode 5.35.2 (C/*l); More bad fontification

From: Alan Mackenzie <[email-masked]>
Date: Thu, 24 Nov 2022 12:56:40 +0000

Hello, Po.

On Mon, Nov 21, 2022 at 10:32:26 +0800, Po Lu via CC-Mode-help wrote:
> Package: cc-mode

> Insert the following text in a c-mode buffer:

> static uint64_t
> ConfineTime (uint64_t time)
> {
>   uint32_t milliseconds;

>   /* Given a microsecond time, confine the millisecond part to
>      CARD32.  */
>   milliseconds = time / 1000;

>   return (milliseconds * (uint64_t) 1000
> 	  + time % 1000);
> }

> Notice how "milliseconds" is recognized as a type, and the uint64_t in
> the cast as an identifier.

Yes.  Here the "symmetric space" criterion for * was buggy.  That
criterion says if there is whitespace on neither side of the *, or both,
it is a multiplication sign.  Otherwise it is the indirection operator.

The bug was not taking the ( properly into account.  Please apply the
attached patch, which should fix this, and confirm it works OK.  Thanks!

> Emacs  : GNU Emacs 29.0.50 (build 236, x86_64-pc-linux-gnu)
>  of 2022-11-21
> Package: CC Mode 5.35.2 (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 -r d37a87d7240d cc-engine.el
--- a/cc-engine.el	Thu Nov 17 10:20:00 2022 +0000
+++ b/cc-engine.el	Wed Nov 23 12:48:03 2022 +0000
@@ -11096,8 +11096,9 @@
 			      at-decl-start))
 		 (let ((space-before-id
 			(save-excursion
-			  (goto-char name-start)
-			  (or (bolp) (memq (char-before) '(?\  ?\t)))))
+			  (goto-char id-start)
+			  (and (> (skip-chars-forward "* \t\n\r") 0)
+			       (memq (char-before) '(?\  ?\t ?\n ?\r)))))
 		       (space-after-type
 			(save-excursion
 			  (goto-char type-start)
@@ -11107,6 +11108,8 @@
 				   (memq (char-after) '(?\  ?\t)))))))
 		   (when (not (eq (not space-before-id)
 				  (not space-after-type)))
+		     (when (eq at-type 'maybe)
+		       (setq unsafe-maybe t))
 		     (setq maybe-expression t)
 		     (throw 'at-decl-or-cast t)))))