summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Mackenzie <acm@muc.de>2017-11-21 18:06:11 +0000
committerAlan Mackenzie <acm@muc.de>2017-11-21 18:06:11 +0000
commit735c8b516e09ecd056563569fb132e5ca56810d7 (patch)
treea3365aea1cae4e504f6fde72a223d8942f9563b3
parent92f0c4cd56d4dc1a92c116172404e65996c5884d (diff)
downloademacs-735c8b516e.tar.gz
Make c-defun-name analyze more thoroughly a function type which is a struct
This fixes bug #29293. * lisp/progmodes/cc-cmds.el (c-defun-name): When a struct (etc.) type is encountered, check whether it is the return type of a function rather than a declaration of the struct itself. Similarly adapt the cond arm which deals with functions properly to recognize struct return types.
-rw-r--r--lisp/progmodes/cc-cmds.el22
1 files changed, 19 insertions, 3 deletions
diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el
index 2b663135932..471560e19d4 100644
--- a/lisp/progmodes/cc-cmds.el
+++ b/lisp/progmodes/cc-cmds.el
@@ -1849,7 +1849,15 @@ with a brace block."
;; Pick out the defun name, according to the type of defun.
(cond
;; struct, union, enum, or similar:
- ((looking-at c-type-prefix-key)
+ ((save-excursion
+ (and
+ (looking-at c-type-prefix-key)
+ (consp (c-forward-decl-or-cast-1 (c-point 'bosws) 'top nil))
+ (or (not (or (eq (char-after) ?{)
+ (and c-recognize-knr-p
+ (c-in-knr-argdecl))))
+ (progn (c-backward-syntactic-ws)
+ (not (eq (char-before) ?\)))))))
(let ((key-pos (point)))
(c-forward-over-token-and-ws) ; over "struct ".
(cond
@@ -1897,8 +1905,16 @@ with a brace block."
(t
;; Normal function or initializer.
- (when (c-syntactic-re-search-forward "[{(]" nil t)
- (backward-char)
+ (when
+ (and
+ (consp (c-forward-decl-or-cast-1 (c-point 'bosws) 'top nil))
+ (or (eq (char-after) ?{)
+ (and c-recognize-knr-p
+ (c-in-knr-argdecl)))
+ (progn
+ (c-backward-syntactic-ws)
+ (eq (char-before) ?\)))
+ (c-go-list-backward))
(c-backward-syntactic-ws)
(when (eq (char-before) ?\=) ; struct foo bar = {0, 0} ;
(c-backward-token-2)