From 3d9d9be3a1d0a9d4ea6f4fad86cfe4ebc8da329b Mon Sep 17 00:00:00 2001 From: Alan Mackenzie Date: Thu, 21 May 2026 14:58:23 +0000 Subject: [PATCH] CC Mode: Fontify a cast type preceding a brace initialization This fixes bug#81084. * lisp/progmodes/cc-engine.el (c-forward-decl-or-cast-1): In the test for a cast near the end of the function, add a test for a {...} block which isn't a statement block, allowing such blocks to be recognized as operands of casts. --- lisp/progmodes/cc-engine.el | 59 +++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index bc7d8372f11..5f150778129 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el @@ -11687,34 +11687,37 @@ This function might do hidden buffer changes." (forward-char) (c-forward-syntactic-ws) (setq cast-end (point)) - (and (looking-at c-primary-expr-regexp) - (progn - (setq pos (match-end 0)) - (or - ;; Check if the expression begins with a prefix keyword. - (match-beginning 2) - (if (match-beginning 1) - ;; Expression begins with an ambiguous operator. - (cond - ((match-beginning c-per-&*+--match) - (memq at-type '(t known found))) - ((match-beginning c-per-++---match) - t) - ((match-beginning c-per-\(-match) - (or - (memq at-type '(t known found)) - (not inside-macro))) - (t nil)) - ;; Unless it's a keyword, it's the beginning of a primary - ;; expression. - (not (looking-at c-keywords-regexp))))) - ;; If `c-primary-expr-regexp' matched a nonsymbol token, check - ;; that it matched a whole one so that we don't e.g. confuse - ;; the operator '-' with '->'. It's ok if it matches further, - ;; though, since it e.g. can match the float '.5' while the - ;; operator regexp only matches '.'. - (or (not (looking-at c-nonsymbol-token-regexp)) - (<= (match-end 0) pos)))) + (or + (and (looking-at c-primary-expr-regexp) + (progn + (setq pos (match-end 0)) + (or + ;; Check if the expression begins with a prefix keyword. + (match-beginning 2) + (if (match-beginning 1) + ;; Expression begins with an ambiguous operator. + (cond + ((match-beginning c-per-&*+--match) + (memq at-type '(t known found))) + ((match-beginning c-per-++---match) + t) + ((match-beginning c-per-\(-match) + (or + (memq at-type '(t known found)) + (not inside-macro))) + (t nil)) + ;; Unless it's a keyword, it's the beginning of a primary + ;; expression. + (not (looking-at c-keywords-regexp))))) + ;; If `c-primary-expr-regexp' matched a nonsymbol token, + ;; check that it matched a whole one so that we don't + ;; e.g. confuse the operator '-' with '->'. It's ok if it + ;; matches further, though, since it e.g. can match the float + ;; '.5' while the operator regexp only matches '.'. + (or (not (looking-at c-nonsymbol-token-regexp)) + (<= (match-end 0) pos))) + (and (eq (char-after) ?\{) + (not (eq (c-looking-at-statement-block-1) t))))) ;; There should either be a cast before it or something that isn't an ;; identifier or close paren.