From: Alan Mackenzie Date: Thu, 3 Oct 2019 12:50:08 +0000 (+0000) Subject: C++ Mode: Fontify correctly declarators with identifier preceded by & X-Git-Tag: emacs-27.0.90~1316 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=e7e55e5e4dad95c5e605553d4ad3daa1422d0ea3;p=emacs.git C++ Mode: Fontify correctly declarators with identifier preceded by & The problem was bar in the following being spuriously recognised as a function, and foo as a type, as though the & were a *: Foo foo (&bar);. * lisp/progmodes/cc-engine.el (c-forward-decl-or-cast-1): New variable got-function-name-prefix, which is set when an operator like * (but not &) precedes the putative identifer in parentheses. Test this variable when deciding whether or not to "move the type backwards" to the previous identifier. * lisp/progmodes/cc-langs.el (c-type-decl-operator-prefix-key): New lang const and var. --- diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index 6d7d322def7..d1cca115f3a 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el @@ -9544,6 +9544,9 @@ This function might do hidden buffer changes." ;; True if there's a prefix match outside the outermost ;; paren pair that surrounds the declarator. got-prefix-before-parens + ;; True if there's a prefix, such as "*" which might precede the + ;; identifier in a function declaration. + got-function-name-prefix ;; True if there's a suffix match outside the outermost ;; paren pair that surrounds the declarator. The value is ;; the position of the first suffix match. @@ -9605,6 +9608,9 @@ This function might do hidden buffer changes." (unless got-prefix-before-parens (setq got-prefix-before-parens (= paren-depth 0))) (setq got-prefix t) + (when (save-match-data + (looking-at c-type-decl-operator-prefix-key)) + (setq got-function-name-prefix t)) (goto-char (match-end 1))) (c-forward-syntactic-ws))) @@ -9773,7 +9779,7 @@ This function might do hidden buffer changes." (throw 'at-decl-or-cast t)) (when (and got-parens - (not got-prefix) + (not got-function-name-prefix) ;; (not got-suffix-after-parens) (or backup-at-type maybe-typeless diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el index 6ba14a8229b..d092094817c 100644 --- a/lisp/progmodes/cc-langs.el +++ b/lisp/progmodes/cc-langs.el @@ -3423,7 +3423,7 @@ Identifier syntax is in effect when this is matched \(see 'dont-doc) (c-lang-defconst c-type-decl-operator-prefix-key - "Regexp matching any declarator operator which isn't a keyword + "Regexp matching any declarator operator which isn't a keyword, that might precede the identifier in a declaration, e.g. the \"*\" in \"char *argv\". The end of the first submatch is taken as the end of the operator. Identifier syntax is in effect when