aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2019-10-03 12:50:08 +0000
committerAlan Mackenzie2019-10-03 12:50:08 +0000
commite7e55e5e4dad95c5e605553d4ad3daa1422d0ea3 (patch)
treef05c879291bb42b59d592302360200392667e22c
parent5b09393f2cde83f10c84926ba579782fb52e05b8 (diff)
downloademacs-e7e55e5e4dad95c5e605553d4ad3daa1422d0ea3.tar.gz
emacs-e7e55e5e4dad95c5e605553d4ad3daa1422d0ea3.zip
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.
-rw-r--r--lisp/progmodes/cc-engine.el8
-rw-r--r--lisp/progmodes/cc-langs.el2
2 files changed, 8 insertions, 2 deletions
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."
9544 ;; True if there's a prefix match outside the outermost 9544 ;; True if there's a prefix match outside the outermost
9545 ;; paren pair that surrounds the declarator. 9545 ;; paren pair that surrounds the declarator.
9546 got-prefix-before-parens 9546 got-prefix-before-parens
9547 ;; True if there's a prefix, such as "*" which might precede the
9548 ;; identifier in a function declaration.
9549 got-function-name-prefix
9547 ;; True if there's a suffix match outside the outermost 9550 ;; True if there's a suffix match outside the outermost
9548 ;; paren pair that surrounds the declarator. The value is 9551 ;; paren pair that surrounds the declarator. The value is
9549 ;; the position of the first suffix match. 9552 ;; the position of the first suffix match.
@@ -9605,6 +9608,9 @@ This function might do hidden buffer changes."
9605 (unless got-prefix-before-parens 9608 (unless got-prefix-before-parens
9606 (setq got-prefix-before-parens (= paren-depth 0))) 9609 (setq got-prefix-before-parens (= paren-depth 0)))
9607 (setq got-prefix t) 9610 (setq got-prefix t)
9611 (when (save-match-data
9612 (looking-at c-type-decl-operator-prefix-key))
9613 (setq got-function-name-prefix t))
9608 (goto-char (match-end 1))) 9614 (goto-char (match-end 1)))
9609 (c-forward-syntactic-ws))) 9615 (c-forward-syntactic-ws)))
9610 9616
@@ -9773,7 +9779,7 @@ This function might do hidden buffer changes."
9773 (throw 'at-decl-or-cast t)) 9779 (throw 'at-decl-or-cast t))
9774 9780
9775 (when (and got-parens 9781 (when (and got-parens
9776 (not got-prefix) 9782 (not got-function-name-prefix)
9777 ;; (not got-suffix-after-parens) 9783 ;; (not got-suffix-after-parens)
9778 (or backup-at-type 9784 (or backup-at-type
9779 maybe-typeless 9785 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
3423 'dont-doc) 3423 'dont-doc)
3424 3424
3425(c-lang-defconst c-type-decl-operator-prefix-key 3425(c-lang-defconst c-type-decl-operator-prefix-key
3426 "Regexp matching any declarator operator which isn't a keyword 3426 "Regexp matching any declarator operator which isn't a keyword,
3427that might precede the identifier in a declaration, e.g. the 3427that might precede the identifier in a declaration, e.g. the
3428\"*\" in \"char *argv\". The end of the first submatch is taken 3428\"*\" in \"char *argv\". The end of the first submatch is taken
3429as the end of the operator. Identifier syntax is in effect when 3429as the end of the operator. Identifier syntax is in effect when