Hello,
I’d like to use #pragma push_macro
in an include-guarded precompiled header and then use #pragma pop_macro
in a source file to restore the macro. Example:
TestHeader.h
:
#ifndef TESTHEADER_H
#define TESTHEADER_H
#define TestMacro
#pragma push_macro("TestMacro")
#undef TestMacro
#endif
TestSource.c
:
#include "TestHeader.h"
#pragma pop_macro("TestMacro")
#ifdef TestMacro
#warning TestMacro is defined.
#else
#warning TestMacro is not defined.
#endif
int main(void) {}
Compile (as described in Clang Compiler User’s Manual — Clang 16.0.0git documentation):
clang -x c-header TestHeader.h -o TestHeader.h.pch
clang -include-pch TestHeader.h.pch TestSource.c
I expected the output to be
TestSource.c:6:6: warning: TestMacro is defined. [-W#warnings]
However, the actual output is
TestSource.c:3:9: warning: pragma pop_macro could not pop 'TestMacro', no matching push_macro [-Wignored-pragmas]
TestSource.c:8:6: warning: TestMacro is not defined. [-W#warnings]
Replacing the include guard with #pragma once
results in the same output. Using gcc (gcc TestHeader.h && gcc TestSource.c
), removing the include guard or not using PCH shows the expected output.
Is there a way to make Clang keep the macros pushed by an include-guarded precompiled header so they can be popped by a source file?