diff options
| author | Alan Mackenzie | 2019-08-06 16:49:29 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2019-08-06 16:49:29 +0000 |
| commit | 7f0de07b3ac67370bfe78faac9c6bffdd90d55ce (patch) | |
| tree | 7f5b277a4ee7d7a106b912e1c49090790f0056e3 | |
| parent | 96e672364cbd6f1a865511d78f3a218c0570345e (diff) | |
| download | emacs-7f0de07b3ac67370bfe78faac9c6bffdd90d55ce.tar.gz emacs-7f0de07b3ac67370bfe78faac9c6bffdd90d55ce.zip | |
C++ Mode: Prevent End of statement being found after {} in "count << vec{} <<"
* lisp/progmodes/cc-engine.el (c-beginning-of-statement-1): Check for
operators which cannot start a statement, which may follow a closing brace.
Don't recognise an end of statement in such a case.
* lisp/progmodes/cc-langs.el (c-operator-re, c-bin-tern-operators)
(c-unary-operators, c-non-after-{}-operators, c-non-after-{}-ops-re): New lang
consts and vars.
| -rw-r--r-- | lisp/progmodes/cc-engine.el | 18 | ||||
| -rw-r--r-- | lisp/progmodes/cc-langs.el | 30 |
2 files changed, 47 insertions, 1 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index a095277989a..29ebe2eea1f 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el | |||
| @@ -1227,7 +1227,23 @@ comment at the start of cc-engine.el for more info." | |||
| 1227 | (not (looking-at | 1227 | (not (looking-at |
| 1228 | c-opt-block-decls-with-vars-key)) | 1228 | c-opt-block-decls-with-vars-key)) |
| 1229 | (or comma-delim | 1229 | (or comma-delim |
| 1230 | (not (eq (char-after) ?\,))))))) | 1230 | (not (eq (char-after) ?\,)))))) |
| 1231 | ;; Is the {..} followed by an operator which | ||
| 1232 | ;; prevents it being a statement in its own right? | ||
| 1233 | (save-excursion | ||
| 1234 | (and | ||
| 1235 | (c-go-list-forward) | ||
| 1236 | (progn | ||
| 1237 | (c-forward-syntactic-ws) | ||
| 1238 | (or | ||
| 1239 | (not (looking-at c-non-after-{}-ops-re)) | ||
| 1240 | (let | ||
| 1241 | ((bad-op-len | ||
| 1242 | (- (match-end 0) (match-beginning 0)))) | ||
| 1243 | (and | ||
| 1244 | (looking-at c-operator-re) | ||
| 1245 | (> (- (match-end 0) (match-beginning 0)) | ||
| 1246 | bad-op-len)))))))) | ||
| 1231 | (save-excursion | 1247 | (save-excursion |
| 1232 | (c-forward-sexp) (point))) | 1248 | (c-forward-sexp) (point))) |
| 1233 | ;; Just gone back over some paren block? | 1249 | ;; Just gone back over some paren block? |
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el index 9d36f8f9e49..6ba14a8229b 100644 --- a/lisp/progmodes/cc-langs.el +++ b/lisp/progmodes/cc-langs.el | |||
| @@ -1205,6 +1205,36 @@ since CC Mode treats every identifier as an expression." | |||
| 1205 | ;; The operators as a flat list (without duplicates). | 1205 | ;; The operators as a flat list (without duplicates). |
| 1206 | t (c-filter-ops (c-lang-const c-operators) t t)) | 1206 | t (c-filter-ops (c-lang-const c-operators) t t)) |
| 1207 | 1207 | ||
| 1208 | (c-lang-defconst c-operator-re | ||
| 1209 | ;; A regexp which matches any operator. | ||
| 1210 | t (regexp-opt (c-lang-const c-operator-list))) | ||
| 1211 | (c-lang-defvar c-operator-re (c-lang-const c-operator-re)) | ||
| 1212 | |||
| 1213 | (c-lang-defconst c-bin-tern-operators | ||
| 1214 | ;; All binary and ternary operators | ||
| 1215 | t (c-filter-ops (c-lang-const c-operators) | ||
| 1216 | '(left-assoc right-assoc right-assoc-sequence) | ||
| 1217 | t)) | ||
| 1218 | |||
| 1219 | (c-lang-defconst c-unary-operators | ||
| 1220 | ;; All unary operators. | ||
| 1221 | t (c-filter-ops (c-lang-const c-operators) | ||
| 1222 | '(prefix postfix postfix-if-paren) | ||
| 1223 | t)) | ||
| 1224 | |||
| 1225 | (c-lang-defconst c-non-after-{}-operators | ||
| 1226 | "Operators which can't appear after a block {..} construct." | ||
| 1227 | t (c--set-difference (c-lang-const c-bin-tern-operators) | ||
| 1228 | (c-lang-const c-unary-operators) | ||
| 1229 | :test #'string-equal) | ||
| 1230 | awk (remove "/" (c-lang-const c-non-after-{}-operators))) | ||
| 1231 | |||
| 1232 | (c-lang-defconst c-non-after-{}-ops-re | ||
| 1233 | ;; A regexp matching operators which can't appear after a block {..} | ||
| 1234 | ;; construct. | ||
| 1235 | t (regexp-opt (c-lang-const c-non-after-{}-operators))) | ||
| 1236 | (c-lang-defvar c-non-after-{}-ops-re (c-lang-const c-non-after-{}-ops-re)) | ||
| 1237 | |||
| 1208 | (c-lang-defconst c-overloadable-operators | 1238 | (c-lang-defconst c-overloadable-operators |
| 1209 | "List of the operators that are overloadable, in their \"identifier | 1239 | "List of the operators that are overloadable, in their \"identifier |
| 1210 | form\". See also `c-op-identifier-prefix'." | 1240 | form\". See also `c-op-identifier-prefix'." |