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#24377: 25.1; CC-Mode (C++) uses font-lock-type-face for ordinary variable Date: Thu, 29 Dec 2016 15:50:04 +0000 Message-ID: <20161229155004.GC12532@acm.fritz.box> References: <20160913183514.30625.qmail@mail.muc.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1483026693 7988 195.159.176.226 (29 Dec 2016 15:51:33 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 29 Dec 2016 15:51:33 +0000 (UTC) User-Agent: Mutt/1.5.24 (2015-08-30) Cc: 24377-done@debbugs.gnu.org To: Bastian Beischer Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Dec 29 16:51:16 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 1cMcz2-0008BT-9Y for geb-bug-gnu-emacs@m.gmane.org; Thu, 29 Dec 2016 16:51:12 +0100 Original-Received: from localhost ([::1]:36119 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cMcz5-00031g-PA for geb-bug-gnu-emacs@m.gmane.org; Thu, 29 Dec 2016 10:51:15 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47282) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cMcyx-000300-8r for bug-gnu-emacs@gnu.org; Thu, 29 Dec 2016 10:51:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cMcyt-0005yI-9l for bug-gnu-emacs@gnu.org; Thu, 29 Dec 2016 10:51:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:43866) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cMcyt-0005yC-6I; Thu, 29 Dec 2016 10:51:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cMcyt-0005TZ-1z; Thu, 29 Dec 2016 10:51:03 -0500 Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Thu, 29 Dec 2016 15:51:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 24377 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: Mail-Followup-To: 24377@debbugs.gnu.org, acm@muc.de, bastian.beischer@gmail.com Original-Received: via spool by 24377-done@debbugs.gnu.org id=D24377.148302662820961 (code D ref 24377); Thu, 29 Dec 2016 15:51:02 +0000 Original-Received: (at 24377-done) by debbugs.gnu.org; 29 Dec 2016 15:50:28 +0000 Original-Received: from localhost ([127.0.0.1]:59264 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cMcyJ-0005S0-Vi for submit@debbugs.gnu.org; Thu, 29 Dec 2016 10:50:28 -0500 Original-Received: from ocolin.muc.de ([193.149.48.4]:22543 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1cMcyH-0005Rl-LZ for 24377-done@debbugs.gnu.org; Thu, 29 Dec 2016 10:50:26 -0500 Original-Received: (qmail 75054 invoked by uid 3782); 29 Dec 2016 15:50:24 -0000 Original-Received: from acm.muc.de (p548C6C46.dip0.t-ipconnect.de [84.140.108.70]) by colin.muc.de (tmda-ofmipd) with ESMTP; Thu, 29 Dec 2016 16:50:24 +0100 Original-Received: (qmail 16546 invoked by uid 1000); 29 Dec 2016 15:50:04 -0000 Content-Disposition: inline In-Reply-To: X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@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:127550 Archived-At: Hello, Bastian. On Tue, Sep 13, 2016 at 10:24:40PM +0200, Bastian Beischer wrote: > Hello Alan, > First of all, thanks for the patch - it's appreciated. My comments > below: > Alan Mackenzie writes: > > 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). Sorry, but in the end I wasn't able to fix this problem. There is now just too much ambiguity in C++'s syntax. The "int d(a*5)" is a sort of special case variant of "int d(a*b)". This could either be a declaration of d which is initialised to a*b, or the declaration of a function d taking one parameter b whose type is a pointer to a. C++ Mode, being an almost purely syntactic editor has no way to resolve these ambiguities. It seems not really worthwhile to handle the special case of a literal integer following the "*". So I have left that construct being fontified as the function declaration, which is probably the more common case. So, I have committed the patch as it was when I last sent it to you for review in September, and I am closing this bug. Sorry, again. > Thanks a lot again! > -- > Bastian Beischer > RWTH Aachen University of Technology -- Alan Mackenzie (Nuremberg, Germany).