From unknown Fri Jun 20 18:10:45 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#22486 <22486@debbugs.gnu.org> To: bug#22486 <22486@debbugs.gnu.org> Subject: Status: CC Mode 5.33 (C++/l); Bad indentation in a hideous C++ struct Reply-To: bug#22486 <22486@debbugs.gnu.org> Date: Sat, 21 Jun 2025 01:10:45 +0000 retitle 22486 CC Mode 5.33 (C++/l); Bad indentation in a hideous C++ struct reassign 22486 cc-mode submitter 22486 Michael Welsh Duggan severity 22486 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Thu Jan 28 15:37:09 2016 Received: (at submit) by debbugs.gnu.org; 28 Jan 2016 20:37:09 +0000 Received: from localhost ([127.0.0.1]:40061 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aOtJV-0008IT-8E for submit@debbugs.gnu.org; Thu, 28 Jan 2016 15:37:09 -0500 Received: from md5i.com ([75.151.244.229]:44524) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aOtJU-0008IM-1J for submit@debbugs.gnu.org; Thu, 28 Jan 2016 15:37:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=md5i.com; s=dkim; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID: Date:Subject:To:From; bh=jkQgercpOLZ4GLAee8b4WoGFU1+xve0+U1M9pmDtl7A=; b=c/Ry BChADnOxrDqlg7ZAPcXDZE/0g1RTUQDSOCPh4ls9386hQKdpu+rH1WgelqM2+QN7LAUdUyHO7qyIH 1ElojEZVo24+f/SVfVI8niREiObk0DssvsefrLv1TJZlgmt; Received: from md5i by md5i.com with local (Exim 4.86) (envelope-from ) id 1aOtJT-0002bv-JL for submit@debbugs.gnu.org; Thu, 28 Jan 2016 15:37:07 -0500 From: Michael Welsh Duggan To: submit@debbugs.gnu.org Subject: CC Mode 5.33 (C++/l); Bad indentation in a hideous C++ struct X-Debbugs-Package: cc-mode Date: Thu, 28 Jan 2016 15:37:07 -0500 Message-ID: <87a8npphjg.fsf@md5i.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) In the following C++ snippet: template struct ArgListMatcher : ArgListMatcher::value>, MakeIndices::value, Coun= tRef::value>, Arg, Args...> { using Parent =3D ArgListMatcher< MakeIndices::value>, MakeIndices::value, CountRef::value>, Arg, Args...>; using Parent::ArgListMatcher; }; Starting with "template" as the first line, the lines' contexts are listed as: syntax: ((topmost-intro 1)), indent: 0 syntax: ((topmost-intro-cont 1)), indent: 0 syntax: ((inher-intro 1)), indent: 4 syntax: ((template-args-cont 1 99)), indent: 19 syntax: ((member-init-intro 154)), indent: 23 syntax: ((defun-open 1)), indent: 0 All of these seem reasonable save for member-init-intro, which I expected to be template-args-cont. Emacs : GNU Emacs 25.0.50.3 (x86_64-pc-linux-gnu, X toolkit) of 2016-01-19 Package: CC Mode 5.33 (C++/l) Buffer Style: SiLK c-emacs-features: (pps-extended-state col-0-paren posix-char-classes gen-st= ring-delim gen-comment-delim syntax-properties 1-bit) current state: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D (setq c-basic-offset 4 c-comment-only-line-offset 0 c-indent-comment-alist '((anchored-comment column . 0) (end-block space . = 1) (cpp-end-block space . 2)) c-indent-comments-syntactically-p nil c-block-comment-prefix "* " c-comment-prefix-regexp '((pike-mode . "//+!?\\|\\**") (awk-mode . "#+") (other . "//+\\|\\**")) c-doc-comment-style '((java-mode . javadoc) (pike-mode . autodoc) (c-mode . gtkdoc)) c-cleanup-list '(scope-operator) c-hanging-braces-alist '((brace-list-open) (brace-entry-open) (statement-cont) (substatement-open after) (block-close . c-snug-do-while) (extern-lang-open after) (namespace-open after) (module-open after) (composition-open after) (inexpr-class-open after) (inexpr-class-close before) (arglist-cont-nonempt= y)) c-hanging-colons-alist nil c-hanging-semi&comma-criteria '(c-semi&comma-inside-parenlist) c-backslash-column 48 c-backslash-max-column 72 c-special-indent-hook nil c-label-minimum-indentation 1 c-offsets-alist '((inexpr-class . +) (inexpr-statement . +) (lambda-intro-cont . +) (inlambda . c-lineup-inexpr-block) (template-args-cont c-lineup-template-args +) (incomposition . +) (inmodule . +) (innamespace . 0) (inextern-lang . 0) (composition-close . 0) (module-close . 0) (namespace-close . 0) (extern-lang-close . 0) (composition-open . 0) (module-open . 0) (namespace-open . 0) (extern-lang-open . 0) (objc-method-call-cont c-lineup-ObjC-method-call-colons c-lineup-ObjC-method-call + ) (objc-method-args-cont . c-lineup-ObjC-method-args) (objc-method-intro . [0]) (friend . 0) (cpp-define-intro c-lineup-cpp-define +) (cpp-macro-cont . +) (cpp-macro . [0]) (inclass . +) (stream-op . c-lineup-streamop) (arglist-cont-nonempty c-lineup-gcc-asm-reg c-lineup-arglist ) (arglist-cont c-lineup-gcc-asm-reg 0) (comment-intro c-lineup-knr-region-comment c-lineup-comment ) (catch-clause . 0) (else-clause . 0) (do-while-closure . 0) (access-label . /) (case-label . *) (substatement . +) (statement-case-intro . *) (statement . 0) (brace-entry-open . 0) (brace-list-entry . 0) (brace-list-intro . +) (brace-list-close . 0) (block-close . 0) (block-open . 0) (inher-cont . c-lineup-multi-inher) (inher-intro . +) (member-init-cont . c-lineup-multi-inher) (member-init-intro . +) (annotation-var-cont . +) (annotation-top-cont . 0) (topmost-intro . 0) (knr-argdecl . 0) (func-decl-cont . +) (inline-close . 0) (class-close . 0) (class-open . 0) (defun-block-intro . +) (defun-close . 0) (defun-open . 0) (c . c-lineup-C-comments) (string . c-lineup-dont-change) (topmost-intro-cont . c-lineup-topmost-intro-cont) (brace-list-open . 0) (inline-open . 0) (arglist-close . +) (arglist-intro . +) (statement-cont . c-lineup-math) (statement-case-open . *) (label . *) (substatement-label . 2) (substatement-open . 0) (knr-argdecl-intro . +) (statement-block-intro . +) ) c-buffer-is-cc-mode 'c++-mode c-tab-always-indent t c-syntactic-indentation t c-syntactic-indentation-in-macros t c-ignore-auto-fill '(string cpp code) c-auto-align-backslashes t c-backspace-function 'backward-delete-char-untabify c-delete-function 'delete-char c-electric-pound-behavior nil c-default-style '((java-mode . "java") (awk-mode . "awk") (other . "gnu")) c-enable-xemacs-performance-kludge-p nil c-old-style-variable-behavior nil defun-prompt-regexp nil tab-width 8 comment-column 32 parse-sexp-ignore-comments t parse-sexp-lookup-properties t auto-fill-function nil comment-multi-line t comment-start-skip "\\(//+\\|/\\*+\\)\\s *" fill-prefix nil fill-column 70 paragraph-start "[ ]*\\(//+\\|\\**\\)[ ]*$\\|^\f" adaptive-fill-mode t adaptive-fill-regexp "[ ]*\\(//+\\|\\**\\)[ ]*\\([ ]*\\([-=E2=80=93!|#%= ;>*=C2=B7=E2=80=A2=E2=80=A3=E2=81=83=E2=97=A6]+[ ]*\\)*\\)" ) --=20 Michael Welsh Duggan (md5i@md5i.com) From debbugs-submit-bounces@debbugs.gnu.org Fri Feb 05 12:14:20 2016 Received: (at 22486) by debbugs.gnu.org; 5 Feb 2016 17:14:20 +0000 Received: from localhost ([127.0.0.1]:34612 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aRjxc-0002Hr-1y for submit@debbugs.gnu.org; Fri, 05 Feb 2016 12:14:20 -0500 Received: from mail.muc.de ([193.149.48.3]:46181) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aRjxa-0002Hi-6l for 22486@debbugs.gnu.org; Fri, 05 Feb 2016 12:14:18 -0500 Received: (qmail 96269 invoked by uid 3782); 5 Feb 2016 17:14:17 -0000 Received: from acm.muc.de (p548A4CF8.dip0.t-ipconnect.de [84.138.76.248]) by colin.muc.de (tmda-ofmipd) with ESMTP; Fri, 05 Feb 2016 18:14:16 +0100 Received: (qmail 9576 invoked by uid 1000); 5 Feb 2016 17:16:37 -0000 Date: Fri, 5 Feb 2016 17:16:37 +0000 To: Michael Welsh Duggan Subject: Re: bug#22486: CC Mode 5.33 (C++/l); Bad indentation in a hideous C++ struct Message-ID: <20160205171637.GF7727@acm.fritz.box> References: <87a8npphjg.fsf@md5i.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87a8npphjg.fsf@md5i.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Delivery-Agent: TMDA/1.1.12 (Macallan) From: Alan Mackenzie X-Primary-Address: acm@muc.de X-Spam-Score: -0.3 (/) X-Debbugs-Envelope-To: 22486 Cc: 22486@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.3 (/) Hello, Michael. On Thu, Jan 28, 2016 at 03:37:07PM -0500, Michael Welsh Duggan wrote: > In the following C++ snippet: > template > struct ArgListMatcher : > ArgListMatcher::value>, > MakeIndices::value, CountRef::value>, > Arg, Args...> <============================ > { > using Parent = ArgListMatcher< > MakeIndices::value>, > MakeIndices::value, > CountRef::value>, Arg, Args...>; > using Parent::ArgListMatcher; > }; > Starting with "template" as the first line, the lines' contexts are > listed as: > syntax: ((topmost-intro 1)), indent: 0 > syntax: ((topmost-intro-cont 1)), indent: 0 > syntax: ((inher-intro 1)), indent: 4 > syntax: ((template-args-cont 1 99)), indent: 19 > syntax: ((member-init-intro 154)), indent: 23 <===================== > syntax: ((defun-open 1)), indent: 0 > All of these seem reasonable save for member-init-intro, which I > expected to be template-args-cont. Yes. Also noticeable here is that some of the <...> pairs are not marked with paren syntax by CC Mode. Further analysis shows that these are the pairs with arithmetic operators (- and +) inside them. If the - operator in line 4 is replaced by a comma, then line 5 gets correctly recognised as template-args-cont. (No, I'm not suggesting this as a workaround. :-) CC Mode currently uses the presence of things like + and - and other things which "can't [couldn't] be inside templates" as a heuristic to distingish template delimiters from less-than and greater-than. [On a personal note, it seems like the designers of C++ are lacking taste; they just don't know where to stop. C++'s syntax is ambiguous and highly context dependent. It seems like those designers are determined that only editors attached to a compiler's syntax tree are to be practical for C++.] Would it, perhaps, be feasible to detect the ... operator as an indication that +, -, (?etc.) are permissible inside template delimiters? Is it true that ... only exists inside either a variadic parameter list or template delimiters? [ .... ] > -- > Michael Welsh Duggan > (md5i@md5i.com) -- Alan Mackenzie (Nuremberg, Germany). From debbugs-submit-bounces@debbugs.gnu.org Fri Feb 05 14:02:03 2016 Received: (at 22486) by debbugs.gnu.org; 5 Feb 2016 19:02:03 +0000 Received: from localhost ([127.0.0.1]:34688 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aRldr-00082Y-JF for submit@debbugs.gnu.org; Fri, 05 Feb 2016 14:02:03 -0500 Received: from upton.red.cert.org ([192.88.209.60]:60883) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aRldo-000823-5y for 22486@debbugs.gnu.org; Fri, 05 Feb 2016 14:02:01 -0500 Received: from bucknell.indigo.cert.org (bucknell.indigo.cert.org [10.60.10.121]) by upton.red.cert.org (8.14.4/8.14.4) with ESMTP id u15J1sNu031842; Fri, 5 Feb 2016 14:01:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cert.org; s=jthatj15xw2j; t=1454698914; bh=weSGAz52tG05G0xxLukzs61klMGBSgTHc9s9rXZZ3BA=; h=From:To:Cc:Subject:References:Date:In-Reply-To:Message-ID: MIME-Version:Content-Type:Sender:Reply-To; b=DozauXeFJRiZLoMuB701lvDrkZ8FoLa0caXx9xuFVAorp36CANaoWI6Kf8eGQmu9r XGTJLBZBVVAMk4BsbBi64ld60Qmbsab0CMl4otAjqhw63TqWCgHV8tv7zFxoPKC3i4 0FbvorXDLgqsu1p9PfvmiaRTrognnuJ4PCUdhGYk= Received: from watermonitor.yellow.cert.org (watermonitor.yellow.cert.org [10.20.11.220]) by bucknell.indigo.cert.org (8.14.4/8.14.4/2.81) with ESMTP id u15J1sP6024901; Fri, 5 Feb 2016 14:01:54 -0500 Received: from watermonitor.yellow.cert.org (localhost [127.0.0.1]) by watermonitor.yellow.cert.org (8.14.4/8.14.4) with ESMTP id u15J1rqS022010; Fri, 5 Feb 2016 14:01:53 -0500 Received: (from mwd@localhost) by watermonitor.yellow.cert.org (8.14.4/8.14.4) id u15J1qIp022007; Fri, 5 Feb 2016 14:01:52 -0500 X-Authentication-Warning: watermonitor.yellow.cert.org: mwd set sender to mwd@cert.org using -f From: Michael Welsh Duggan To: Alan Mackenzie Subject: Re: bug#22486: CC Mode 5.33 (C++/l); Bad indentation in a hideous C++ struct References: <87a8npphjg.fsf@md5i.com> <20160205171637.GF7727@acm.fritz.box> Date: Fri, 05 Feb 2016 14:01:52 -0500 In-Reply-To: <20160205171637.GF7727@acm.fritz.box> (Alan Mackenzie's message of "Fri, 5 Feb 2016 17:16:37 +0000") Message-ID: User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/25.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.6 (--) X-Debbugs-Envelope-To: 22486 Cc: 22486@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.6 (--) Alan Mackenzie writes: > Hello, Michael. > > On Thu, Jan 28, 2016 at 03:37:07PM -0500, Michael Welsh Duggan wrote: >> In the following C++ snippet: > >> template >> struct ArgListMatcher : >> ArgListMatcher::value>, >> MakeIndices::value, CountRef::value>, >> Arg, Args...> <============================ >> { >> using Parent = ArgListMatcher< >> MakeIndices::value>, >> MakeIndices::value, >> CountRef::value>, Arg, Args...>; >> using Parent::ArgListMatcher; >> }; > >> Starting with "template" as the first line, the lines' contexts are >> listed as: > >> syntax: ((topmost-intro 1)), indent: 0 >> syntax: ((topmost-intro-cont 1)), indent: 0 >> syntax: ((inher-intro 1)), indent: 4 >> syntax: ((template-args-cont 1 99)), indent: 19 >> syntax: ((member-init-intro 154)), indent: 23 <===================== >> syntax: ((defun-open 1)), indent: 0 > >> All of these seem reasonable save for member-init-intro, which I >> expected to be template-args-cont. > > Also noticeable here is that some of the <...> pairs are not marked with > paren syntax by CC Mode. Further analysis shows that these are the pairs > with arithmetic operators (- and +) inside them. > > If the - operator in line 4 is replaced by a comma, then line 5 gets > correctly recognised as template-args-cont. (No, I'm not suggesting this > as a workaround. :-) Yeah. You're going to see arithmetic operators in template parameter lists a lot more due to the way variadic templates are handled. (They basically are type-matched recursively via partial template specialization.) > CC Mode currently uses the presence of things like + and - and other > things which "can't [couldn't] be inside templates" as a heuristic to > distingish template delimiters from less-than and greater-than. [On a > personal note, it seems like the designers of C++ are lacking taste; they > just don't know where to stop. C++'s syntax is ambiguous and highly > context dependent. It seems like those designers are determined that > only editors attached to a compiler's syntax tree are to be practical for > C++.] No arguments with your parenthetical. Though I expect some of the C++ designers are the types to use vi and manually indent everything to their taste. > Would it, perhaps, be feasible to detect the ... operator as an > indication that +, -, (?etc.) are permissible inside template delimiters? > Is it true that ... only exists inside either a variadic parameter list > or template delimiters? Nope, sorry. Functions can use the ... as well. Here's an example, compilable with g++ -std=c++11: #include int sum() { return 0; } template int sum(int first, T... rest) { return first + sum(rest...); } int sum2() { return 0; } template int sum2(int first, T... rest) { return first + sum2(1 + rest...); } int main() { std::cout << sum(1, 2, 3, 4) << std::endl; /* outputs 10 */ std::cout << sum2(1, 2, 3, 4) << std::endl; /* outputs 16 */ } sum(1, 2, 3, 4) turns into (1 + 2 + 3 + 4 + 0), whereas sum2(1, 2, 3, 4) turns into (1 + 3 + 5 + 7 + 0). This is because of the sum(rest...) and sum2(1 + rest...) expansions. sum(rest...) turns into sum(rest0, rest1, ..., restn) sum(1 + rest...) turns into sum (1 + rest0, 1 + rest1, ..., 1 + restn) -- Michael Welsh Duggan (mwd@cert.org) From debbugs-submit-bounces@debbugs.gnu.org Sun Feb 14 11:53:33 2016 Received: (at 22486) by debbugs.gnu.org; 14 Feb 2016 16:53:33 +0000 Received: from localhost ([127.0.0.1]:38970 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aUzvQ-0000bf-RN for submit@debbugs.gnu.org; Sun, 14 Feb 2016 11:53:33 -0500 Received: from mail.muc.de ([193.149.48.3]:18182) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aUzvP-0000bX-9n for 22486@debbugs.gnu.org; Sun, 14 Feb 2016 11:53:31 -0500 Received: (qmail 48103 invoked by uid 3782); 14 Feb 2016 16:53:29 -0000 Received: from acm.muc.de (p579E9CF1.dip0.t-ipconnect.de [87.158.156.241]) by colin.muc.de (tmda-ofmipd) with ESMTP; Sun, 14 Feb 2016 17:53:28 +0100 Received: (qmail 31270 invoked by uid 1000); 14 Feb 2016 16:55:52 -0000 Date: Sun, 14 Feb 2016 16:55:52 +0000 To: Michael Welsh Duggan Subject: Re: bug#22486: CC Mode 5.33 (C++/l); Bad indentation in a hideous C++ struct Message-ID: <20160214165552.GA10822@acm.fritz.box> References: <87a8npphjg.fsf@md5i.com> <20160205171637.GF7727@acm.fritz.box> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Delivery-Agent: TMDA/1.1.12 (Macallan) From: Alan Mackenzie X-Primary-Address: acm@muc.de X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 22486 Cc: 22486@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) Hello, Michael. On Fri, Feb 05, 2016 at 02:01:52PM -0500, Michael Welsh Duggan wrote: > Alan Mackenzie writes: > > On Thu, Jan 28, 2016 at 03:37:07PM -0500, Michael Welsh Duggan wrote: > >> In the following C++ snippet: > >> template > >> struct ArgListMatcher : > >> ArgListMatcher::value>, > >> MakeIndices::value, CountRef::value>, > >> Arg, Args...> <============================ > >> { > >> using Parent = ArgListMatcher< > >> MakeIndices::value>, > >> MakeIndices::value, > >> CountRef::value>, Arg, Args...>; > >> using Parent::ArgListMatcher; > >> }; > >> Starting with "template" as the first line, the lines' contexts are > >> listed as: > >> syntax: ((topmost-intro 1)), indent: 0 > >> syntax: ((topmost-intro-cont 1)), indent: 0 > >> syntax: ((inher-intro 1)), indent: 4 > >> syntax: ((template-args-cont 1 99)), indent: 19 > >> syntax: ((member-init-intro 154)), indent: 23 <===================== > >> syntax: ((defun-open 1)), indent: 0 > >> All of these seem reasonable save for member-init-intro, which I > >> expected to be template-args-cont. Please see the patch below. Basically, I've had to slacken the criteria for detecting template delimiters, so the danger of mistaking a less-than followed by a greater-than for a template are higher than they were. Come to think of it, the danger probably isn't that high anyway. Would you please do the usual with the patch and let me know how well the problem is solved in real code. Thanks! [ .... ] > Yeah. You're going to see arithmetic operators in template parameter > lists a lot more due to the way variadic templates are handled. (They > basically are type-matched recursively via partial template > specialization.) Maybe C++ compilers are going to mandate the handling of tail recursion. :-) [ .... ] > > Would it, perhaps, be feasible to detect the ... operator as an > > indication that +, -, (?etc.) are permissible inside template delimiters? > > Is it true that ... only exists inside either a variadic parameter list > > or template delimiters? > Nope, sorry. Functions can use the ... as well. Here's an example, > compilable with g++ -std=c++11: > #include > int sum() > { > return 0; > } > template > int sum(int first, T... rest) > { > return first + sum(rest...); > } > int sum2() > { > return 0; > } > template > int sum2(int first, T... rest) > { > return first + sum2(1 + rest...); > } > int main() > { > std::cout << sum(1, 2, 3, 4) << std::endl; /* outputs 10 */ > std::cout << sum2(1, 2, 3, 4) << std::endl; /* outputs 16 */ > } > sum(1, 2, 3, 4) turns into (1 + 2 + 3 + 4 + 0), whereas sum2(1, 2, 3, 4) > turns into (1 + 3 + 5 + 7 + 0). This is because of the sum(rest...) and > sum2(1 + rest...) expansions. > sum(rest...) turns into sum(rest0, rest1, ..., restn) > sum(1 + rest...) turns into sum (1 + rest0, 1 + rest1, ..., 1 + restn) Well it's interesting that C++ can now have functions with a genuinely variable number of arguments, rather than the clumsy mechanism (which C still needs to use) in (or whatever that include file is called). The cost is high, though. Anyhow, here's the patch: diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index a4a1604..d4dcb1c 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el @@ -6056,7 +6056,10 @@ c-forward-<>-arglist-recur ;; Stop on ',', '|', '&', '+' and '-' to catch ;; common binary operators that could be between ;; two comparison expressions "ad". - "[<;{},|+&-]\\|[>)]" + ;; 2016-02-11: C++11 templates can now contain arithmetic + ;; expressions, so template detection in C++ is now less + ;; robust than it was. + c-<>-notable-chars-re nil t t)) (cond @@ -6064,7 +6067,9 @@ c-forward-<>-arglist-recur ;; Either an operator starting with '>' or the end of ;; the angle bracket arglist. - (if (looking-at c->-op-without->-cont-regexp) + (if (save-excursion + (c-backward-token-2) + (looking-at c-multichar->-op-not->>-regexp)) (progn (goto-char (match-end 0)) t) ; Continue the loop. @@ -6134,6 +6139,11 @@ c-forward-<>-arglist-recur ))) t) ; carry on looping. + ((and + (eq (char-before) ?\() + (c-go-up-list-forward) + (eq (char-before) ?\)))) + ((and (not c-restricted-<>-arglists) (or (and (eq (char-before) ?&) (not (eq (char-after) ?&))) diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el index 8a1d43c..9f1dd1d 100644 --- a/lisp/progmodes/cc-langs.el +++ b/lisp/progmodes/cc-langs.el @@ -228,6 +228,12 @@ c-lang-defvar ;; with the group symbol for each group and should return non-nil ;; if that group is to be included. ;; + ;; OP-FILTER selects the operators. It is either t to select all + ;; operators, a string to select all operators for which `string-match' + ;; matches the operator with the string, or a function which will be + ;; called with the operator and should return non-nil when the operator + ;; is to be selected. + ;; ;; If XLATE is given, it's a function which is called for each ;; matching operator and its return value is collected instead. ;; If it returns a list, the elements are spliced directly into @@ -1245,7 +1251,6 @@ 'c-opt-op-identitier-prefix t "\\`<." (lambda (op) (substring op 1))))) - (c-lang-defvar c-<-op-cont-regexp (c-lang-const c-<-op-cont-regexp)) (c-lang-defconst c->-op-cont-tokens @@ -1264,7 +1269,6 @@ 'c-opt-op-identitier-prefix ;; Regexp matching the second and subsequent characters of all ;; multicharacter tokens that begin with ">". t (c-make-keywords-re nil (c-lang-const c->-op-cont-tokens))) - (c-lang-defvar c->-op-cont-regexp (c-lang-const c->-op-cont-regexp)) (c-lang-defconst c->-op-without->-cont-regexp @@ -1279,10 +1283,19 @@ 'c-opt-op-identitier-prefix "\\`>>" (lambda (op) (substring op 1))) :test 'string-equal))) - (c-lang-defvar c->-op-without->-cont-regexp (c-lang-const c->-op-without->-cont-regexp)) +(c-lang-defconst c-multichar->-op-not->>-regexp + ;; Regexp matching multichar tokens containing ">", except ">>" + t (c-make-keywords-re nil + (delete ">>" + (c-filter-ops (c-lang-const c-all-op-syntax-tokens) + t + "\\(.>\\|>.\\)")))) +(c-lang-defvar c-multichar->-op-not->>-regexp + (c-lang-const c-multichar->-op-not->>-regexp)) + (c-lang-defconst c-stmt-delim-chars ;; The characters that should be considered to bound statements. To ;; optimize `c-crosses-statement-barrier-p' somewhat, it's assumed to @@ -3087,6 +3100,19 @@ 'c-opt-op-identitier-prefix ; generics is not yet coded in CC Mode. (c-lang-defvar c-recognize-<>-arglists (c-lang-const c-recognize-<>-arglists)) +(c-lang-defconst c-<>-notable-chars-re + "A regexp matching any single character notable inside a <...> construct. +This must include \"<\" and \">\", \",\", and any character which cannot be +valid inside such a construct. This is used in `c-forward-<>-arglist-recur' to +try to detect sequences of tokens which cannot be a template \(etc.) +construct. When \"(\" is present, that defun will attempt to parse a +parenthesized expression inside the template. When \")\" is present it will +treat an unbalanced closing paren as a sign of the invalidity of the +putative template construct." + t "[<;{},|+&->)]" + c++ "[<;{},>()]") +(c-lang-defvar c-<>-notable-chars-re (c-lang-const c-<>-notable-chars-re)) + (c-lang-defconst c-enums-contain-decls "Non-nil means that an enum structure can contain declarations." t nil > -- > Michael Welsh Duggan > (mwd@cert.org) -- Alan Mackenzie (Nuremberg, Germany). From debbugs-submit-bounces@debbugs.gnu.org Sun Feb 14 15:41:33 2016 Received: (at 22486) by debbugs.gnu.org; 14 Feb 2016 20:41:33 +0000 Received: from localhost ([127.0.0.1]:39099 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aV3U5-0000lR-CH for submit@debbugs.gnu.org; Sun, 14 Feb 2016 15:41:33 -0500 Received: from md5i.com ([75.151.244.229]:58590) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aV3U3-0000lI-Ks for 22486@debbugs.gnu.org; Sun, 14 Feb 2016 15:41:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=md5i.com; s=dkim; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:References: Subject:Cc:To:From; bh=xmLU/uD76EWktmtkHCqEohrOazTH6IQ6w2pgqvBK9B0=; b=r+gYfj Gw/wtIODK5IMj79d9W8sjaQj811xASqJx47qxOdqLy6mkL93HWV3KWroNGNfAOvx/M4U56fzczMvU CE6xMohL+Tj0ReIkcAX2s7kfwVjhhIzkmjj85YeT3VWlh; Received: from md5i by md5i.com with local (Exim 4.86) (envelope-from ) id 1aV3U1-0007SC-38; Sun, 14 Feb 2016 15:41:29 -0500 From: Michael Welsh Duggan To: Alan Mackenzie Subject: Re: bug#22486: CC Mode 5.33 (C++/l); Bad indentation in a hideous C++ struct References: <87a8npphjg.fsf@md5i.com> <20160205171637.GF7727@acm.fritz.box> <20160214165552.GA10822@acm.fritz.box> Date: Sun, 14 Feb 2016 15:41:29 -0500 In-Reply-To: <20160214165552.GA10822@acm.fritz.box> (Alan Mackenzie's message of "Sun, 14 Feb 2016 16:55:52 +0000") Message-ID: <87mvr3dnye.fsf@md5i.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.91 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 22486 Cc: 22486@debbugs.gnu.org, Michael Welsh Duggan X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) Alan Mackenzie writes: > Hello, Michael. > > On Fri, Feb 05, 2016 at 02:01:52PM -0500, Michael Welsh Duggan wrote: >> Alan Mackenzie writes: > >> > On Thu, Jan 28, 2016 at 03:37:07PM -0500, Michael Welsh Duggan wrote: >> >> In the following C++ snippet: > >> >> template >> >> struct ArgListMatcher : >> >> ArgListMatcher::value>, >> >> MakeIndices::value, CountRef::value>, >> >> Arg, Args...> <============================ >> >> { >> >> using Parent = ArgListMatcher< >> >> MakeIndices::value>, >> >> MakeIndices::value, >> >> CountRef::value>, Arg, Args...>; >> >> using Parent::ArgListMatcher; >> >> }; > >> >> Starting with "template" as the first line, the lines' contexts are >> >> listed as: > >> >> syntax: ((topmost-intro 1)), indent: 0 >> >> syntax: ((topmost-intro-cont 1)), indent: 0 >> >> syntax: ((inher-intro 1)), indent: 4 >> >> syntax: ((template-args-cont 1 99)), indent: 19 >> >> syntax: ((member-init-intro 154)), indent: 23 <===================== >> >> syntax: ((defun-open 1)), indent: 0 > >> >> All of these seem reasonable save for member-init-intro, which I >> >> expected to be template-args-cont. > > Please see the patch below. Basically, I've had to slacken the criteria > for detecting template delimiters, so the danger of mistaking a > less-than followed by a greater-than for a template are higher than they > were. Come to think of it, the danger probably isn't that high anyway. > > Would you please do the usual with the patch and let me know how well > the problem is solved in real code. Thanks! Seems to work for me. Thanks! (Have fun with the more recent bug I sent you, #22644. I verified that it still bugs with this patch.) -- Michael Welsh Duggan (md5i@md5i.com) From debbugs-submit-bounces@debbugs.gnu.org Mon Feb 15 08:46:39 2016 Received: (at 22486-done) by debbugs.gnu.org; 15 Feb 2016 13:46:39 +0000 Received: from localhost ([127.0.0.1]:39511 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aVJU7-00067n-Ms for submit@debbugs.gnu.org; Mon, 15 Feb 2016 08:46:39 -0500 Received: from mail.muc.de ([193.149.48.3]:13337) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aVJU6-00067g-Oa for 22486-done@debbugs.gnu.org; Mon, 15 Feb 2016 08:46:39 -0500 Received: (qmail 30794 invoked by uid 3782); 15 Feb 2016 13:46:37 -0000 Received: from acm.muc.de (p5B1462D6.dip0.t-ipconnect.de [91.20.98.214]) by colin.muc.de (tmda-ofmipd) with ESMTP; Mon, 15 Feb 2016 14:46:36 +0100 Received: (qmail 4996 invoked by uid 1000); 15 Feb 2016 13:49:01 -0000 Date: Mon, 15 Feb 2016 13:49:01 +0000 To: 22486-done@debbugs.gnu.org Subject: Re: bug#22486: CC Mode 5.33 (C++/l); Bad indentation in a hideous C++ struct Message-ID: <20160215134901.GA4992@acm.fritz.box> References: <87a8npphjg.fsf@md5i.com> <20160205171637.GF7727@acm.fritz.box> <20160214165552.GA10822@acm.fritz.box> <87mvr3dnye.fsf@md5i.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87mvr3dnye.fsf@md5i.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Delivery-Agent: TMDA/1.1.12 (Macallan) From: Alan Mackenzie X-Primary-Address: acm@muc.de X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 22486-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) Bug fixed in emacs-25 branch. -- Alan Mackenzie (Nuremberg, Germany). From unknown Fri Jun 20 18:10:45 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Tue, 15 Mar 2016 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator