From: Alan Mackenzie <acm@muc.de>
To: John Eivind Helset <jehelset@gmail.com>
Cc: acm@muc.de, 48670@debbugs.gnu.org
Subject: bug#48670: 27.2; cc-mode and constexpr if
Date: Sun, 30 May 2021 16:29:17 +0000 [thread overview]
Message-ID: <YLO9XckkiP/XU7xP@ACM> (raw)
In-Reply-To: <87lf8242gc.fsf@gmail.com>
Hello, John.
On Wed, May 26, 2021 at 05:08:03 +0200, John Eivind Helset wrote:
> cc-mode has problems with constexpr-if-statements whose true-statement
> is not a compound statement.
> >From 'emacs -Q' open a buffer in cc-mode and compare the formatting of:
> void f(){
> if(a == 4)
> return 4;
> else if(a == 3)
> return 3;
> else
> return 2;
> }
> void f_constexpr(){
> if constexpr(a == 4)
> return 4;
> else if constexpr(a == 3)
> return 3;
> else
> return 2;
> }
Thanks for taking the trouble to report this bug, and thanks even more
for creating a minimal, easy to work with, test case.
The bug has in fact already been fixed in the development version of
Emacs, and should be getting released with Emacs 28.1, whenever that
will happen.
In the mean time, please apply the following patch to
..../emacs/lisp/progmodes/cc-engine.el, and then byte compile that file.
Should you want any help with the patching or byte compilation, feel
free to send me private email.
--- cc-engine.el.orig 2021-05-30 16:08:48.855885223 +0000
+++ cc-engine.el 2021-05-30 16:16:47.785903083 +0000
@@ -1181,6 +1181,15 @@
;; suitable error.
(setq pre-stmt-found t)
(throw 'loop nil))
+ ;; Handle C++'s `constexpr', etc.
+ (if (save-excursion
+ (and (looking-at c-block-stmt-hangon-key)
+ (progn
+ (c-backward-syntactic-ws lim)
+ (c-safe (c-backward-sexp) t))
+ (looking-at c-block-stmt-2-key)
+ (setq pos (point))))
+ (goto-char pos))
(cond
;; Have we moved into a macro?
((and (not macro-start)
> In GNU Emacs 27.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.27, cairo version 1.17.4)
> of 2021-03-26 built on juergen
> Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
> System Description: Arch Linux
[ .... ]
> --
> John Eivind Helset
--
Alan Mackenzie (Nuremberg, Germany).
next prev parent reply other threads:[~2021-05-30 16:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-26 3:08 bug#48670: 27.2; cc-mode and constexpr if John Eivind Helset
2021-05-30 16:29 ` Alan Mackenzie [this message]
2021-05-30 16:35 ` Alan Mackenzie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YLO9XckkiP/XU7xP@ACM \
--to=acm@muc.de \
--cc=48670@debbugs.gnu.org \
--cc=jehelset@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).