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

Fixed regression on defined() preprocessing #152

Merged
merged 2 commits into from
Jan 18, 2020

Conversation

spookydonut
Copy link
Collaborator

Fixes #96

0a650be changed the preprocessor to always substitute macros for their value if they were defined, as such #if defined(FOO) would cause a lint error if FOO was defined.

There were two different errors with the exact same message, the first would happen if #define FOO because defined() would have no arguments. The second would happen if #define FOO 1 because 1 isn't an ident.

Because of those tangentially related things I discovered in my attempts to fix the bug, I've changed the error messages to be more specific.

@@ -955,6 +955,18 @@ impl<'ctx> Preprocessor<'ctx> {
return Ok(());
}

// special case for inside a defined() call
if let Some(Token::Punct(Punctuation::LParen)) = self.output.back() {
if self.output.len().checked_sub(2).is_some() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the result of this rather than just .is_some() and repeating the calculation below

@SpaceManiac SpaceManiac merged commit bb70113 into SpaceManiac:master Jan 18, 2020
@SpaceManiac SpaceManiac added this to the suite v1.3 milestone Jan 22, 2020
spookydonut added a commit that referenced this pull request Jan 24, 2020
Fixes #96.

0a650be changed the preprocessor to
always substitute macros for their value if they were defined, as such
`#if defined(FOO)` would cause a lint error if `FOO` was defined.

There were two different errors with the exact same message, the first
would happen if `#define FOO` because `defined()` would have no
arguments.  The second would happen if `#define FOO 1` because `1`
isn't an ident.

Because of those tangentially related things I discovered in my
attempts to fix the bug, I've changed the error messages to be more
specific.

(cherry picked from commit bb70113)
@spookydonut spookydonut deleted the fixdefined branch January 26, 2020 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"malformed defined() call" errors for defined([anything defined])
2 participants