clangd icon indicating copy to clipboard operation
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

Open StMartin81 opened this issue 1 year ago • 1 comments

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.

grafik clangd-includes.zip

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;
}


StMartin81 avatar Feb 27 '24 10:02 StMartin81

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>.)

HighCommander4 avatar Feb 28 '24 04:02 HighCommander4