Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive when calling a macro from within another macro #166

Open
jufajardini opened this issue Aug 11, 2022 · 0 comments
Open

False positive when calling a macro from within another macro #166

jufajardini opened this issue Aug 11, 2022 · 0 comments

Comments

@jufajardini
Copy link

If I have a file with MACRO_B calling MACRO_A - which is defined in header-a.h, cppclean will complain that header-a.h doesn't need to be included:

Three files to reproduce:

  • main.c
#include "macro-a.h"
#include <stdio.h>

int main( )
{
    int result = MY_RESULT(3);
    printf("result is %d\n", result);
    
    return 0;
}
  • macro-b.h
#include "macro-a.h"

#define MY_RESULT(c) {          \
    ( MY_REPLACE_MACRO - (c))   \
}
  • macro-a.h
#define MY_REPLACE_MACRO 345

Program compiles as runs as expected, but running cppclean gives a false positive:

cppclean macro-b.h 
macro-b.h:1: 'macro-a.h' does not need to be #included

Removing the macro-a.h include leads to a compilation error:

main.c:6:18: error: use of undeclared identifier 'MY_REPLACE_MACRO'
    int result = MY_RESULT(3);
                 ^
./macro-b.h:4:7: note: expanded from macro 'MY_RESULT'
    ( MY_REPLACE_MACRO - (c))   \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant