GNU bug report logs -
#14133
24.2; c functions recognition breaks on certain preprocessor macros
Previous Next
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 14133 in the body.
You can then email your comments to 14133 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#14133
; Package
emacs
.
(Wed, 03 Apr 2013 17:02:03 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Gauthier Ostervall <gauthier <at> ostervall.se>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Wed, 03 Apr 2013 17:02:03 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Function coloring, c-beginning-of-defun and c-end-of-defun behaves
strangely if the functions contain ifdef'd code.
For example:
void function_one(void)
{
// Make the number of spaces before # vary.
#if defined(DEBUG)
trap();
#endif // DEBUG
}
void function_two(void)
{
// doing nothing
}
The number of spaces that precede the macros seem to influence the
strange behavior.
At first I thought that the c-*-of-defun functions worked if both
C-macros were aligned, but it is not always the case.
It is quite easy to see if the current state is working or not: the
identifier 'function_two' is not colored correctly when the function
recognition fails.
There seems also to be differences depending on the form of the macro:
#if defined(DEBUG)
#if defined DEBUG
#ifdef DEBUG
The cases showing the fault depend on the previous states, the file
content alone is not enough to guarantee seeing the fault.
Examples of code that causes the fault (only function_one is shown for
readability, see above for function_two):
--- 1 ---
1.a.
// -- OK
void function_one(void)
{
// Make the number of spaces before # vary.
#if defined DEBUG
trap();
#endif // DEBUG
}
1.b. Add one space before #if -> Fail
1.c. Add one more space before #if -> OK
1.d. Delete the space added in 1.c. -> still OK (although same content
as in 1.b.).
--- 2 ---
2.a.
// --- OK
void function_one(void)
{
// Make the number of spaces before # vary.
#if defined DEBUG
trap();
#endif // DEBUG
}
2.b. Add one space before #if -> OK (unlike case 1)
2.c. Add one more space before #if -> Fail
2.d. Delete the space added in 2.c. -> still Fail (although same
content as in 2.b.).
2.e. Remove the last space before #if -> OK
--- 3 ---
3.a.
// --- OK
void function_one(void)
{
// Make the number of spaces before # vary.
#if defined DEBUG
trap();
#endif // DEBUG
}
3.b. Add four spaces before #if -> Fail
3.c. Add one space before #endif -> Fail
3.d. Add one space before #endif -> OK
3.e. Delete one space before #endif -> OK (although same content as 3.c)
As far as I can see, the behavior of #ifdef is the same as that of #if
defined without parens. The behavior of #if defined with parens
differs, though.
IIRC, all preprocessor macros should be considered as blank lines when
it comes to function recognition?
Information forwarded
to
bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org
:
bug#14133
; Package
emacs,cc-mode
.
(Tue, 09 Apr 2013 06:38:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 14133 <at> debbugs.gnu.org (full text, mbox):
On Wed, Apr 3, 2013 at 12:48 PM, Gauthier Ostervall
<gauthier <at> ostervall.se> wrote:
> Function coloring, c-beginning-of-defun and c-end-of-defun behaves
> strangely if the functions contain ifdef'd code.
>
> bug#14133: 24.2;
Faulty behavior also verified on 24.3.1
Working as expected on 23.4.1
All version installed from the zip files at
http://ftp.gnu.org/gnu/emacs/windows/ , on Windows 7.
Information forwarded
to
bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org
:
bug#14133
; Package
emacs,cc-mode
.
(Tue, 09 Apr 2013 21:11:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 14133 <at> debbugs.gnu.org (full text, mbox):
Hi, Gauthier.
> Function coloring, c-beginning-of-defun and c-end-of-defun behaves
> strangely if the functions contain ifdef'd code.
More precisely, doing C-M-a from function_two goes to the beginning of
function_one. I couldn't see any fault with the font locking, though.
> For example:
> void function_one(void)
> {
> // Make the number of spaces before # vary.
> #if defined(DEBUG)
> trap();
> #endif // DEBUG
> }
>
>
> void function_two(void)
> {
> // doing nothing
> }
> The number of spaces that precede the macros seem to influence the
> strange behavior.
Actually, it is the prescence of spaces before the # which are triggering
the bug.
> It is quite easy to see if the current state is working or not: the
> identifier 'function_two' is not colored correctly when the function
> recognition fails.
I didn't see this. Would you please try the patch below and let me know
how much it fixes and how much is still not working. After applying the
patch, you MUST byte-compile cc-langs.el, cc-engine.el and cc-mode.el,
for it to work. (Let me know if you have any trouble doing this.)
Thanks for taking the trouble to report the bug. Here's the patch:
=== modified file 'lisp/progmodes/cc-langs.el'
*** lisp/progmodes/cc-langs.el 2013-03-05 17:13:01 +0000
--- lisp/progmodes/cc-langs.el 2013-04-09 20:36:25 +0000
***************
*** 812,819 ****
(c-lang-defconst c-anchored-cpp-prefix
"Regexp matching the prefix of a cpp directive anchored to BOL,
in the languages that have a macro preprocessor."
! t (if (c-lang-const c-opt-cpp-prefix)
! (concat "^" (c-lang-const c-opt-cpp-prefix))))
(c-lang-defvar c-anchored-cpp-prefix (c-lang-const c-anchored-cpp-prefix))
(c-lang-defconst c-opt-cpp-start
--- 812,819 ----
(c-lang-defconst c-anchored-cpp-prefix
"Regexp matching the prefix of a cpp directive anchored to BOL,
in the languages that have a macro preprocessor."
! t "^\\s *\\(#\\)\\s *"
! (java awk) nil)
(c-lang-defvar c-anchored-cpp-prefix (c-lang-const c-anchored-cpp-prefix))
(c-lang-defconst c-opt-cpp-start
=== modified file 'lisp/progmodes/cc-mode.el'
*** lisp/progmodes/cc-mode.el 2013-01-02 16:13:04 +0000
--- lisp/progmodes/cc-mode.el 2013-04-09 20:39:18 +0000
***************
*** 936,942 ****
;; Add needed properties to each CPP construct in the region.
(goto-char c-new-BEG)
! (let ((pps-position c-new-BEG) pps-state mbeg)
(while (and (< (point) c-new-END)
(search-forward-regexp c-anchored-cpp-prefix c-new-END t))
;; If we've found a "#" inside a string/comment, ignore it.
--- 936,943 ----
;; Add needed properties to each CPP construct in the region.
(goto-char c-new-BEG)
! (skip-chars-backward " \t")
! (let ((pps-position (point)) pps-state mbeg)
(while (and (< (point) c-new-END)
(search-forward-regexp c-anchored-cpp-prefix c-new-END t))
;; If we've found a "#" inside a string/comment, ignore it.
***************
*** 945,958 ****
pps-position (point))
(unless (or (nth 3 pps-state) ; in a string?
(nth 4 pps-state)) ; in a comment?
! (goto-char (match-beginning 0))
(setq mbeg (point))
(if (> (c-syntactic-end-of-macro) mbeg)
(progn
(c-neutralize-CPP-line mbeg (point))
! (c-set-cpp-delimiters mbeg (point))
! ;(setq pps-position (point))
! )
(forward-line)) ; no infinite loop with, e.g., "#//"
)))))
--- 946,957 ----
pps-position (point))
(unless (or (nth 3 pps-state) ; in a string?
(nth 4 pps-state)) ; in a comment?
! (goto-char (match-beginning 1))
(setq mbeg (point))
(if (> (c-syntactic-end-of-macro) mbeg)
(progn
(c-neutralize-CPP-line mbeg (point))
! (c-set-cpp-delimiters mbeg (point)))
(forward-line)) ; no infinite loop with, e.g., "#//"
)))))
--
Alan Mackenzie (Nuremberg, Germany).
Information forwarded
to
bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org
:
bug#14133
; Package
emacs,cc-mode
.
(Wed, 10 Apr 2013 11:54:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 14133 <at> debbugs.gnu.org (full text, mbox):
On Tue, Apr 9, 2013 at 11:06 PM, Alan Mackenzie <acm <at> muc.de> wrote:
> Would you please try the patch below and let me know
> how much it fixes and how much is still not working. After applying the
> patch, you MUST byte-compile cc-langs.el, cc-engine.el and cc-mode.el,
> for it to work. (Let me know if you have any trouble doing this.)
Your patch fixed this issue, thank you! (built in Cygwin)
Now I will need to find out how to build emacs natively for win64 (or
revert to version 23 and wait for your correction to be integrated).
Reply sent
to
Alan Mackenzie <acm <at> muc.de>
:
You have taken responsibility.
(Mon, 15 Apr 2013 16:25:01 GMT)
Full text and
rfc822 format available.
Notification sent
to
Gauthier Ostervall <gauthier <at> ostervall.se>
:
bug acknowledged by developer.
(Mon, 15 Apr 2013 16:25:02 GMT)
Full text and
rfc822 format available.
Message #19 received at 14133-done <at> debbugs.gnu.org (full text, mbox):
Bug fixed in the trunk.
--
Alan Mackenzie (Nuremberg, Germany).
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Tue, 14 May 2013 11:24:03 GMT)
Full text and
rfc822 format available.
This bug report was last modified 12 years and 38 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.