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#45560: 27.1; add-change-log-entry erroneously removes "const" from function name Date: Fri, 1 Jan 2021 16:20:25 +0000 Message-ID: References: <87im8ievo2.fsf@tromey.com> <87ft3mmuim.fsf@gnus.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="24764"; mail-complaints-to="usenet@ciao.gmane.io" Cc: acm@muc.de, 45560@debbugs.gnu.org To: Lars Ingebrigtsen , Tom Tromey Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jan 01 17:21:12 2021 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 1kvNAt-0006If-QB for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 01 Jan 2021 17:21:11 +0100 Original-Received: from localhost ([::1]:52128 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kvNAs-0002Op-ED for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 01 Jan 2021 11:21:10 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36530) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kvNAk-0002Nm-OZ for bug-gnu-emacs@gnu.org; Fri, 01 Jan 2021 11:21:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51281) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kvNAk-0006SA-HD for bug-gnu-emacs@gnu.org; Fri, 01 Jan 2021 11:21:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kvNAk-0006gG-DK for bug-gnu-emacs@gnu.org; Fri, 01 Jan 2021 11:21:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 01 Jan 2021 16:21:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45560 X-GNU-PR-Package: emacs Original-Received: via spool by 45560-submit@debbugs.gnu.org id=B45560.160951803625627 (code B ref 45560); Fri, 01 Jan 2021 16:21:02 +0000 Original-Received: (at 45560) by debbugs.gnu.org; 1 Jan 2021 16:20:36 +0000 Original-Received: from localhost ([127.0.0.1]:34594 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kvNAJ-0006fH-Jg for submit@debbugs.gnu.org; Fri, 01 Jan 2021 11:20:36 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:56558 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1kvNAH-0006f0-18 for 45560@debbugs.gnu.org; Fri, 01 Jan 2021 11:20:34 -0500 Original-Received: (qmail 41631 invoked by uid 3782); 1 Jan 2021 16:20:26 -0000 Original-Received: from acm.muc.de (p4fe15b14.dip0.t-ipconnect.de [79.225.91.20]) by colin.muc.de (tmda-ofmipd) with ESMTP; Fri, 01 Jan 2021 17:20:25 +0100 Original-Received: (qmail 8265 invoked by uid 1000); 1 Jan 2021 16:20:25 -0000 Content-Disposition: inline In-Reply-To: <87ft3mmuim.fsf@gnus.org> 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-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" Xref: news.gmane.io gmane.emacs.bugs:197136 Archived-At: Hello, Lars and Tom On Thu, Dec 31, 2020 at 06:09:21 +0100, Lars Ingebrigtsen wrote: > Tom Tromey writes: > > Put this into a .c file: > > > > void > > const_ref () > > { > > } > > > > Now, put point inside the braces and M-x add-change-log-entry. > > > > For me the resulting ChangeLog looks like: > > > > 2020-12-30 Tom Tromey > > > > * q.c (_ref): > Debugging this, it looks like this is down to > (c-defun-name-1) > returning "_ref" if called in the const_ref function, so I've added Alan > to the CCs. Yes, there was a regular expression recognising "const" where it shouldn't have. It was a regexp with many discordant, conflicting requirements, so I had to "split it in two" to get it working properly. Please try the following patch out, which shouldn't be at all controversial, and let me know whether it fixes everything. Thanks! diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index 7444f0f805..60e85fc085 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el @@ -9021,14 +9021,15 @@ c-forward-declarator (c-forward-noise-clause)) ((and (looking-at c-type-decl-prefix-key) (if (and (c-major-mode-is 'c++-mode) - (match-beginning 3)) + (match-beginning 4)) ; Was 3 - 2021-01-01 ;; If the third submatch matches in C++ then ;; we're looking at an identifier that's a ;; prefix only if it specifies a member pointer. (progn (setq id-start (point)) (c-forward-name) - (if (looking-at "\\(::\\)") + (if (save-match-data + (looking-at "\\(::\\)")) ;; We only check for a trailing "::" and ;; let the "*" that should follow be ;; matched in the next round. @@ -9038,13 +9039,15 @@ c-forward-declarator (setq got-identifier t) nil)) t)) - (if (looking-at c-type-decl-operator-prefix-key) + (if (save-match-data + (looking-at c-type-decl-operator-prefix-key)) (setq decorated t)) (if (eq (char-after) ?\() (progn (setq paren-depth (1+ paren-depth)) (forward-char)) - (goto-char (match-end 1))) + (goto-char (or (match-end 1) + (match-end 2)))) (c-forward-syntactic-ws) t))) @@ -9721,14 +9724,15 @@ c-forward-decl-or-cast-1 (setq after-paren-pos (point)))) (while (and (looking-at c-type-decl-prefix-key) (if (and (c-major-mode-is 'c++-mode) - (match-beginning 3)) + (match-beginning 4)) ;; If the third submatch matches in C++ then ;; we're looking at an identifier that's a ;; prefix only if it specifies a member pointer. (when (progn (setq pos (point)) (setq got-identifier (c-forward-name))) (setq name-start pos) - (if (looking-at "\\(::\\)") + (if (save-match-data + (looking-at "\\(::\\)")) ;; We only check for a trailing "::" and ;; let the "*" that should follow be ;; matched in the next round. @@ -9749,7 +9753,8 @@ c-forward-decl-or-cast-1 (when (save-match-data (looking-at c-type-decl-operator-prefix-key)) (setq got-function-name-prefix t)) - (goto-char (match-end 1))) + (goto-char (or (match-end 1) + (match-end 2)))) (c-forward-syntactic-ws))) (setq got-parens (> paren-depth 0)) diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el index c3cd81e1e8..9577f55e87 100644 --- a/lisp/progmodes/cc-langs.el +++ b/lisp/progmodes/cc-langs.el @@ -3433,41 +3433,47 @@ c-populate-syntax-table t (c-make-bare-char-alt (c-lang-const c-block-prefix-disallowed-chars) t)) (c-lang-defvar c-block-prefix-charset (c-lang-const c-block-prefix-charset)) -(c-lang-defconst c-type-decl-prefix-key - "Regexp matching any declarator operator that might precede the -identifier in a declaration, e.g. the \"*\" in \"char *argv\". This -regexp should match \"(\" if parentheses are valid in declarators. -The end of the first submatch is taken as the end of the operator. -Identifier syntax is in effect when this is matched (see -`c-identifier-syntax-table')." +(c-lang-defconst c-type-decl-prefix-keywords-key + ;; Regexp matching any keyword operator that might precede the identifier in + ;; a declaration, e.g. "const" or nil. It doesn't test there is no "_" + ;; following the keyword. t (if (or (c-lang-const c-type-modifier-kwds) (c-lang-const c-modifier-kwds)) - (concat + (concat (regexp-opt (c--delete-duplicates (append (c-lang-const c-type-modifier-kwds) (c-lang-const c-modifier-kwds)) :test 'string-equal) t) - "\\>") - ;; Default to a regexp that never matches. - regexp-unmatchable) + "\\>"))) + +(c-lang-defconst c-type-decl-prefix-key + "Regexp matching any declarator operator that might precede the +identifier in a declaration, e.g. the \"*\" in \"char *argv\". This +regexp should match \"(\" if parentheses are valid in declarators. +The operator found is either the first submatch (if it is not a +keyword) or the second submatch (if it is)." + t (if (c-lang-const c-type-decl-prefix-keywords-key) + (concat "\\(\\`a\\`\\)\\|" ; 1 - will never match. + (c-lang-const c-type-decl-prefix-keywords-key) ; 2 + "\\([^_]\\|$\\)") ; 3 + regexp-unmatchable) ;; Default to a regexp that never matches. ;; Check that there's no "=" afterwards to avoid matching tokens ;; like "*=". - (c objc) (concat "\\(" + (c objc) (concat "\\(" ; 1 "[*(]" - "\\|" - (c-lang-const c-type-decl-prefix-key) - "\\)" - "\\([^=]\\|$\\)") - c++ (concat "\\(" + "\\)\\|" + (c-lang-const c-type-decl-prefix-keywords-key) ; 2 + "\\([^=_]\\|$\\)") ; 3 + c++ (concat "\\(" ; 1 "&&" "\\|" "\\.\\.\\." "\\|" "[*(&~]" + "\\)\\|\\(" ; 2 + (c-lang-const c-type-decl-prefix-keywords-key) ; 3 "\\|" - (c-lang-const c-type-decl-prefix-key) - "\\|" - (concat "\\(" ; 3 + (concat "\\(" ; 4 ;; If this matches there's special treatment in ;; `c-font-lock-declarators' and ;; `c-font-lock-declarations' that check for a @@ -3475,8 +3481,9 @@ c-populate-syntax-table (c-lang-const c-identifier-start) "\\)") "\\)" - "\\([^=]\\|$\\)") + "\\([^=_]\\|$\\)") ; 5 pike "\\(\\*\\)\\([^=]\\|$\\)") + (c-lang-defvar c-type-decl-prefix-key (c-lang-const c-type-decl-prefix-key) 'dont-doc) > -- > (domestic pets only, the antidote for overdose, milk.) > bloggy blog: http://lars.ingebrigtsen.no -- Alan Mackenzie (Nuremberg, Germany).