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

From: Gauthier Ostervall <[email-masked]>
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?