summaryrefslogtreecommitdiff
path: root/lisp/progmodes/cc-engine.el
diff options
context:
space:
mode:
authorAlan Mackenzie <acm@muc.de>2022-10-17 20:33:26 +0000
committerAlan Mackenzie <acm@muc.de>2022-10-17 20:33:26 +0000
commitc2b79d9148f21c3717f1eaa2d37b837b0922b94c (patch)
tree501dc8809f43f63fc40f9337e345262c9d67dcb9 /lisp/progmodes/cc-engine.el
parent1e9341672d53fa9b297858dc47f7318974abc80e (diff)
downloademacs-c2b79d9148f21c3717f1eaa2d37b837b0922b94c.tar.gz
CC Mode: Don't fontify as types variables with the same names as struct tags
This fixes bug #58534. * lisp/progmodes/cc-engine.el (c-forward-type): Only regard "struct" keywords which create self contained types (e.g. C++'s "typename") as creating found types. * lisp/progmodes/cc-langs.el (c-self-contained-typename-kwds (c-self-contained-typename-key): New language consts and variable.
Diffstat (limited to 'lisp/progmodes/cc-engine.el')
-rw-r--r--lisp/progmodes/cc-engine.el13
1 files changed, 9 insertions, 4 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 223b1e917fe..596cccdf48e 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -9055,7 +9055,8 @@ multi-line strings (but not C++, for example)."
(c-forward-<>-arglist t)
(c-forward-syntactic-ws))
- (let ((start (point)) pos res name-res id-start id-end id-range)
+ (let ((start (point)) pos res name-res id-start id-end id-range
+ post-prefix-pos)
;; Skip leading type modifiers. If any are found we know it's a
;; prefix of a type.
@@ -9067,6 +9068,7 @@ multi-line strings (but not C++, for example)."
(c-forward-syntactic-ws)
(or (eq res 'no-id)
(setq res 'prefix))))
+ (setq post-prefix-pos (point))
(cond
((looking-at c-typeof-key) ; e.g. C++'s "decltype".
@@ -9099,9 +9101,12 @@ multi-line strings (but not C++, for example)."
(setq name-res (c-forward-name))
(setq res (not (null name-res)))
(when (eq name-res t)
- ;; In many languages the name can be used without the
- ;; prefix, so we add it to `c-found-types'.
- (c-add-type pos (point))
+ ;; With some keywords the name can be used without the prefix, so we
+ ;; add the name to `c-found-types' when this is the case.
+ (when (save-excursion
+ (goto-char post-prefix-pos)
+ (looking-at c-self-contained-typename-key))
+ (c-add-type pos (point)))
(when (and c-record-type-identifiers
c-last-identifier-range)
(c-record-type-id c-last-identifier-range)))