GNU bug report logs - #46301
28.0.50; cc-mode: add support for c++ lambda expression

Previous Next

Package: emacs;

Reported by: Utkarsh Singh <utkarsh190601 <at> gmail.com>

Date: Thu, 4 Feb 2021 18:28:02 UTC

Severity: normal

Found in version 28.0.50

Done: Alan Mackenzie <acm <at> muc.de>

Bug is archived. No further changes may be made.

Full log


Message #8 received at 46301 <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: Utkarsh Singh <utkarsh190601 <at> gmail.com>
Cc: 46301 <at> debbugs.gnu.org
Subject: Re: bug#46301: 28.0.50; cc-mode: add support for c++ lambda expression
Date: Tue, 23 Feb 2021 19:19:28 +0000
Hello, Utkarsh.

On Thu, Feb 04, 2021 at 21:17:22 +0530, Utkarsh Singh wrote:
> Hi,

> This bugs only occurs when we assign lambda expression as default
> arguments in C++.  I know there are better ways of using lambda but I
> was just playing with both C++ and Emacs on a hobby project.

> Consider this C++ code:

> template <typename T>
> void bubble_sort(std :: vector<T> &v, bool cmp(T, T)=[](T a, T b){return a < b;})
> {
>     bool swapped = true;
>     for(size_t i = 0; i < v.size() && swapped; i++) {
> 	swapped = false;
> 	for(size_t j = 0; j < v.size()-i; j++){
> 	    if(cmp(v[j+1], v[j])) {
> 		std::swap(v[j], v[j+1]);
> 		swapped=true;
> 	    }
> 	}
>     }
> }

> Here cmp takes a lambda as default argument and if in c++-mode if we try
> using C-M-e(c-end-of-defun) it will get trapped into lambda.

But from the end of that lambda, a further C-M-e takes point to the end
of bubble_sort.

Why do you think this is a bug?  The lambda form is a function, it is at
the top level (i.e. not within braces), so why shouldn't C-M-e stop at
its end?  That's a genuine question, by the way, not a rhetorical one.

If anything, the rather unsystematic behaviour of C-M-a near this lambda
function is of more concern.  And there's the worry that this example
will break other places where it's assumed that braces cannot occur in
parameter lists.

But of all the languages there are, trust C++ to be awkward.  ;-)

> To solve this is added c-forward-to-nth

[ patch received with thanks, but snipped. ]

> --
> Utkarsh Singh

-- 
Alan Mackenzie (Nuremberg, Germany).




This bug report was last modified 4 years and 134 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.