From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#62339: cc-mode fontifies variables incorrectly when const follows type Date: Thu, 23 Mar 2023 14:40:23 +0000 Message-ID: References: <878rfqcez5.fsf@dancol.org> <837cva6m1e.fsf@gnu.org> <87y1no6f6d.fsf@dancol.org> <83ttyc6cqz.fsf@gnu.org> <87lejo1ldz.fsf@dancol.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11956"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 62339@debbugs.gnu.org, Eli Zaretskii To: Daniel Colascione Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Mar 23 15:41:26 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pfM85-0002qR-QU for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 23 Mar 2023 15:41:25 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pfM7k-0002e6-PL; Thu, 23 Mar 2023 10:41:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pfM7j-0002dp-BV for bug-gnu-emacs@gnu.org; Thu, 23 Mar 2023 10:41:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pfM7j-0003vL-3K for bug-gnu-emacs@gnu.org; Thu, 23 Mar 2023 10:41:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pfM7i-00012U-HF for bug-gnu-emacs@gnu.org; Thu, 23 Mar 2023 10:41:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 23 Mar 2023 14:41:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62339 X-GNU-PR-Package: emacs Original-Received: via spool by 62339-submit@debbugs.gnu.org id=B62339.16795824333951 (code B ref 62339); Thu, 23 Mar 2023 14:41:02 +0000 Original-Received: (at 62339) by debbugs.gnu.org; 23 Mar 2023 14:40:33 +0000 Original-Received: from localhost ([127.0.0.1]:39080 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pfM7E-00011e-Jw for submit@debbugs.gnu.org; Thu, 23 Mar 2023 10:40:32 -0400 Original-Received: from mx3.muc.de ([193.149.48.5]:43384) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pfM7C-00011S-Ql for 62339@debbugs.gnu.org; Thu, 23 Mar 2023 10:40:31 -0400 Original-Received: (qmail 43620 invoked by uid 3782); 23 Mar 2023 15:40:24 +0100 Original-Received: from acm.muc.de (pd953a85e.dip0.t-ipconnect.de [217.83.168.94]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Thu, 23 Mar 2023 15:40:24 +0100 Original-Received: (qmail 8664 invoked by uid 1000); 23 Mar 2023 14:40:23 -0000 Content-Disposition: inline In-Reply-To: <87lejo1ldz.fsf@dancol.org> X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:258461 Archived-At: Hello, Daniel. On Wed, Mar 22, 2023 at 18:17:05 -0400, Daniel Colascione wrote: > Alan Mackenzie writes: > > Hello, Eli and Daniel. > > Thanks for the bug report! > > On Wed, Mar 22, 2023 at 17:12:52 +0200, Eli Zaretskii wrote: > >> > From: Daniel Colascione > >> > Cc: 62339@debbugs.gnu.org > >> > Date: Wed, 22 Mar 2023 10:19:55 -0400 > >> > This problem reproduces for me on latest master with emacs -Q: > >> > ``` > >> > TEST(Foo, Bar) { > >> > NamedTemporaryDirectory const test_directory; > >> > } > >> > ``` > >> Thanks. What I see with Emacs built from master is that > >> test_directory in the above example gets font-lock-type-face in > >> c++-mode (but not in c-mode). With Emacs built from emacs-29, both > >> modes produce correct fontification. > >> Alan, can you please look into this? > > I think this is caused by a faulty fix of bug #59267, where "typeless" C > > declarations like > > const foo; > > , which are implicit int, were not being recognised. > Can we back out this fix in the meantime? These "typeless" declarations > can't be all that common. It turned out that the bug was caused by a single missing line of code, a (c-forward-syntactic-ws) in c-forward-type, so the fix wasn't too difficult. I've taken the opportunity also to fix some minor other innaccuracies in c-forward-type. Please try the following patch, and either confirm to me that it appears to fix the bug, or say what's still wrong. Thanks! diff -r 300ebf19cd62 cc-engine.el --- a/cc-engine.el Fri Feb 17 08:58:11 2023 +0000 +++ b/cc-engine.el Thu Mar 23 14:34:08 2023 +0000 @@ -9143,7 +9143,7 @@ (c-forward-syntactic-ws)) (let ((start (point)) pos res name-res id-start id-end id-range - post-prefix-pos) + post-prefix-pos prefix-end-pos) ;; Skip leading type modifiers. If any are found we know it's a ;; prefix of a type. @@ -9153,6 +9153,7 @@ (when (looking-at c-no-type-key) (setq res 'no-id))) (goto-char (match-end 1)) + (setq prefix-end-pos (point)) (setq pos (point)) (c-forward-syntactic-ws) (or (eq res 'no-id) @@ -9304,7 +9305,10 @@ (not (looking-at c-type-decl-prefix-key))))) ;; A C specifier followed by an implicit int, e.g. ;; "register count;" - (goto-char id-start) + (goto-char prefix-end-pos) + (setq pos (point)) + (unless stop-at-end + (c-forward-syntactic-ws)) (setq res 'no-id)) (name-res @@ -9312,6 +9316,7 @@ ;; A normal identifier. (goto-char id-end) (setq pos (point)) + (c-forward-syntactic-ws) (if (or res c-promote-possible-types) (progn (when (not (eq c-promote-possible-types 'just-one)) @@ -9319,7 +9324,9 @@ (when (and c-record-type-identifiers id-range) (c-record-type-id id-range)) (unless res - (setq res 'found))) + (setq res 'found)) + (when (eq res 'prefix) + (setq res t))) (setq res (if (c-check-qualified-type id-start) ;; It's an identifier that has been used as ;; a type somewhere else. -- Alan Mackenzie (Nuremberg, Germany).