From unknown Sat Aug 09 14:04:46 2025 X-Loop: owner@emacsbugs.donarmstrong.com Subject: bug#4289: 23.1; Incorrect indentation in C, following certain 'case' labels Reply-To: Benjamin Moody , 4289@debbugs.gnu.org Resent-From: Benjamin Moody Resent-To: bug-submit-list@lists.donarmstrong.com Resent-CC: Emacs Bugs 2Resent-Date: Sat, 29 Aug 2009 21:05:05 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-Emacs-PR-Message: report 4289 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: Received: via spool by submit@emacsbugs.donarmstrong.com id=B.125157961018659 (code B ref -1); Sat, 29 Aug 2009 21:05:05 +0000 Received: (at submit) by emacsbugs.donarmstrong.com; 29 Aug 2009 21:00:10 +0000 X-Spam-Checker-Version: SpamAssassin 3.2.5-bugs.debian.org_2005_01_02 (2008-06-10) on rzlab.ucr.edu X-Spam-Level: X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. X-Spam-Status: No, score=0.1 required=4.0 tests=FOURLA,FVGT_m_MULTI_ODD autolearn=no version=3.2.5-bugs.debian.org_2005_01_02 Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id n7TL08fY018615 for ; Sat, 29 Aug 2009 14:00:09 -0700 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MhV1s-0001FD-Fo for bug-gnu-emacs@gnu.org; Sat, 29 Aug 2009 17:00:08 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MhV1n-0001EB-NL for bug-gnu-emacs@gnu.org; Sat, 29 Aug 2009 17:00:08 -0400 Received: from [199.232.76.173] (port=34540 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MhV1n-0001E8-Kp for bug-gnu-emacs@gnu.org; Sat, 29 Aug 2009 17:00:03 -0400 Received: from qw-out-1920.google.com ([74.125.92.149]:58348) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MhV1n-0002oZ-1G for bug-gnu-emacs@gnu.org; Sat, 29 Aug 2009 17:00:03 -0400 Received: by qw-out-1920.google.com with SMTP id 5so1043446qwf.24 for ; Sat, 29 Aug 2009 14:00:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:received:date:message-id:from :to:subject; bh=DtS9U9tS7IeDf47bdZy7T0m3ZYsVqDx+lgx++8YSFUQ=; b=ilSBSpI4dRBeUCisy/E22g0EeGktsw8lmTN/AhqeEKnFeU9CoYgT383PrCJy825dRA 6m1WEDyjlZ3w4otwOYuHm1T+DXNJIuPqgv1HZfQvk+dvCUb1QtvgMYcHmL4co6wea/Nc iL69BKGDLpuCRPLxR3x0UwxXhOv2y9y6XY4LY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:message-id:from:to:subject; b=LMhtVSL84b/BZoQpOePe7aU7J6qJrbcwMJMwtoZ+7D7moNaF+lsn7wYjHf0KaHoERC GexPI9iKfk+3V6osbL9ZrBk9Aei3ei6xmoIm2/cyCGKor7dwKHGD//4V30W3/OsbAQZe h+0/5DMnK9FfBYQsneVufvSUmhopSxX1jFu/8= Received: by 10.224.14.143 with SMTP id g15mr2210203qaa.123.1251579600568; Sat, 29 Aug 2009 14:00:00 -0700 (PDT) Received: from bigdeer.rsh.net (c-24-60-162-5.hsd1.ma.comcast.net [24.60.162.5]) by mx.google.com with ESMTPS id 6sm4212299qwd.2.2009.08.29.13.59.59 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 29 Aug 2009 13:59:59 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=bigdeer.rsh.net ident=benjamin) by bigdeer.rsh.net with esmtp (Exim 4.69) (envelope-from ) id 1MhV1f-0007w0-84 for bug-gnu-emacs@gnu.org; Sat, 29 Aug 2009 16:59:55 -0400 Date: Sat, 29 Aug 2009 16:59:54 -0400 Message-Id: <87eiqupc8l.fsf@bigdeer.rsh.net> From: Benjamin Moody To: bug-gnu-emacs@gnu.org X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) 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: C-x C-f / t m p / t e s t . c v o i d SPC f o o ( i n t SPC x ) { s w i t c h SPC ( x ) SPC { c a s d e e 1 SPC SPC 1 : c a s e SPC 2 : p r i n t f ( " a a a " ) ; b r e a k ; c a s e SPC ' 3 ' : c a s e SPC ' 4 ' : p r i n t f ( " b b b " ) ; b r e a k j ; ; } } M-x r e p o r t - e m a 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) From rgm@gnu.org Sun Aug 30 18:39:40 2009 Received: (at control) by emacsbugs.donarmstrong.com; 31 Aug 2009 01:39:40 +0000 X-Spam-Checker-Version: SpamAssassin 3.2.5-bugs.debian.org_2005_01_02 (2008-06-10) on rzlab.ucr.edu X-Spam-Level: X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. X-Spam-Status: No, score=-4.8 required=4.0 tests=AWL,ONEWORD,X_DEBBUGS_NO_ACK autolearn=ham version=3.2.5-bugs.debian.org_2005_01_02 Received: from fencepost.gnu.org (fencepost.gnu.org [140.186.70.10]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id n7V1ddqG020147 for ; Sun, 30 Aug 2009 18:39:40 -0700 Received: from rgm by fencepost.gnu.org with local (Exim 4.67) (envelope-from ) id 1Mhvrt-0003sr-N5; Sun, 30 Aug 2009 21:39:37 -0400 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <19099.10713.648314.852464@fencepost.gnu.org> Date: Sun, 30 Aug 2009 21:39:37 -0400 From: Glenn Morris To: control Subject: control X-Debbugs-No-Ack: yes close 1306 reassign 4289 emacs,cc-mode severity 4288 wishlist From unknown Sat Aug 09 14:04:46 2025 X-Loop: owner@emacsbugs.donarmstrong.com Subject: bug#4289: 23.1; Incorrect indentation in C, following certain 'case' labels Reply-To: Alan Mackenzie , 4289@debbugs.gnu.org Resent-From: Alan Mackenzie Resent-To: bug-submit-list@lists.donarmstrong.com Resent-CC: Emacs Bugs , owner@debbugs.gnu.org 2Resent-Date: Mon, 31 Aug 2009 20:10:05 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-Emacs-PR-Message: followup 4289 X-Emacs-PR-Package: emacs,cc-mode X-Emacs-PR-Keywords: Received: via spool by submit@emacsbugs.donarmstrong.com id=B.125174896115516 (code B ref -1); Mon, 31 Aug 2009 20:10:05 +0000 Received: (at submit) by emacsbugs.donarmstrong.com; 31 Aug 2009 20:02:41 +0000 X-Spam-Checker-Version: SpamAssassin 3.2.5-bugs.debian.org_2005_01_02 (2008-06-10) on rzlab.ucr.edu X-Spam-Level: X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. X-Spam-Status: No, score=-4.3 required=4.0 tests=AWL,FVGT_m_MULTI_ODD, HAS_BUG_NUMBER,MURPHY_DRUGS_REL8 autolearn=unavailable version=3.2.5-bugs.debian.org_2005_01_02 Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id n7VK2enn015510 for ; Mon, 31 Aug 2009 13:02:41 -0700 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MiD5L-0005E5-Q4 for bug-gnu-emacs@gnu.org; Mon, 31 Aug 2009 16:02:39 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MiD5H-0005BG-5h for bug-gnu-emacs@gnu.org; Mon, 31 Aug 2009 16:02:39 -0400 Received: from [199.232.76.173] (port=53090 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MiD5G-0005BC-Ra for bug-gnu-emacs@gnu.org; Mon, 31 Aug 2009 16:02:34 -0400 Received: from colin.muc.de ([193.149.48.1]:3913 helo=mail.muc.de) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MiD5G-0007XX-3Y for bug-gnu-emacs@gnu.org; Mon, 31 Aug 2009 16:02:34 -0400 Received: (qmail 69752 invoked by uid 3782); 31 Aug 2009 20:02:29 -0000 Received: from acm.muc.de (pD9E52A28.dip.t-dialin.net [217.229.42.40]) by colin2.muc.de (tmda-ofmipd) with ESMTP; Mon, 31 Aug 2009 22:02:27 +0200 Received: (qmail 16005 invoked by uid 1000); 31 Aug 2009 20:05:38 -0000 Date: Mon, 31 Aug 2009 20:05:38 +0000 To: Benjamin Moody , 4289@debbugs.gnu.org Cc: bug-gnu-emacs@gnu.org Message-ID: <20090831200538.GA15906@muc.de> References: <87eiqupc8l.fsf@bigdeer.rsh.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87eiqupc8l.fsf@bigdeer.rsh.net> User-Agent: Mutt/1.5.9i X-Delivery-Agent: TMDA/1.1.5 (Fettercairn) From: Alan Mackenzie X-Primary-Address: acm@muc.de X-detected-operating-system: by monty-python.gnu.org: FreeBSD 4.6-4.9 Hi, Benjamin! On Sat, Aug 29, 2009 at 04:59:54PM -0400, Benjamin Moody wrote: > 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'. Indeed it should. > 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. Yuck! > This is obviously not a serious problem, ... I might disagree about that. > ... but it is a somewhat annoying one which would be nice to see fixed. OK. Would you please test the patch below, which I think fixes it. Once you've applied the patch, please rebuild the CC Mode files as follows: M-x byte-compile-file cc-langs.el M-x byte-compile-file cc-engine.el M-x byte-compile-file cc-mode.el (This is needed because cc-{engine,mode}.el use macros contained in cc-langs.el.) Then restart Emacs if necessary, then test your file. Thank you indeed for such a wonderfully clear, concise and helpful bug report! Index: cc-engine.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/progmodes/cc-engine.el,v retrieving revision 1.76 diff -c -r1.76 cc-engine.el *** cc-engine.el 29 Aug 2009 02:07:45 -0000 1.76 --- cc-engine.el 31 Aug 2009 19:55:19 -0000 *************** *** 1067,1074 **** (not (eq ret 'beginning)) (looking-at c-case-kwds-regexp)) (if (< after-case:-pos start) ! (setq pos after-case:-pos) ! (setq ret 'label))) ;; Skip over the unary operators that can start the statement. (while (progn --- 1067,1075 ---- (not (eq ret 'beginning)) (looking-at c-case-kwds-regexp)) (if (< after-case:-pos start) ! (setq pos after-case:-pos)) ! (if (eq ret 'same) ! (setq ret 'label))) ;; Skip over the unary operators that can start the statement. (while (progn Index: cc-langs.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/progmodes/cc-langs.el,v retrieving revision 1.67 diff -c -r1.67 cc-langs.el *** cc-langs.el 19 May 2009 22:35:07 -0000 1.67 --- cc-langs.el 31 Aug 2009 19:55:21 -0000 *************** *** 2885,2891 **** i.e. before \":\". Only used if `c-recognize-colon-labels' is set." t (concat ;; Don't allow string literals. ! "[\"']\\|" ;; All keywords except `c-label-kwds' and `c-protection-kwds'. (c-make-keywords-re t (set-difference (c-lang-const c-keywords) --- 2885,2891 ---- i.e. before \":\". Only used if `c-recognize-colon-labels' is set." t (concat ;; Don't allow string literals. ! "\"\\|" ;; All keywords except `c-label-kwds' and `c-protection-kwds'. (c-make-keywords-re t (set-difference (c-lang-const c-keywords) > Benjamin Moody -- Alan Mackenzie (Nuremberg, Germany) From lekktu@gmail.com Thu Oct 22 02:35:31 2009 Received: (at control) by emacsbugs.donarmstrong.com; 22 Oct 2009 09:35:32 +0000 X-Spam-Checker-Version: SpamAssassin 3.2.5-bugs.debian.org_2005_01_02 (2008-06-10) on rzlab.ucr.edu X-Spam-Level: X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. X-Spam-Status: No, score=0.0 required=4.0 tests=AWL,MISSING_SUBJECT, MURPHY_DRUGS_REL8,NOSUBJECT,VALID_BTS_CONTROL autolearn=no version=3.2.5-bugs.debian.org_2005_01_02 Received: from mail-fx0-f213.google.com (mail-fx0-f213.google.com [209.85.220.213]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id n9M9ZTNW004084 for ; Thu, 22 Oct 2009 02:35:31 -0700 Received: by fxm9 with SMTP id 9so9696363fxm.1 for ; Thu, 22 Oct 2009 02:35:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:from:date:message-id :subject:to:content-type; bh=8EmqKmTQZFxRHmBqMf0mAHPBq3MFliknc0lztWoJq6Y=; b=HxQYupT4FFltZz1ItMJj0h3XTFYNK5e7ryT0Cek2T3YESYQLNQM8G9V9i2CKiMAEbc EvYuLj8f7w1qApk14qvzihjcYCGQUOU+1DBevO5UhGKLQhzQ6+vBiuihHNGFYaXeeEYe kJYg0CmwEGM5xp9e/Qz4pt4br7Ml4TcpNJkWo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; b=Y5ybjjcxlLdLgAFAm7oQwPF4q6enZ/vhDgoBesbKLPsYfKZBy2gNxuVUArd1lZsA9C Mqc9bcUQhekOxrkhuBrM/oRLNjZDm8m0DPtCnEMhvvK6rKfs9H9j6QMJR6VObUwlfUeo 7VB35jQ8OYFrwvpcsbgPdQA8bmjmcb1XFRU14= MIME-Version: 1.0 Received: by 10.239.145.8 with SMTP id q8mr761204hba.122.1256204124158; Thu, 22 Oct 2009 02:35:24 -0700 (PDT) From: Juanma Barranquero Date: Thu, 22 Oct 2009 11:35:04 +0200 Message-ID: Subject: To: control@debbugs.gnu.org Content-Type: text/plain; charset=UTF-8 reassign 4326 emacs,ns merge 4261 4434 merge 1589 3359 4207 merge 3829 4077 tags 4781 + patch tags 4747 + patch tags 4579 + patch tags 4471 + patch tags 4434 + patch tags 4234 + patch tags 4221 + patch tags 4147 + patch tags 4144 + patch tags 4139 + patch tags 4023 + patch tags 4736 + moreinfo unreproducible tags 4547 + notabug tags 4451 + notabug tags 4448 + moreinfo tags 4427 + moreinfo tags 4373 + notabug tags 4360 + notabug tags 4271 + moreinfo tags 4236 + moreinfo tags 4143 + moreinfo unreproducible tags 4120 + moreinfo unreproducible tags 4070 + moreinfo unreproducible severity 4422 wishlist severity 4396 minor severity 4394 minor severity 4341 wishlist severity 4300 minor severity 4263 minor severity 4178 minor severity 4172 wishlist severity 4110 wishlist severity 4056 wishlist close 4772 close 4700 close 4599 close 4515 close 4463 close 4445 close 4395 close 4334 close 4289 close 4219 quit