clangd
clangd copied to clipboard
"IWYU pragma: export" not respected when a standard-library function name like "printf" is #defined to be a user-provided function name
In the example project I have a wrapper header file which includes another header file which should be exported. In the other header file there is a define which I use in my main.c file. clangd complains about not using the included header file directly. It would be nice if this could be supported.
main.c:
#include "printf_wrapper.h"
int main(){
printf("Test");
return 0;
}
printf_wrapper.h:
#pragma once
#include "printf.h" // IWYU pragma: export
printf.h:
#pragma once
int printf_(const char* format, ...);
# define printf printf_
printf.c:
#include "printf.h"
int printf_(const char* format, ...){
return 0;
}
Note, if printf is renamed to myprintf and printf_ is renamed to myprintf_, this works as intended.
It's specifically because printf is a known standard-library name, that this doesn't work. (If you hover over the use of printf in main(), you can see it says "provided by <cstdio>", suggesting that clangd hard-codes this name as something that's provided by <cstdio>.)