--- Begin Message ---
Subject: |
27.0.50; lisp/progmodes/cc-engine.el incorrect indentation of C++14 curly-brace initializer list |
Date: |
Wed, 27 Sep 2017 19:49:57 +0200 |
The following C++14 source code, which is also attached as `mwe.cpp',
shows the indentation problem:
--8<------------------------------
#include <vector>
#include <iostream>
static std::vector<std::vector<unsigned>>
fn(std::vector<std::vector<unsigned>> data) {
return {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
};
}
static std::vector<std::vector<unsigned>>
fn(unsigned n, std::vector<std::vector<unsigned>> data) {
return {
{n + 1, n + 2, n + 3},
{n + 4, n + 5, n + 6},
{n + 7, n + 8, n + 9},
};
}
int main() {
/* Expected indentation */
fn({
{1, 2, 3},
{3, 4, 5},
{6, 7, 8},
});
for (const auto &v : fn({
{3, 4, 5},
{6, 7, 8},
{9, 10, 11},
})) {
for (const auto &a : v) {
std::cout << a << '\n';
}
}
/* End: Expected indentation */
/* Problem */
fn(20, {
{1, 2, 3},
{3, 4, 5},
{6, 7, 8},
});
for (const auto &v : fn(20, {
{3, 4, 5},
{6, 7, 8},
{9, 10, 11},
})) {
for (const auto &a : v) {
std::cout << a << '\n';
}
}
/* End: Problem */
}
--8<------------------------------
To fix the problem, I make the following patch:
--8<------------------------------
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 05b391a..077e9c9 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -10387,6 +10387,7 @@ comment at the start of cc-engine.el for more info."
(eq (char-after) ?\())
(setq braceassignp 'c++-noassign))
((looking-at c-pre-id-bracelist-key))
+ ((looking-at ",\\s *"))
((looking-at c-return-key))
((and (looking-at c-symbol-start)
(not (looking-at c-keywords-regexp)))
@@ -10398,6 +10399,7 @@ comment at the start of cc-engine.el for more info."
(and (c-go-up-list-backward nil lim) ; FIXME!!! Check
`lim' 2016-07-12.
(eq (char-after) ?\()))
((looking-at c-pre-id-bracelist-key))
+ ((looking-at ",\\s *"))
((looking-at c-return-key))
(t (setq after-type-id-pos (point))
nil))))
--8<------------------------------
Any better suggestion as to how to fix the problem?
Thanks.
In GNU Emacs 27.0.50 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.18.9)
of 2017-09-27 built on lgw01-amd64-052
Windowing system distributor 'The X.Org Foundation', version 11.0.11804000
System Description: Ubuntu 16.04.3 LTS
Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
Making completion list...
Quit
Configured using:
'configure --build=x86_64-linux-gnu --prefix=/usr
'--includedir=${prefix}/include' '--mandir=${prefix}/share/man'
'--infodir=${prefix}/share/info' --sysconfdir=/etc --localstatedir=/var
--disable-silent-rules '--libdir=${prefix}/lib/x86_64-linux-gnu'
'--libexecdir=${prefix}/lib/x86_64-linux-gnu' --disable-maintainer-mode
--disable-dependency-tracking --prefix=/usr --sharedstatedir=/var/lib
--program-suffix=-snapshot --with-modules=yes --with-x=yes
--with-x-toolkit=gtk3 --with-xwidgets=yes 'CFLAGS=-g -O2
-fstack-protector-strong -Wformat -Werror=format-security'
'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2'
'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro''
Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS NOTIFY
LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS GTK3 X11 MODULES XWIDGETS LIBSYSTEMD LCMS2
Important settings:
value of $LC_MONETARY: en_US.UTF-8
value of $LC_NUMERIC: en_US.UTF-8
value of $LC_TIME: en_US.UTF-8
value of $LANG: en_US.UTF-8
value of $XMODIFIERS: @im=ibus
locale-coding-system: utf-8-unix
Major mode: C++//l
Minor modes in effect:
tooltip-mode: t
global-eldoc-mode: t
electric-indent-mode: t
mouse-wheel-mode: t
tool-bar-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
line-number-mode: t
transient-mark-mode: t
abbrev-mode: t
Load-path shadows:
None found.
Features:
(shadow sort mail-extr emacsbug message subr-x puny seq byte-opt gv
bytecomp byte-compile cconv dired dired-loaddefs format-spec rfc822 mml
mml-sec password-cache epa derived epg epg-config gnus-util rmail
rmail-loaddefs mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util mail-prsvr mail-utils cc-mode cc-fonts easymenu cc-guess
cc-menus cc-cmds cc-styles cc-align cc-engine cc-vars cc-defs
cl-loaddefs cl-lib elec-pair time-date mule-util tooltip eldoc electric
uniquify ediff-hook vc-hooks lisp-float-type mwheel term/x-win x-win
term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode elisp-mode lisp-mode
prog-mode register page menu-bar rfn-eshadow isearch timer select
scroll-bar mouse jit-lock font-lock syntax facemenu font-core
term/tty-colors frame cl-generic cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932
hebrew greek romanian slovak czech european ethiopic indian cyrillic
chinese composite charscript charprop case-table epa-hook jka-cmpr-hook
help simple abbrev obarray minibuffer cl-preloaded nadvice loaddefs
button faces cus-face macroexp files text-properties overlay sha1 md5
base64 format env code-pages mule custom widget hashtable-print-readable
backquote dbusbind inotify lcms2 dynamic-setting system-font-setting
font-render-setting xwidget-internal move-toolbar gtk x-toolkit x
multi-tty make-network-process emacs)
Memory information:
((conses 16 115959 7786)
(symbols 48 22648 1)
(miscs 40 46 140)
(strings 32 34019 980)
(string-bytes 1 1013691)
(vectors 16 17237)
(vector-slots 8 521799 8627)
(floats 8 50 155)
(intervals 56 397 1)
(buffers 992 13)
(heap 1024 40263 1174))
--
Best regards,
Tadeus
mwe.cpp
Description: Text Data
--- End Message ---
--- Begin Message ---
Subject: |
Re: bug#28623: 27.0.50; lisp/progmodes/cc-engine.el incorrect indentation of C++14 curly-brace initializer list |
Date: |
Thu, 9 Nov 2017 18:53:54 +0000 |
User-agent: |
Mutt/1.7.2 (2016-11-26) |
Hello, Tadeus.
On Thu, Nov 09, 2017 at 10:27:55 +0100, Tadeus Prastowo wrote:
> On Wed, Nov 8, 2017 at 8:23 PM, Alan Mackenzie <address@hidden> wrote:
[...]
> > I've corrected c-inside-bracelist-p such that it now uses position l as
> > this limit. I've also taken the opportunity to simplify it quite a bit.
> > This now appears to work.
> > So, thank you for taking the time to test this, and finding this further
> > bug.
> My pleasure. And thank you very much for looking into this last
> problem as well.
I've committed the patch to the canonical places, including the emacs-26
branch at savannah (whence it will find it's way into master), and I'm
closing the bug.
[ .... ]
> And, just out of curiosity, in cc-engine, there is a long function
> with many inline comments in the form of CASE xxx. Why aren't those
> refactored into individual functions? Performance issue?
There are two such functions, c-forward-decl-or-cast-1 and
c-guess-basic-syntax. Both of them have LOTS of local variables which
would have to be passed into smaller individual functions, and sometimes
those functions would have to alter the "more global" version of the
variable.
Doing this would indeed be slower, but probably not very much. I suspect
all the parameter passing would be awkward. But it's worth stating that
my predecessor, Martin Stjernholm, extracted c-guess-continued-construct
from c-guess-basic-syntax, which shows that it is possible.
> --
> Best regards,
> Tadeus
--
Alan Mackenzie (Nuremberg, Germany).
--- End Message ---