Subject: 23.1; Incorrect indentation in C, following certain 'case' labels

From: Benjamin Moody <[email-masked]>
Date: Sat, 29 Aug 2009 16:59:54 -0400

In Emacs 23.1, I've found an issue with the indentation rules for C
mode.  In some circumstances, following a series of multiple labels,
the second and subsequent statements are not indented properly.  For
example, in the following code:

void foo(int x)
{
  switch (x) {
  case 1:
  case 2:
    printf("aaa");
    break;

  case '3':
  case '4':
    printf("bbb");
  break;
  }
}

the second 'break' statement should be indented by 4 spaces, to align
with the 'printf'.

This problem seems to appear when there are multiple labels (either
normal named labels, 'case' labels, or 'default' labels) in a row,
with no intervening statments, and either the first or the last such
label is a 'case' label with a character constant as its value.

This problem does NOT occur with Emacs 22.3.  It does occur in C++ and
ObjC modes as well.  It affects indentation using either TAB or M-x
indent-region.

A workaround is to place the character constant(s) in parentheses.

This is obviously not a serious problem, but it is a somewhat annoying
one which would be nice to see fixed.

Benjamin Moody

In GNU Emacs 23.1.1 (x86_64-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
 of 2009-08-03 on nautilus, modified by Debian
Windowing system distributor `The X.Org Foundation', version 11.0.10402000
configured using `configure  '--build=x86_64-linux-gnu' '--host=x86_64-linux-gnu' '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib' '--localstatedir=/var/lib' '--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-pop=yes' '--enable-locallisppath=/etc/emacs23:/etc/emacs:/usr/local/share/emacs/23.1/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/23.1/site-lisp:/usr/share/emacs/site-lisp:/usr/share/emacs/23.1/leim' '--with-x=yes' '--with-x-toolkit=athena' '--with-toolkit-scroll-bars' 'build_alias=x86_64-linux-gnu' 'host_alias=x86_64-linux-gnu' 'CFLAGS=-DDEBIAN -g -O2' 'LDFLAGS=-g' 'CPPFLAGS=''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: nil
  locale-coding-system: utf-8-unix
  default-enable-multibyte-characters: t

Major mode: C/l

Minor modes in effect:
  iswitchb-mode: t
  tooltip-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  global-auto-composition-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: t
  line-number-mode: t
  abbrev-mode: t

Recent input:
<help-echo> C-x C-f / t m p / t e s t . c <return> 
v o i d SPC f o o ( i n t SPC x ) <return> { <return> 
<tab> s w i t c h SPC ( x ) SPC { <return> <tab> c 
a s d e <backspace> <backspace> e 1 SPC <backspace> 
<backspace> SPC 1 : <return> <tab> c a s e SPC 2 : 
<return> <tab> p r i n t f ( " a a a " ) ; <return> 
<tab> b r e a k ; <return> <return> <tab> c a s e SPC 
' 3 ' : <return> <tab> c a s e SPC ' 4 ' : <return> 
<tab> p r i n t f ( " b b b " ) ; <return> <tab> b 
r e a k j ; <backspace> <backspace> ; <return> } <S-return> 
} <return> M-x r e p o r t - e m a <tab> <return>

Recent messages:
Setting up ede...
Loading `eieio': old-style backquotes detected!
Setting up ede...done
Setting up eieio...done
Setting up semantic...done
Setting up speedbar...done
Setting up cedet-contrib...done
Loading /etc/emacs/site-start.d/55ecb.el (source)...done
For information about GNU Emacs and the GNU system, type C-h C-a.
(New file)