GNU bug report logs - #33649
26.1.50; variable is highlighted as type in c++ mode

Previous Next

Packages: emacs, cc-mode;

Reported by: Shanavas <shanavas.m2 <at> gmail.com>

Date: Thu, 6 Dec 2018 15:29:02 UTC

Severity: minor

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 33649 in the body.
You can then email your comments to 33649 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#33649; Package emacs. (Thu, 06 Dec 2018 15:29:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Shanavas <shanavas.m2 <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 06 Dec 2018 15:29:03 GMT) Full text and rfc822 format available.

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

From: Shanavas <shanavas.m2 <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 26.1.50; variable is highlighted as type in c++ mode
Date: Thu, 06 Dec 2018 16:51:41 +0530
[Message part 1 (text/plain, inline)]
For the following snippet,

```
int a = 9;
func(a);
func(a * 9);
```
`a` is highlighted differently in two function calls.
In `func(a)` it is highlighted as a variable where in `func(a * 9)` it is highlighted as a type.

Major mode: C++//l
-- 
ഷാനവാസ്
Sent from my Android device with K-9 Mail.
[Message part 2 (text/html, inline)]

bug reassigned from package 'emacs' to 'emacs,cc-mode'. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Thu, 06 Dec 2018 18:51:01 GMT) Full text and rfc822 format available.

bug No longer marked as found in versions 26.1.50. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Thu, 06 Dec 2018 18:51:01 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#33649; Package emacs,cc-mode. (Fri, 07 Dec 2018 16:40:01 GMT) Full text and rfc822 format available.

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

From: Alan Mackenzie <acm <at> muc.de>
To: Shanavas <shanavas.m2 <at> gmail.com>
Cc: 33649 <at> debbugs.gnu.org
Subject: Re: bug#33649: 26.1.50; variable is highlighted as type in c++ mode
Date: 7 Dec 2018 16:39:51 -0000
Hello Shanavas.

In article <mailman.5279.1544110157.1284.bug-gnu-emacs <at> gnu.org> you wrote:
> [-- text/plain, encoding quoted-printable, charset: utf-8, 15 lines --]

> For the following snippet,

> ```
> int a = 9;
> func(a);
> func(a * 9);
> ```
> `a` is highlighted differently in two function calls.
> In `func(a)` it is highlighted as a variable where in `func(a * 9)` it is highlighted as a type.

Yes.  It is due to CC Mode parsing "a *" as a "pointer to type a"
without taking into account the following "9".  Thanks for taking the
trouble to report this bug.

The following patch should fix this.  Would you please try it out on
your real source code, and either confirm to me that it works, or tell
me what is still wrong.

The patch should be applied to emacs/lisp/progmodes/cc-engine.el, and
you should then byte-compile the patched file.  If you want any help
with the patching or the byte compilation, feel free to send me private
mail.

Thanks again, and looking forward to hearing back from you.



diff -r 021672422937 cc-engine.el
--- a/cc-engine.el	Sat Nov 24 10:18:12 2018 +0000
+++ b/cc-engine.el	Fri Dec 07 16:23:37 2018 +0000
@@ -8551,6 +8551,8 @@
 	  got-parens
 	  ;; True if there is an identifier in the declarator.
 	  got-identifier
+	  ;; True if we find a number where an identifier was expected.
+	  got-number
 	  ;; True if there's a non-close-paren match of
 	  ;; `c-type-decl-suffix-key'.
 	  got-suffix
@@ -8628,7 +8630,9 @@
 	  (and (looking-at c-identifier-start)
 	       (setq pos (point))
 	       (setq got-identifier (c-forward-name))
-	       (setq name-start pos)))
+	       (setq name-start pos))
+	  (when (looking-at "[0-9]")
+	    (setq got-number t))) ; We've probably got an arithmetic expression.
 
       ;; Skip over type decl suffix operators and trailing noise macros.
       (while
@@ -9102,7 +9106,7 @@
 
 	   ;; CASE 18
 	   (when (and (not (memq context '(nil top)))
-		      (or got-prefix
+		      (or (and got-prefix (not got-number))
 			  (and (eq context 'decl)
 			       (not c-recognize-paren-inits)
 			       (or got-parens got-suffix))))


> Major mode: C++//l
> -- 
> ഷാനവാസ്
> Sent from my Android device with K-9 Mail.

-- 
Alan Mackenzie (Nuremberg, Germany).





Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#33649; Package emacs,cc-mode. (Mon, 10 Dec 2018 07:44:02 GMT) Full text and rfc822 format available.

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

From: Shanavas <shanavas.m2 <at> gmail.com>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 33649 <at> debbugs.gnu.org
Subject: Re: bug#33649: 26.1.50; variable is highlighted as type in c++ mode
Date: Mon, 10 Dec 2018 13:12:54 +0530
[Message part 1 (text/plain, inline)]
Thanks, Works great.

Please apply appropriate patch to emacs-26 branch too.
-- 
ഷാനവാസ്
Sent from my Android device with K-9 Mail.
[Message part 2 (text/html, inline)]

Reply sent to Alan Mackenzie <acm <at> muc.de>:
You have taken responsibility. (Mon, 10 Dec 2018 12:26:01 GMT) Full text and rfc822 format available.

Notification sent to Shanavas <shanavas.m2 <at> gmail.com>:
bug acknowledged by developer. (Mon, 10 Dec 2018 12:26:01 GMT) Full text and rfc822 format available.

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

From: Alan Mackenzie <acm <at> muc.de>
To: Shanavas <shanavas.m2 <at> gmail.com>
Cc: 33649-done <at> debbugs.gnu.org
Subject: Re: bug#33649: 26.1.50; variable is highlighted as type in c++ mode
Date: Mon, 10 Dec 2018 12:20:39 +0000
Hello, Shanavas.

On Mon, Dec 10, 2018 at 13:12:54 +0530, Shanavas wrote:
> Thanks, Works great.

Thank you for the testing!

> Please apply appropriate patch to emacs-26 branch too.

I've applied the patch to the emacs-26 branch.  It will filter through
to the master branch in due course when "somebody" activates the
movement of bug fixes from emacs-26 to master.

I'm closing the bug, now.

> -- 
> ഷാനവാസ്
> Sent from my Android device with K-9 Mail.

-- 
Alan Mackenzie (Nuremberg, Germany).




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

This bug report was last modified 5 years and 122 days ago.

Previous Next


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