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

clang-format changes semantics of code on '#define keyword(x)' #31086

Closed
llvmbot opened this issue Jan 24, 2017 · 2 comments
Closed

clang-format changes semantics of code on '#define keyword(x)' #31086

llvmbot opened this issue Jan 24, 2017 · 2 comments
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior bugzilla Issues migrated from bugzilla clang-format confirmed Verified by a second party good first issue https://github.com/llvm/llvm-project/contribute invalid-code-generation Tool (e.g. clang-format) produced invalid code that no longer compiles

Comments

@llvmbot
Copy link
Member

llvmbot commented Jan 24, 2017

Bugzilla Link 31738
Version 3.8
OS Linux
Reporter LLVM Bugzilla Contributor

Extended Description

For certain keywords, '#define keyword(x)' will erroneously insert an extra space, causing the function-like macro to instead become an object-like macro. This can change the semantics of the compiled code, which should never happen.

$ echo '#define if(x)' | clang-format
#define if (x)

The full list of affected C++ keywords seems to be:

and, and_eq, bitor, case, catch, delete, for, if, new, not_eq, or, or_eq, return, switch, try, while, xor, xor_eq. Additionally, the MSVC-specific __except is affected, and __try is not (but I haven't exhaustively tested all of MSVC's keywords.)

Note that this is not the same as the list of keywords which should be followed by a space when used normally according to the current style, or the list of keywords which are recognised by the preprocessor, or the list of keywords which it's grammatically valid for them to be followed by an open-parenthesis. In particular, note that bitor is affected, but bitand is not.

$ clang-format -version
clang-format version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@mydeveloperday mydeveloperday added bug Indicates an unexpected problem or unintended behavior good first issue https://github.com/llvm/llvm-project/contribute labels Dec 17, 2021
@mydeveloperday
Copy link
Contributor

For the simple case of #define XXX( where XXX is a keyword I think this could be handled,

@mkurdej mkurdej added the invalid-code-generation Tool (e.g. clang-format) produced invalid code that no longer compiles label Jan 31, 2022
@mkurdej mkurdej added the confirmed Verified by a second party label Feb 2, 2022
@mkurdej mkurdej self-assigned this Feb 2, 2022
@mkurdej mkurdej added the awaiting-review Has pending Phabricator review label Feb 2, 2022
@mkurdej
Copy link
Member

mkurdej commented Feb 2, 2022

Revision URI: https://reviews.llvm.org/D118844.

@mkurdej mkurdej closed this as completed in 529aa4b Feb 3, 2022
@github-actions github-actions bot removed the awaiting-review Has pending Phabricator review label Feb 3, 2022
mem-frob pushed a commit to draperlaboratory/hope-llvm-project that referenced this issue Oct 7, 2022
…acro when the name is a keyword.

Fixes llvm/llvm-project#31086.

Before the code:
```
#define if(x)
```

was erroneously formatted to:
```
#define if (x)
```

Reviewed By: HazardyKnusperkeks, owenpan

Differential Revision: https://reviews.llvm.org/D118844
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior bugzilla Issues migrated from bugzilla clang-format confirmed Verified by a second party good first issue https://github.com/llvm/llvm-project/contribute invalid-code-generation Tool (e.g. clang-format) produced invalid code that no longer compiles
Projects
None yet
Development

No branches or pull requests

3 participants