aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2016-02-15 12:45:42 +0000
committerAlan Mackenzie2016-02-15 15:05:02 +0000
commit02b037b85ce32fdcf454f5b12d72f09bcb217891 (patch)
treed9fda6629d10843b78679d50f06a2c654dc5e07c
parent44b16f60fd80afe574964390d896635971cb5504 (diff)
downloademacs-02b037b85ce32fdcf454f5b12d72f09bcb217891.tar.gz
emacs-02b037b85ce32fdcf454f5b12d72f09bcb217891.zip
Allow arithmetic operators inside C++ template constructs.
Fixes debbugs #22486. This corrects the previous patch with this message which was empty. * lisp/progmodes/cc-langs.el (c-multichar->-op-not->>-regexp): New language variable. (c-<>-notable-chars-re): New language variable. * lisp/progmodes/cc-engine.el (c-forward-<>-arglist-recur): User c-<>-notable-chars-re in place of the former fixed string in searching for places to stop and examine. Use c-multichar->-op-not->>-regexp to check that a found ">" is not part of a multichar operator in place of the former c->-op-without->-cont-regexp. Add code to skip forwards over a balanced parenthesized expression.
-rw-r--r--lisp/progmodes/cc-engine.el14
-rw-r--r--lisp/progmodes/cc-langs.el33
2 files changed, 42 insertions, 5 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index a4a1604e6f4..d4dcb1ca0e8 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -6056,7 +6056,10 @@ comment at the start of cc-engine.el for more info."
6056 ;; Stop on ',', '|', '&', '+' and '-' to catch 6056 ;; Stop on ',', '|', '&', '+' and '-' to catch
6057 ;; common binary operators that could be between 6057 ;; common binary operators that could be between
6058 ;; two comparison expressions "a<b" and "c>d". 6058 ;; two comparison expressions "a<b" and "c>d".
6059 "[<;{},|+&-]\\|[>)]" 6059 ;; 2016-02-11: C++11 templates can now contain arithmetic
6060 ;; expressions, so template detection in C++ is now less
6061 ;; robust than it was.
6062 c-<>-notable-chars-re
6060 nil t t)) 6063 nil t t))
6061 6064
6062 (cond 6065 (cond
@@ -6064,7 +6067,9 @@ comment at the start of cc-engine.el for more info."
6064 ;; Either an operator starting with '>' or the end of 6067 ;; Either an operator starting with '>' or the end of
6065 ;; the angle bracket arglist. 6068 ;; the angle bracket arglist.
6066 6069
6067 (if (looking-at c->-op-without->-cont-regexp) 6070 (if (save-excursion
6071 (c-backward-token-2)
6072 (looking-at c-multichar->-op-not->>-regexp))
6068 (progn 6073 (progn
6069 (goto-char (match-end 0)) 6074 (goto-char (match-end 0))
6070 t) ; Continue the loop. 6075 t) ; Continue the loop.
@@ -6134,6 +6139,11 @@ comment at the start of cc-engine.el for more info."
6134 ))) 6139 )))
6135 t) ; carry on looping. 6140 t) ; carry on looping.
6136 6141
6142 ((and
6143 (eq (char-before) ?\()
6144 (c-go-up-list-forward)
6145 (eq (char-before) ?\))))
6146
6137 ((and (not c-restricted-<>-arglists) 6147 ((and (not c-restricted-<>-arglists)
6138 (or (and (eq (char-before) ?&) 6148 (or (and (eq (char-before) ?&)
6139 (not (eq (char-after) ?&))) 6149 (not (eq (char-after) ?&)))
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index 8a1d43c627c..dd1bccf3d96 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -228,6 +228,12 @@ the evaluated constant value at compile time."
228 ;; with the group symbol for each group and should return non-nil 228 ;; with the group symbol for each group and should return non-nil
229 ;; if that group is to be included. 229 ;; if that group is to be included.
230 ;; 230 ;;
231 ;; OP-FILTER selects the operators. It is either t to select all
232 ;; operators, a string to select all operators for which `string-match'
233 ;; matches the operator with the string, or a function which will be
234 ;; called with the operator and should return non-nil when the operator
235 ;; is to be selected.
236 ;;
231 ;; If XLATE is given, it's a function which is called for each 237 ;; If XLATE is given, it's a function which is called for each
232 ;; matching operator and its return value is collected instead. 238 ;; matching operator and its return value is collected instead.
233 ;; If it returns a list, the elements are spliced directly into 239 ;; If it returns a list, the elements are spliced directly into
@@ -1245,7 +1251,6 @@ operators."
1245 t 1251 t
1246 "\\`<." 1252 "\\`<."
1247 (lambda (op) (substring op 1))))) 1253 (lambda (op) (substring op 1)))))
1248
1249(c-lang-defvar c-<-op-cont-regexp (c-lang-const c-<-op-cont-regexp)) 1254(c-lang-defvar c-<-op-cont-regexp (c-lang-const c-<-op-cont-regexp))
1250 1255
1251(c-lang-defconst c->-op-cont-tokens 1256(c-lang-defconst c->-op-cont-tokens
@@ -1264,7 +1269,6 @@ operators."
1264 ;; Regexp matching the second and subsequent characters of all 1269 ;; Regexp matching the second and subsequent characters of all
1265 ;; multicharacter tokens that begin with ">". 1270 ;; multicharacter tokens that begin with ">".
1266 t (c-make-keywords-re nil (c-lang-const c->-op-cont-tokens))) 1271 t (c-make-keywords-re nil (c-lang-const c->-op-cont-tokens)))
1267
1268(c-lang-defvar c->-op-cont-regexp (c-lang-const c->-op-cont-regexp)) 1272(c-lang-defvar c->-op-cont-regexp (c-lang-const c->-op-cont-regexp))
1269 1273
1270(c-lang-defconst c->-op-without->-cont-regexp 1274(c-lang-defconst c->-op-without->-cont-regexp
@@ -1279,10 +1283,19 @@ operators."
1279 "\\`>>" 1283 "\\`>>"
1280 (lambda (op) (substring op 1))) 1284 (lambda (op) (substring op 1)))
1281 :test 'string-equal))) 1285 :test 'string-equal)))
1282
1283(c-lang-defvar c->-op-without->-cont-regexp 1286(c-lang-defvar c->-op-without->-cont-regexp
1284 (c-lang-const c->-op-without->-cont-regexp)) 1287 (c-lang-const c->-op-without->-cont-regexp))
1285 1288
1289(c-lang-defconst c-multichar->-op-not->>-regexp
1290 ;; Regexp matching multichar tokens containing ">", except ">>"
1291 t (c-make-keywords-re nil
1292 (delete ">>"
1293 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1294 t
1295 "\\(.>\\|>.\\)"))))
1296(c-lang-defvar c-multichar->-op-not->>-regexp
1297 (c-lang-const c-multichar->-op-not->>-regexp))
1298
1286(c-lang-defconst c-stmt-delim-chars 1299(c-lang-defconst c-stmt-delim-chars
1287 ;; The characters that should be considered to bound statements. To 1300 ;; The characters that should be considered to bound statements. To
1288 ;; optimize `c-crosses-statement-barrier-p' somewhat, it's assumed to 1301 ;; optimize `c-crosses-statement-barrier-p' somewhat, it's assumed to
@@ -3087,6 +3100,20 @@ expression is considered to be a type."
3087 ; generics is not yet coded in CC Mode. 3100 ; generics is not yet coded in CC Mode.
3088(c-lang-defvar c-recognize-<>-arglists (c-lang-const c-recognize-<>-arglists)) 3101(c-lang-defvar c-recognize-<>-arglists (c-lang-const c-recognize-<>-arglists))
3089 3102
3103(c-lang-defconst c-<>-notable-chars-re
3104 "A regexp matching any single character notable inside a <...> construct.
3105This must include \"<\" and \">\", and should include \",\", and
3106any character which cannot be valid inside such a construct.
3107This is used in `c-forward-<>-arglist-recur' to try to detect
3108sequences of tokens which cannot be a template/generic construct.
3109When \"(\" is present, that defun will attempt to parse a
3110parenthesized expression inside the template. When \")\" is
3111present it will treat an unbalanced closing paren as a sign of
3112the invalidity of the putative template construct."
3113 t "[<;{},|+&->)]"
3114 c++ "[<;{},>()]")
3115(c-lang-defvar c-<>-notable-chars-re (c-lang-const c-<>-notable-chars-re))
3116
3090(c-lang-defconst c-enums-contain-decls 3117(c-lang-defconst c-enums-contain-decls
3091 "Non-nil means that an enum structure can contain declarations." 3118 "Non-nil means that an enum structure can contain declarations."
3092 t nil 3119 t nil