]> git.eshelyaron.com Git - emacs.git/commitdiff
Handle C99 Compound Literals in return statements and argument lists.
authorAlan Mackenzie <acm@muc.de>
Sun, 21 Jan 2018 18:29:26 +0000 (18:29 +0000)
committerAlan Mackenzie <acm@muc.de>
Sun, 21 Jan 2018 18:29:26 +0000 (18:29 +0000)
* 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
lisp/progmodes/cc-langs.el

index b5f085b4b3bf343de866c5c055b42d423ca90ffa..b78e85a6708e5d49922f440d78aecd601757b729 100644 (file)
@@ -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
index 271cc2f8464f3807590b7469932c4365978d6968..c06dd2164db4204fd4920d00b7f407f40f28a2ca 100644 (file)
@@ -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