GNU bug report logs - #15728
24.3.50; cc-mode incorrectly parses particular macro

Previous Next

Packages: emacs, cc-mode;

Reported by: Dima Kogan <dima <at> secretsauce.net>

Date: Sun, 27 Oct 2013 04:17:02 UTC

Severity: normal

Found in version 24.3.50

Done: Alan Mackenzie <acm <at> muc.de>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 15728 in the body.
You can then email your comments to 15728 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#15728; Package emacs. (Sun, 27 Oct 2013 04:17:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Dima Kogan <dima <at> secretsauce.net>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 27 Oct 2013 04:17:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Dima Kogan <dima <at> secretsauce.net>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.3.50; cc-mode incorrectly parses particular macro
Date: Sat, 26 Oct 2013 21:16:12 -0700
I have the following source file:

=========================================================================
int f(void)
{
#define A(b)								\
  int abc ## b;								\
    g()
}
=========================================================================

This indentation is what the latest emacs thinks is correct. Note that
the g() line is indented ahead of the 'int abc' line. This is wrong;
they should have the same indentation. Indeed this is what happens with
emacs23.

In the latest emacs the syntax parser thinks the g() line is
'statement-cont', instead of 'statement'; this is directly related to
the issue. Furthermore, the 'abc ## b' construct is what's confusing the
parser. Removing the '##' makes it parse correctly again.

I'm observing this issue with all emacs24 builds I've tried, with 'emacs
-Q'.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15728; Package emacs. (Sun, 27 Oct 2013 13:52:02 GMT) Full text and rfc822 format available.

Message #8 received at 15728 <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: 15728 <at> debbugs.gnu.org
Cc: Dima Kogan <dima <at> secretsauce.net>
Subject: Re: bug #15728: 24.3.50; cc-mode incorrectly parses particular macro
Date: Sun, 27 Oct 2013 13:49:15 +0000
Hello, Dima

Dima Kogan <dima <at> secretsauce.net> writes:
> I have the following source file:

> =========================================================================
> int f(void)
> {
> #define A(b)                                                            \
>   int abc ## b;                                                         \
>     g()
> }
> =========================================================================

> This indentation is what the latest emacs thinks is correct. Note that
> the g() line is indented ahead of the 'int abc' line. This is wrong;
> they should have the same indentation. Indeed this is what happens with
> emacs23.

> In the latest emacs the syntax parser thinks the g() line is
> 'statement-cont', instead of 'statement'; this is directly related to
> the issue. Furthermore, the 'abc ## b' construct is what's confusing the
> parser. Removing the '##' makes it parse correctly again.

Funnily enough, it seems to work OK if the macro isn't written inside a
function.

> I'm observing this issue with all emacs24 builds I've tried, with 'emacs
> -Q'.

Thanks for the bug report, and thanks even more for making it crisp and
concise.

I think the following patch should fix it.  Would you try it out,
please, and let me know how well it works.



diff -r c21bf2a4a8b8 cc-engine.el
--- a/cc-engine.el	Sun Oct 20 14:10:45 2013 +0000
+++ b/cc-engine.el	Sun Oct 27 13:31:43 2013 +0000
@@ -1266,12 +1266,15 @@
 	      ;; looking for more : and ?.
 	      (setq c-maybe-labelp nil
 		    skip-chars (substring c-stmt-delim-chars 0 -2)))
-	     ;; At a CPP construct?
-	     ((and c-opt-cpp-symbol (looking-at c-opt-cpp-symbol)
-		   (save-excursion
-		     (forward-line 0)
-		     (looking-at c-opt-cpp-prefix)))
-	      (c-end-of-macro))
+	     ;; At a CPP construct or a "#" or "##" operator?
+	     ((and c-opt-cpp-symbol (looking-at c-opt-cpp-symbol))
+	      (if (save-excursion
+		    (skip-chars-backward " \t")
+		    (and (bolp)
+			 (or (bobp)
+			     (not (eq (char-before (1- (point))) ?\\)))))
+		  (c-end-of-macro)
+		(skip-chars-forward c-opt-cpp-symbol)))
 	     ((memq (char-after) non-skip-list)
 	      (throw 'done (point)))))
 	  ;; In trailing space after an as yet undetected virtual semicolon?



-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15728; Package emacs. (Sun, 27 Oct 2013 18:46:02 GMT) Full text and rfc822 format available.

Message #11 received at 15728 <at> debbugs.gnu.org (full text, mbox):

From: Dima Kogan <dima <at> secretsauce.net>
To: 15728 <at> debbugs.gnu.org
Subject: Re: bug #15728: 24.3.50; cc-mode incorrectly parses particular macro
Date: Sun, 27 Oct 2013 11:45:27 -0700
Alan Mackenzie <acm <at> muc.de> writes:

> I think the following patch should fix it.  Would you try it out,
> please, and let me know how well it works.

Hi Alan. I tried the patch and it does solve the issue for me. Thank you
very much for fixing this issue so quickly.

dima




Reply sent to Alan Mackenzie <acm <at> muc.de>:
You have taken responsibility. (Sun, 27 Oct 2013 21:55:02 GMT) Full text and rfc822 format available.

Notification sent to Dima Kogan <dima <at> secretsauce.net>:
bug acknowledged by developer. (Sun, 27 Oct 2013 21:55:03 GMT) Full text and rfc822 format available.

Message #16 received at 15728-done <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: 15728-done <at> debbugs.gnu.org
Subject: Re: bug #15728: 24.3.50; cc-mode incorrectly parses particular macro
Date: Sun, 27 Oct 2013 21:51:54 +0000
Bug fixed.

-- 
Alan Mackenzie (Nuremberg, Germany).




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 25 Nov 2013 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 11 years and 205 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.