From c965e5a641d9478d23a233b48977503506b1b603 Mon Sep 17 00:00:00 2001 From: Alan Mackenzie Date: Sun, 21 Jan 2018 18:29:26 +0000 Subject: [PATCH] Handle C99 Compound Literals in return statements and argument lists. * lisp/progmodes/cc-engine.el (c-looking-at-or-maybe-in-bracelist): Recognize a brace list when preceded by "return" or inside parentheses, either immediately after the "(" or following a comma. (c-looking-at-inexpr-block): Test c-has-compound-literals rather than hard coded C++ Mode. (c-guess-basic-syntax, CASE 7B): Test additionally for not being just inside a parenthesis or being at a Java "new" keyword. CASE 9: Remove the simple minded test on the contents of a block to determine a brace list. * lisp/progmodes/cc-langs.el (c-has-compound-literals): New lang const and lang var. --- lisp/progmodes/cc-engine.el | 29 +++++++++++++++++++++++++---- lisp/progmodes/cc-langs.el | 6 ++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index b5f085b4b3b..b78e85a6708 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el @@ -10525,6 +10525,17 @@ comment at the start of cc-engine.el for more info." ((and class-key (looking-at class-key)) (setq braceassignp nil)) + ((and c-has-compound-literals + (looking-at c-return-key)) + (setq braceassignp t) + nil) + ((and c-has-compound-literals + (eq (char-after) ?,)) + (save-excursion + (when (and (c-go-up-list-backward nil lim) + (eq (char-after) ?\()) + (setq braceassignp t) + nil))) ((eq (char-after) ?=) ;; We've seen a =, but must check earlier tokens so ;; that it isn't something that should be ignored. @@ -10563,9 +10574,14 @@ comment at the start of cc-engine.el for more info." )))) nil) (t t)))))) - (if (and (eq braceassignp 'dontknow) - (/= (c-backward-token-2 1 t lim) 0)) - (setq braceassignp nil))) + (when (and (eq braceassignp 'dontknow) + (/= (c-backward-token-2 1 t lim) 0)) + (if (save-excursion + (and c-has-compound-literals + (eq (c-backward-token-2 1 nil lim) 0) + (eq (char-after) ?\())) + (setq braceassignp t) + (setq braceassignp nil)))) (cond (braceassignp @@ -10930,7 +10946,7 @@ comment at the start of cc-engine.el for more info." (c-on-identifier))) (and c-special-brace-lists (c-looking-at-special-brace-list)) - (and (c-major-mode-is 'c++-mode) + (and c-has-compound-literals (save-excursion (goto-char block-follows) (not (c-looking-at-statement-block))))) @@ -12437,6 +12453,11 @@ comment at the start of cc-engine.el for more info." ;; in-expression block or brace list. C.f. cases 4, 16A ;; and 17E. ((and (eq char-after-ip ?{) + (or (not (eq (char-after containing-sexp) ?\()) + (save-excursion + (and c-opt-inexpr-brace-list-key + (eq (c-beginning-of-statement-1 lim t nil t) 'same) + (looking-at c-opt-inexpr-brace-list-key)))) (progn (setq placeholder (c-inside-bracelist-p (point) paren-state diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el index 271cc2f8464..c06dd2164db 100644 --- a/lisp/progmodes/cc-langs.el +++ b/lisp/progmodes/cc-langs.el @@ -617,6 +617,12 @@ EOL terminated statements." c++ t) (c-lang-defvar c-has-quoted-numbers (c-lang-const c-has-quoted-numbers)) +(c-lang-defconst c-has-compound-literals + "Whether literal initializers {...} are used other than in initializations." + t nil + (c c++) t) +(c-lang-defvar c-has-compound-literals (c-lang-const c-has-compound-literals)) + (c-lang-defconst c-modified-constant "Regexp that matches a “modified” constant literal such as \"L\\='a\\='\", a “long character”. In particular, this recognizes forms of constant -- 2.39.5