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

Fix #140: On enums and scope. #145

Merged
merged 1 commit into from
Jun 4, 2017

Conversation

ciechowoj
Copy link
Contributor

As is the title.

@@ -53,6 +53,10 @@ struct Configuration
@("reduce-aliases", "Reduce primitive type aliases [default].")
bool reduceAliases = true;

/// generate aliases for enum items in global scope
@("alias-enum-items", "Generate aliases for enum items in global scope [default].")
Copy link
Owner

Choose a reason for hiding this comment

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

items -> members.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed.

@@ -216,6 +216,38 @@ D");

}

// Test aliasing of all enum items.
Copy link
Owner

Choose a reason for hiding this comment

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

Here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sigh...
Extended the commit message as well.

@jacob-carlborg
Copy link
Owner

👌.

@jacob-carlborg
Copy link
Owner

Could you please create a PR that updates the changelog with the PRs I just merged. I merged them a bit too quickly 😃.

@ciechowoj
Copy link
Contributor Author

Sure.

@jacob-carlborg jacob-carlborg merged commit 10df6a2 into jacob-carlborg:master Jun 4, 2017
@jacob-carlborg
Copy link
Owner

jacob-carlborg commented Jun 4, 2017

I just noticed that the following code:

struct Foo
{
    enum Bar
    {
        asd
    };
};

Incorrectly translates, with the new --alias-enum-members flag, to:

extern (C):

struct Foo
{
    enum Bar
    {
        asd = 0
    }
}

alias asd = Bar.asd;

The alias should be placed in the parent scope not the global scope.

@jacob-carlborg
Copy link
Owner

jacob-carlborg commented Jun 4, 2017

Here's a better example which gives no warnings:

struct Foo
{
    enum Bar
    {
        asd
    } bar;
};

@ciechowoj
Copy link
Contributor Author

The alias should be placed in the parent scope not the global scope.

No, in C enums are exported to global scope.

e.g.

#include <stdio.h>

struct Foo
{
    enum Bar
    {
        asd = 1
    };
};


int main() {
	printf("%d", asd);
	return 0;
}

This compiles fine and prints 1.

Anyway it should be alias asd = Foo.Bar.asd;

@jacob-carlborg
Copy link
Owner

Ah, I was running the C++ compiler, not the C compiler. My bad.

@ciechowoj ciechowoj deleted the issue140 branch October 4, 2017 21:50
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