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 #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Utkarsh Singh <utkarsh190601 <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 28.0.50; cc-mode: add support for c++ lambda expression
Date: Thu, 04 Feb 2021 21:17:22 +0530
[Message part 1 (text/plain, inline)]
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.

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

((memq where '(at-function-end outwith-function at-header in-header))
    (when (c-syntactic-re-search-forward "{" nil 'eob)
      (backward-char)
      (forward-sexp)

      ;; continue to move sexp if we are looking ) and ,
      (while (looking-at ")\\|,")
	(c-syntactic-re-search-forward "{" nil 'eob)
	(backward-char)
	(forward-sexp))

      (setq n (1- n))))

By this I am trying to move forward lambda's which are separated by ','
or ended with ')'.  I will also attaching the necessary diff to support
the issue.
--
Utkarsh Singh
[cc-cmds.el.diff (text/x-patch, attachment)]
[signature.asc (application/pgp-signature, inline)]

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

Previous Next


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