From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#33649: 26.1.50; variable is highlighted as type in c++ mode Date: 7 Dec 2018 16:39:51 -0000 Organization: muc.de e.V. Message-ID: <20181207163951.49237.qmail@mail.muc.de> References: <5C09219F-CA27-4B4E-9373-16923BB0829D@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1544200692 21841 195.159.176.226 (7 Dec 2018 16:38:12 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 7 Dec 2018 16:38:12 +0000 (UTC) User-Agent: tin/2.4.2-20171224 ("Lochhead") (UNIX) (FreeBSD/11.2-RELEASE-p4 (amd64)) Cc: 33649@debbugs.gnu.org To: Shanavas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Dec 07 17:38:08 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gVJ8d-0005TN-Ss for geb-bug-gnu-emacs@m.gmane.org; Fri, 07 Dec 2018 17:38:04 +0100 Original-Received: from localhost ([::1]:47058 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gVJAk-0002qL-Ju for geb-bug-gnu-emacs@m.gmane.org; Fri, 07 Dec 2018 11:40:14 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50641) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gVJAd-0002m1-Rn for bug-gnu-emacs@gnu.org; Fri, 07 Dec 2018 11:40:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gVJAc-0006zW-P9 for bug-gnu-emacs@gnu.org; Fri, 07 Dec 2018 11:40:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:32974) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gVJAY-0006Wy-2D; Fri, 07 Dec 2018 11:40:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gVJAX-0007f4-Ux; Fri, 07 Dec 2018 11:40:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Fri, 07 Dec 2018 16:40:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 33649 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: Original-Received: via spool by 33649-submit@debbugs.gnu.org id=B33649.154420079529434 (code B ref 33649); Fri, 07 Dec 2018 16:40:01 +0000 Original-Received: (at 33649) by debbugs.gnu.org; 7 Dec 2018 16:39:55 +0000 Original-Received: from localhost ([127.0.0.1]:37232 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gVJAR-0007ef-0h for submit@debbugs.gnu.org; Fri, 07 Dec 2018 11:39:55 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:61454 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1gVJAO-0007eW-Va for 33649@debbugs.gnu.org; Fri, 07 Dec 2018 11:39:53 -0500 Original-Received: (qmail 49238 invoked by uid 3782); 7 Dec 2018 16:39:51 -0000 In-Reply-To: X-Newsgroups: gnu.emacs.bug X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:153181 Archived-At: Hello Shanavas. In article you wrote= : > [-- text/plain, encoding quoted-printable, charset: utf-8, 15 lines --] > For the following snippet, > ``` > int a =3D 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= . =20 ;; Skip over type decl suffix operators and trailing noise macros. (while @@ -9102,7 +9106,7 @@ =20 ;; 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 > --=20 > =E0=B4=B7=E0=B4=BE=E0=B4=A8=E0=B4=B5=E0=B4=BE=E0=B4=B8=E0=B5=8D > Sent from my Android device with K-9 Mail. --=20 Alan Mackenzie (Nuremberg, Germany).