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

Macro expansion error in C/C++ for _Pragma #731

Open
mcserep opened this issue Apr 9, 2024 · 0 comments
Open

Macro expansion error in C/C++ for _Pragma #731

mcserep opened this issue Apr 9, 2024 · 0 comments
Labels
Kind: Bug ⚠️ Kind: Important 🥇 Level: Intermediate (3) Plugin: C++ Issues related to the parsing and presentation of C++ projects.

Comments

@mcserep
Copy link
Collaborator

mcserep commented Apr 9, 2024

PPMacroCallback::MacroExpands deliberately omits expanding #pragma statements and other preprocessor directives:

// If this is a # at the start of a line, discard it from the token stream.
// We don't want the re-preprocess step to see #defines, #includes or other
// preprocessor directives.
if (tok.is(clang::tok::hash) && tok.isAtStartOfLine())
continue;

However, pragmas can also be defined with the _Pragma operator, see reference:
https://gcc.gnu.org/onlinedocs/cpp/Pragmas.html

C99 introduced the _Pragma operator. This feature addresses a major problem with ‘#pragma’: being a directive, it cannot be produced as the result of macro expansion. _Pragma is an operator, much like sizeof or defined, and can be embedded in a macro.

Consider the following MWE, which will produce multiple errors, as the pragmas will be seemingly re-preprocessed.

#define CF_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin")
#define CF_ASSUME_NONNULL_END   _Pragma("clang assume_nonnull end")

CF_ASSUME_NONNULL_BEGIN  // error: already inside '#pragma clang assume_nonnull'
int bar = 42;
CF_ASSUME_NONNULL_END    // error: not currently inside '#pragma clang assume_nonnull'
@mcserep mcserep added Kind: Bug ⚠️ Kind: Important 🥇 Plugin: C++ Issues related to the parsing and presentation of C++ projects. Level: Intermediate (3) labels Apr 9, 2024
@mcserep mcserep added this to the Release H* milestone Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Kind: Bug ⚠️ Kind: Important 🥇 Level: Intermediate (3) Plugin: C++ Issues related to the parsing and presentation of C++ projects.
Projects
Status: To do
Status: To do
Development

No branches or pull requests

1 participant