GNU bug report logs -
#46301
28.0.50; cc-mode: add support for c++ lambda expression
Previous Next
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
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Your bug report
#46301: 28.0.50; cc-mode: add support for c++ lambda expression
which was filed against the emacs package, has been closed.
The explanation is attached below, along with your original report.
If you require more details, please reply to 46301 <at> debbugs.gnu.org.
--
46301: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=46301
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
Hello, Utkarsh.
On Sat, Feb 27, 2021 at 21:17:11 +0530, Utkarsh Singh wrote:
> Alan Mackenzie <acm <at> muc.de> writes:
> > I've spent the last couple of days fixing the handling of C-M-a/e in
> > cc-cmds.el. It took rather more than the four line patch you proposed.
> > ;-) Could I ask you, please, to apply the following patch (which should
> > apply cleanly to the Emacs master branch), byte compile cc-cmds.el, load
> > it into Emacs, and test it for me on your real source code. Then please
> > report back whether the bug is in fact fixed, and if not, what is still
> > wrong. In the event you would like help with the patching or byte
> > compiling, feel free to send me private email.
> Thanks now issue is fixed and code itself looks pretty solid.
Thanks for doing the testing. I've committed the patch to all the
relevant places, and I'm closing the bug with this post.
> Due to my in-experience in Elisp and comprehensive cc-mode library I was
> unable to deep dive into the patch but I have a questions about it:
> Why non-interactive functions of cc-mode doesn't provide doc-string?
Quite a lot of functions, even non-interactive ones, and variables have
a doc string. This means that those functions/variables are available
to modes derived from CC Mode, and their interfaces are fixed. The ones
without doc strings are regarded as "internal" to CC Mode, and their
interfaces can (and do) change at any time. There's a comment to this
effect burried in the first few hundred lines of cc-engine.el.
A few years ago, an alternative convention started being adopted by
Emacs, where a double hypen is used to indicate an "internal" function
or variable.
> --
> Utkarsh Singh
--
Alan Mackenzie (Nuremberg, Germany).
[Message part 3 (message/rfc822, inline)]
[Message part 4 (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 84 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.