From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Bastian Beischer Newsgroups: gmane.emacs.bugs Subject: bug#24377: 25.1; CC-Mode (C++) uses font-lock-type-face for ordinary variable Date: Tue, 13 Sep 2016 22:24:40 +0200 Message-ID: References: <20160913183514.30625.qmail@mail.muc.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: blaine.gmane.org 1473798333 24589 195.159.176.226 (13 Sep 2016 20:25:33 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 13 Sep 2016 20:25:33 +0000 (UTC) Cc: 24377@debbugs.gnu.org To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Sep 13 22:25:27 2016 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 1bjuGd-00050a-QR for geb-bug-gnu-emacs@m.gmane.org; Tue, 13 Sep 2016 22:25:20 +0200 Original-Received: from localhost ([::1]:51454 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjuGb-0001GS-VS for geb-bug-gnu-emacs@m.gmane.org; Tue, 13 Sep 2016 16:25:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58422) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjuGT-0001Bv-Jp for bug-gnu-emacs@gnu.org; Tue, 13 Sep 2016 16:25:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bjuGQ-0003mc-VZ for bug-gnu-emacs@gnu.org; Tue, 13 Sep 2016 16:25:08 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:32988) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjuGM-0003jV-3I; Tue, 13 Sep 2016 16:25:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bjuGL-0002eY-Vk; Tue, 13 Sep 2016 16:25:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Bastian Beischer Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Tue, 13 Sep 2016 20:25:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 24377 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: Original-Received: via spool by 24377-submit@debbugs.gnu.org id=B24377.147379828910175 (code B ref 24377); Tue, 13 Sep 2016 20:25:01 +0000 Original-Received: (at 24377) by debbugs.gnu.org; 13 Sep 2016 20:24:49 +0000 Original-Received: from localhost ([127.0.0.1]:58933 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bjuG9-0002e2-CV for submit@debbugs.gnu.org; Tue, 13 Sep 2016 16:24:49 -0400 Original-Received: from mail-wm0-f47.google.com ([74.125.82.47]:38047) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bjuG7-0002do-47 for 24377@debbugs.gnu.org; Tue, 13 Sep 2016 16:24:47 -0400 Original-Received: by mail-wm0-f47.google.com with SMTP id 1so222235461wmz.1 for <24377@debbugs.gnu.org>; Tue, 13 Sep 2016 13:24:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=Y42GASiufARZb2VxCz9Mffe7MYa+X21Izr+pfx7VHYw=; b=SfpwSD1QdzKdbxIXk0PwPKJsimpZO74FTha1HJgXmng3gPUcPblgEjuqXSUIwy0x4I 41iYuGFZCb+3YuCWdfFEegrQyBtOKhe0mupDTnZyy4e5HW8nR0FGtsUhmOc4ruielc49 nTIVR3eEdwysesbzZWxLrOZvJo0t1LHpznhXdII4jzOWo+fXGx/nnXH4lv8VFxAYKWc1 GqLQ4QtlWgjnHnR5wTKQG4fIvsU6iIHWjxOZCykBvpNQZsKqOe8OOEwI/Hw15v15kN2/ yD6NOaBbiQzRqk8P+4ZWgWsv/zzA0Po3tT3uPuhGul8pfWp0FF9vxCXaYkTh+hbGFRLd UaHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=Y42GASiufARZb2VxCz9Mffe7MYa+X21Izr+pfx7VHYw=; b=fGBDadqbT4Hb/n2cYdBBR3m16q8yZsWBM08xk8EJ79aUEoPIh1mw2CEeKMBTeeoH7t +IuK4EGdUQ8tDpozqJPyv/RK5+/C2NikIIfesXPGQD+vfOq3ml8lApyK+BhJC3QUDYZ7 IgMsI0Lf4YHMJFX5Oa5axh07RA2iPV8kKZxUpgMmFZVC6ZMHxhR6mFB9vOq9GUnyIWh9 qWMjHyUWBNtPwkK5iR8YTv2J0Du3h4Ldi4ijR4hcfbzVOVACWh9QJOHJp4CwSyvUlMkZ RuI4w91QUQxtpW6ONNpE4Wir6RbWpvz+gPYmK0rerAirfl0Mo8A7EFqZvL5oz9KwcUvG oA8w== X-Gm-Message-State: AE9vXwMbcYgaMpaQPJdqPKvDlS8/h+gGtTMgoby7WvUf7WqWCEvnnc7TyWSde33tDE0QXBgN3mrfGPQ7zUW0Rw== X-Received: by 10.194.103.3 with SMTP id fs3mr22142352wjb.115.1473798281388; Tue, 13 Sep 2016 13:24:41 -0700 (PDT) Original-Received: by 10.28.22.201 with HTTP; Tue, 13 Sep 2016 13:24:40 -0700 (PDT) In-Reply-To: <20160913183514.30625.qmail@mail.muc.de> 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:123271 Archived-At: Hello Alan, First of all, thanks for the patch - it's appreciated. My comments below: Alan Mackenzie writes: > Hello, Bastian. > > In article you wrote: > >> This piece of C++ code is wrongly fontified by CC-Mode: > >> int b = 5; >> int a = (b*3); > >> Reproduce as follows: > >> 1) emacs -Q >> 2) Open file "test.C" >> 3) Paste snippet in buffer >> 4) Place cursor over "b" in second line >> 5) M-x describe-face -> font-lock-type-face > >> This appears to be correlated with the presence of the opening >> parentheses and the '*' character, because: > >> 1) int a = b*3; >> does not have this problem > >> 2) "b" gets fontified incorrectly after entering the '*' character: >> int a = (b* > > Thanks for this bug report, and thanks even more for taking the trouble > to reduce the test case to just two lines. > >> In GNU Emacs 25.1.2 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.30) >> of 2016-08-30 built on beischer-w520 >> Repository revision: 17197d0ae9eac100b56078b2a48964b29710b76e >> Windowing system distributor 'The X.Org Foundation', version 11.0.11804000 >> Configured using: >> 'configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib >> --localstatedir=/var --mandir=/usr/share/man --with-gameuser=:games >> --with-sound=alsa --with-xft --with-modules --with-x-toolkit=gtk2 >> --with-gconf --without-gsettings 'CFLAGS=-march=native -O2 -pipe >> -fstack-protector-strong' CPPFLAGS=-D_FORTIFY_SOURCE=2 >> LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro' > > [ .... ] > > Yes, the CC Mode fontification code was confusing the "*" with an > indirection operator, such as you might get in "int (*b) (....);" > > The solution seems to be to recognise the case where an arithmetic > operator (including "=") precedes the open parenthesis. This is what the > following patch does. Would you please try out this patch on real code, > and let me know whether the problem is completely fixed, and if not, > what's still going wrong. Thanks! > Yes this helps in the example above, but I'm not sure this is a fully correct solution. One can write something like this: void f(int arg) { printf("%d\n", arg) } f(a*5); Another example: int d(a*5) In both cases a is also wrongly fontified (and still is after applying the patch). > After applying the patch, plese recompile all of CC Mode, since the > change is partly in Lisp macros, which need to propagate to other files. > > Here's the patch: > Thanks a lot again! On Tue, Sep 13, 2016 at 8:35 PM, Alan Mackenzie wrote: > Hello, Bastian. > > In article you wrote: > >> This piece of C++ code is wrongly fontified by CC-Mode: > >> int b = 5; >> int a = (b*3); > >> Reproduce as follows: > >> 1) emacs -Q >> 2) Open file "test.C" >> 3) Paste snippet in buffer >> 4) Place cursor over "b" in second line >> 5) M-x describe-face -> font-lock-type-face > >> This appears to be correlated with the presence of the opening >> parentheses and the '*' character, because: > >> 1) int a = b*3; >> does not have this problem > >> 2) "b" gets fontified incorrectly after entering the '*' character: >> int a = (b* > > Thanks for this bug report, and thanks even more for taking the trouble > to reduce the test case to just two lines. > >> In GNU Emacs 25.1.2 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.30) >> of 2016-08-30 built on beischer-w520 >> Repository revision: 17197d0ae9eac100b56078b2a48964b29710b76e >> Windowing system distributor 'The X.Org Foundation', version 11.0.11804000 >> Configured using: >> 'configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib >> --localstatedir=/var --mandir=/usr/share/man --with-gameuser=:games >> --with-sound=alsa --with-xft --with-modules --with-x-toolkit=gtk2 >> --with-gconf --without-gsettings 'CFLAGS=-march=native -O2 -pipe >> -fstack-protector-strong' CPPFLAGS=-D_FORTIFY_SOURCE=2 >> LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro' > > [ .... ] > > Yes, the CC Mode fontification code was confusing the "*" with an > indirection operator, such as you might get in "int (*b) (....);" > > The solution seems to be to recognise the case where an arithmetic > operator (including "=") precedes the open parenthesis. This is what the > following patch does. Would you please try out this patch on real code, > and let me know whether the problem is completely fixed, and if not, > what's still going wrong. Thanks! > > After applying the patch, plese recompile all of CC Mode, since the > change is partly in Lisp macros, which need to propagate to other files. > > Here's the patch: > > > > diff -r 9ff65a2d07bd cc-fonts.el > --- a/cc-fonts.el Sun Sep 11 20:46:35 2016 +0000 > +++ b/cc-fonts.el Tue Sep 13 18:22:17 2016 +0000 > @@ -1310,6 +1310,13 @@ > ;; multiline declaration. > (c-put-char-property (1- match-pos) > 'c-type 'c-decl-arg-start)) > + ;; Got an open paren preceded by an arith operator. > + ((and (eq (char-before match-pos) ?\() > + (save-excursion > + (and (zerop (c-backward-token-2 2)) > + (looking-at c-arithmetic-op-regexp)))) > + (setq context nil > + c-restricted-<>-arglists nil)) > (t (setq context 'arglist > c-restricted-<>-arglists t)))) > > diff -r 9ff65a2d07bd cc-langs.el > --- a/cc-langs.el Sun Sep 11 20:46:35 2016 +0000 > +++ b/cc-langs.el Tue Sep 13 18:22:17 2016 +0000 > @@ -1231,6 +1231,22 @@ > (c-lang-defvar c-assignment-op-regexp > (c-lang-const c-assignment-op-regexp)) > > +(c-lang-defconst c-arithmetic-operators > + "List of all arithmetic operators, including \"+=\", etc." > + ;; Note: in the following, there are too many operators for AWK and IDL. > + t (append (c-lang-const c-assignment-operators) > + '("+" "-" "*" "/" "%" > + "<<" ">>" > + "<" ">" "<=" ">=" > + "==" "!=" > + "&" "^" "|" > + "&&" "||"))) > + > +(c-lang-defconst c-arithmetic-op-regexp > + t (c-make-keywords-re nil > + (c-lang-const c-arithmetic-operators))) > +(c-lang-defvar c-arithmetic-op-regexp (c-lang-const c-arithmetic-op-regexp)) > + > (c-lang-defconst c-:$-multichar-token-regexp > ;; Regexp matching all tokens ending in ":" which are longer than one char. > ;; Currently (2016-01-07) only used in C++ Mode. > > > > -- > Alan Mackenzie (Nuremberg, Germany). > -- Bastian Beischer RWTH Aachen University of Technology @CERN Office: Bdg 32-4-B12 Phone: +41-22-76-75750 E-mail: bastian.beischer@cern.ch Address: CERN, CH-1211 Geneve 23 @RWTH Aachen Office: 28 C 203 Phone: +49-241-80-27205 E-mail: beischer@physik.rwth-aachen.de Address: I. Physikalisches Institut B, Sommerfeldstr. 14, D-52074 Aachen