]> git.eshelyaron.com Git - emacs.git/commitdiff
C++ Mode: Correctly handle <:, <::, <::>, etc, according to the C++ standard
authorAlan Mackenzie <acm@muc.de>
Fri, 11 Oct 2019 19:10:11 +0000 (19:10 +0000)
committerAlan Mackenzie <acm@muc.de>
Fri, 11 Oct 2019 19:10:11 +0000 (19:10 +0000)
* lisp/progmodes/cc-engine.el (c-before-change-check-<>-operators): Perform
checking now on an insertion, should point be inside a critical token.
(c-forward-<>-arglist-recur, c-guess-continued-construct): Check for <::, etc.

* lisp/progmodes/cc-langs.el (c-<-pseudo-digraph-cont-regexp)
(c-<-pseudo-digraph-cont-len): New lang variables/constants.

lisp/progmodes/cc-engine.el
lisp/progmodes/cc-langs.el

index 4ca440fd84b4f9227b27d7e22a874272fec7e9cb..9ed4fe3d88cacb97cb62617cea69057ff770df4b 100644 (file)
@@ -6922,7 +6922,15 @@ comment at the start of cc-engine.el for more info."
   ;;
   ;; FIXME!!!  This routine ignores the possibility of macros entirely.
   ;; 2010-01-29.
-  (when (and (> end beg)
+  (when (and (or (> end beg)
+                (and (> c-<-pseudo-digraph-cont-len 0)
+                     (goto-char beg)
+                     (progn
+                       (skip-chars-backward
+                        "^<" (max (- (point) c-<-pseudo-digraph-cont-len)
+                                  (point-min)))
+                       (eq (char-before) ?<))
+                     (looking-at c-<-pseudo-digraph-cont-regexp)))
             (or
              (progn
                (goto-char beg)
@@ -7948,7 +7956,8 @@ comment at the start of cc-engine.el for more info."
 
       (forward-char) ; Forward over the opening '<'.
 
-      (unless (looking-at c-<-op-cont-regexp)
+      (unless (and (looking-at c-<-op-cont-regexp)
+                  (not (looking-at c-<-pseudo-digraph-cont-regexp)))
        ;; go forward one non-alphanumeric character (group) per iteration of
        ;; this loop.
        (while (and
@@ -8026,7 +8035,8 @@ comment at the start of cc-engine.el for more info."
                  (let (id-start id-end subres keyword-match)
                    (cond
                     ;; The '<' begins a multi-char operator.
-                    ((looking-at c-<-op-cont-regexp)
+                    ((and (looking-at c-<-op-cont-regexp)
+                          (not (looking-at c-<-pseudo-digraph-cont-regexp)))
                      (goto-char (match-end 0)))
                     ;; We're at a nested <.....>
                     ((progn
@@ -12552,7 +12562,8 @@ comment at the start of cc-engine.el for more info."
                  (/= (char-before placeholder) ?<)
                  (progn
                    (goto-char (1+ placeholder))
-                   (not (looking-at c-<-op-cont-regexp))))))
+                   (or (not (looking-at c-<-op-cont-regexp))
+                       (looking-at c-<-pseudo-digraph-cont-regexp))))))
       (goto-char placeholder)
       (c-beginning-of-statement-1 containing-sexp t)
       (if (save-excursion
index d092094817c701bee07ebe39b02633e0b5ae3a34..a6fdc3ec798daa6063c74a32337217bf4608e465 100644 (file)
@@ -1406,6 +1406,23 @@ operators."
                    (lambda (op) (substring op 1)))))
 (c-lang-defvar c-<-op-cont-regexp (c-lang-const c-<-op-cont-regexp))
 
+(c-lang-defconst c-<-pseudo-digraph-cont-regexp
+  "Regexp matching the continuation of a pseudo digraph starting \"<\".
+This is used only in C++ Mode, where \"<::\" is handled as a
+template opener followed by the \"::\" operator - usually."
+  t regexp-unmatchable
+  c++ "::\\([^:>]\\|$\\)")
+(c-lang-defvar c-<-pseudo-digraph-cont-regexp
+              (c-lang-const c-<-pseudo-digraph-cont-regexp))
+
+(c-lang-defconst c-<-pseudo-digraph-cont-len
+  "The maximum length of the main bit of a `c-<pseudp-digraph-cont-regexp' match.
+This doesn't count the merely contextual bits of the regexp match."
+  t 0
+  c++ 2)
+(c-lang-defvar c-<-pseudo-digraph-cont-len
+              (c-lang-const c-<-pseudo-digraph-cont-len))
+
 (c-lang-defconst c->-op-cont-tokens
   ;; A list of second and subsequent characters of all multicharacter tokens
   ;; that begin with ">".