GNU bug report logs -
#23901
CC Mode 5.33 (Java/l); Wrong indentation of fallthrough switch/case with strings
Previous Next
Full log
View this message in rfc822 format
Hello, Åsmund.
On Tue, Jul 05, 2016 at 09:37:15PM +0200, Åsmund Grammeltvedt wrote:
> Hi!
> Running indent-region on the following code produces wrong indentation
> on all but the first statement in the last switch block.
OK.
> I have included two cases that work correctly for comparison:
Thank you for such a clear description of the fault, and thanks also for
including a CC Mode configuration dump (from C-c C-b).
> class Foo {
> public void Bar(String foo) {
> int a = 0;
> switch (a) {
> case 0:
> case 1:
> a += 1;
> a += 2;
> break;
> }
> switch (foo) {
> case "foo":
> a += 1;
> a += 2;
> break;
> }
> switch (foo) {
> case "foo":
> case "bar":
> a += 1;
> a += 2;
> break;
> }
> }
> }
The problem appears to be in the CC Mode variable
`c-nonlabel-token-key', which specifies things which can't be in a
label. The Java value includes the character '"', presumably from a
period in ancient history when strings in Java couldn't be case labels.
Please try out the following fix, and please confirm that it has fixed
the bug, or tell me what is still not right. The file cc-langs.el is in
the directory ..../lisp/progmodes/.
Note that after applying the patch, you need to recompile, at the very
least, cc-langs.el, cc-fonts.el, cc-engine.el, cc-mode.el. (Or just
recompile all of cc-*.el).
diff -r 2fcfc6e054b3 cc-langs.el
--- a/cc-langs.el Sun Jul 03 17:54:20 2016 +0000
+++ b/cc-langs.el Wed Jul 06 11:45:48 2016 +0000
@@ -3233,8 +3233,8 @@
(append (c-lang-const c-label-kwds)
(c-lang-const c-protection-kwds))
:test 'string-equal)))
- ;; Don't allow string literals, except in AWK. Character constants are OK.
- (c objc java pike idl) (concat "\"\\|"
+ ;; Don't allow string literals, except in AWK and Java. Character constants are OK.
+ (c objc pike idl) (concat "\"\\|"
(c-lang-const c-nonlabel-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
> Emacs : GNU Emacs 25.1.50.2 (x86_64-pc-linux-gnu, GTK+ Version 3.10.8)
> of 2016-04-15
> Package: CC Mode 5.33 (Java/l)
> Buffer Style: java
> c-emacs-features: (pps-extended-state col-0-paren posix-char-classes
> gen-string-delim gen-comment-delim syntax-properties 1-bit)
[ CC Mode state appreciated and snipped. ]
> --
> Åsmund Grammeltvedt
--
Alan Mackenzie (Nuremberg, Germany).
This bug report was last modified 8 years and 355 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.