;; (including a case label) or something like C++'s "public:"?
;; A case label might use an expression rather than a token.
(setq after-case:-pos (or tok start))
- (if (or (looking-at c-nonlabel-token-key) ; e.g. "while" or "'a'"
+ (if (or (looking-at c-nonlabel-nonparen-token-key)
+ ; e.g. "while" or "'a'"
;; Catch C++'s inheritance construct "class foo : bar".
(save-excursion
(and
(c-safe (c-backward-sexp) t)
- (looking-at c-nonlabel-token-2-key))))
+ (looking-at c-nonlabel-token-2-key)))
+ ;; Catch C++'s "case a(1):"
+ (and (c-major-mode-is 'c++-mode)
+ (eq (char-after) ?\()
+ (save-excursion
+ (not (and
+ (zerop (c-backward-token-2 2))
+ (looking-at c-case-kwds-regexp))))))
(setq c-maybe-labelp nil)
(if after-labels-pos ; Have we already encountered a label?
(if (not last-label-pos)
c++ (concat "\\s(\\|\"\\|" (c-lang-const c-nonlabel-token-key)))
(c-lang-defvar c-nonlabel-token-key (c-lang-const c-nonlabel-token-key))
+(c-lang-defconst c-nonlabel-nonparen-token-key
+ "Regexp matching things that can't occur in generic colon labels,
+neither in a statement nor in a declaration context, with the
+exception of an open parenthesis. The regexp is tested at the
+beginning of every sexp in a suspected label, i.e. before \":\".
+Only used if `c-recognize-colon-labels' is set."
+ ;; This lang const is the same as `c-nonlabel-token-key', except for a
+ ;; slight difference in the c++-mode value.
+ t (concat
+ ;; All keywords except `c-label-kwds' and `c-protection-kwds'.
+ (c-make-keywords-re t
+ (c--set-difference (c-lang-const c-keywords)
+ (append (c-lang-const c-label-kwds)
+ (c-lang-const c-protection-kwds))
+ :test 'string-equal)))
+ ;; Don't allow string literals, except in AWK and Java. Character constants are OK.
+ (c objc pike idl) (concat "\"\\|"
+ (c-lang-const c-nonlabel-nonparen-token-key))
+ ;; Also check for open parens in C++, to catch member init lists in
+ ;; constructors. We normally allow it so that macros with arguments
+ ;; work in labels.
+ c++ (concat "[{[]\\|\"\\|" (c-lang-const c-nonlabel-nonparen-token-key)))
+(c-lang-defvar c-nonlabel-nonparen-token-key
+ (c-lang-const c-nonlabel-nonparen-token-key))
+
(c-lang-defconst c-nonlabel-token-2-key
"Regexp matching things that can't occur two symbols before a colon in
a label construct. This catches C++'s inheritance construct \"class foo