cppclean
cppclean copied to clipboard
False positive when calling a macro from within another macro
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)) \