GNU bug report logs - #14133
24.2; c functions recognition breaks on certain preprocessor macros

Previous Next

Packages: emacs, cc-mode;

Reported by: Gauthier Ostervall <gauthier <at> ostervall.se>

Date: Wed, 3 Apr 2013 17:02:03 UTC

Severity: normal

Found in version 24.2

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

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Gauthier Ostervall <gauthier <at> ostervall.se>
Subject: bug#14133: closed (Re: bug#14133: 24.2; c functions recognition
 breaks on certain preprocessor macros)
Date: Mon, 15 Apr 2013 16:25:02 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#14133: 24.2; c functions recognition breaks on certain preprocessor macros

which was filed against the emacs,cc-mode package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 14133 <at> debbugs.gnu.org.

-- 
14133: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=14133
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Alan Mackenzie <acm <at> muc.de>
To: 14133-done <at> debbugs.gnu.org
Subject: Re: bug#14133: 24.2; c functions recognition breaks on certain
	preprocessor macros
Date: Mon, 15 Apr 2013 16:19:38 +0000
Bug fixed in the trunk.

-- 
Alan Mackenzie (Nuremberg, Germany).

[Message part 3 (message/rfc822, inline)]
From: Gauthier Ostervall <gauthier <at> ostervall.se>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.2; c functions recognition breaks on certain preprocessor macros
Date: Wed, 3 Apr 2013 12:48:37 +0200
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?

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.