Skip to content

[BUG] Global variable treated as local variable by initialization safety guarantee rule #59

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

Closed
filipsajdak opened this issue Oct 9, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@filipsajdak
Copy link
Contributor

filipsajdak commented Oct 9, 2022

The initialization safety guarantee informs that the global variable is a local variable and that it needs to be initialized before the local variable in the function.

i : int;

main: () -> int = {
    j : int;
    j = 42;
    i = 12;
}

Compile it with cppfront and we get an error:

cppfront % build/external/cppfront external/tests/global_variable.cpp2
external/tests/global_variable.cpp2...
global_variable.cpp2(5,5): error: local variable i must be initialized before j (local variables must be initialized in the order they are declared)
  ==> program violates initialization safety guarantee - see previous errors

Expected behavior: i is a global variable and (according to the error message) should not be considered in checking the order of initialization of the local variables.

@filipsajdak filipsajdak added the bug Something isn't working label Oct 9, 2022
@filipsajdak filipsajdak changed the title [BUG] Global variable treated as local variable [BUG] Global variable treated as local variable by initialization safety guarantee rule Oct 9, 2022
@hsutter
Copy link
Owner

hsutter commented Dec 18, 2022

Good catch, thanks! Also I should error on that uninitialized non-local object (on line 1 above) and the current commit fixes that too.

stefanofiorentino pushed a commit to stefanofiorentino/cppfront that referenced this issue Dec 20, 2022
Extend declaration parsing to track parent decls/scopes
And require a non-local object to have an initializer
Azmah-Bad pushed a commit to Azmah-Bad/cppfront that referenced this issue Feb 24, 2023
Extend declaration parsing to track parent decls/scopes
And require a non-local object to have an initializer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants