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

Implement #elifdef and #elifndef #467

Merged
merged 4 commits into from
Apr 30, 2023
Merged

Implement #elifdef and #elifndef #467

merged 4 commits into from
Apr 30, 2023

Conversation

danielsan901998
Copy link
Contributor

Implement C23 feature #elifdef and #elifndef from #430.
For testing added two new Preproccesor tests #elifdef.c and #elifdefc2x.c to check it is proccessed correctly with the -std=c2x flag
Also changed build.zig to compile with current master branch of zig.

Copy link
Owner

@Vexu Vexu left a comment

Choose a reason for hiding this comment

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

Looks good! And thanks for updating this for the latest master.

}
switch (if_kind.get(if_level)) {
until_else => {
const macro_name = (try pp.expectMacroName(&tokenizer)) orelse continue;
Copy link
Owner

Choose a reason for hiding this comment

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

I think a missing macro name should be considered false similarly to a missing expression with #if.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have tested it with clang and you are right, i have also added a test for checking the missing macro name in the commit ef844b6

Copy link
Contributor Author

@danielsan901998 danielsan901998 Apr 28, 2023

Choose a reason for hiding this comment

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

Clang generate this output:

test/cases/#elifdefc2x_error.c:7:9: error: macro name missing
#elifdef
        ^
# 10 "test/cases/#elifdefc2x_error.c"
inttest/cases/#elifdefc2x_error.c:16:10: error: macro name missing
#elifndef
         ^

# 19 "test/cases/#elifdefc2x_error.c"
int
2 errors generated.

And Gcc genete this:

# 10 "test/cases/#elifdefc2x_error.c"
int
# 19 "test/cases/#elifdefc2x_error.c"
int

I think the behaviour of gcc looks more correct, i'm going to commit to the pull request to reflect this.
With the change now both #elifdef and #elifndef are considered false when the macro name is missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If there are not more issues, I think that with commit e156730 it should be ready to merge.

Copy link
Owner

Choose a reason for hiding this comment

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

It looks like they have the same output with clang missing a newline after the int.

@Vexu Vexu merged commit 8640bb5 into Vexu:master Apr 30, 2023
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.

2 participants