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

Always disable statement decomposer on C++ "auto" expressions #140

Open
tiagolascasas opened this issue Mar 5, 2024 · 3 comments
Open

Comments

@tiagolascasas
Copy link
Member

If you apply the statement decomposer to C++ auto expressions, e.g., auto start = high_resolution_clock::now();, it will decompose it into auto start; start = high_resolution_clock::now();, which is not valid C++ code. auto always expects an initialization in the same statement in order to infer the type, and this is broken by detaching the declaration from the initialization.

I think it is not reasonable to expect a developer to filter out these expressions before applying the decomposer, and that instead the decomposer should be the one doing the filtering. A more advanced solution would be to keep the decomposition but replace auto by its intended type, although that would require significant effort.

@joaobispo
Copy link
Member

Yes, the decomposer should have a check that skips declarations that are auto.

Also, as suggested, there could be a normalization step that transforms the auto type in the type of the initialization. Tentative code for that transformation could be:

for(const varDecl of Query.search("vardecl")) {
    if(varDecl.type.isAuto) {
        varDecl.type = varDecl.init.type;
    }
}

@joaobispo
Copy link
Member

I'm having problems replicating this issue. When applying the StatementDecomposer to code like auto a = foo(); or auto b = 1 + 3; it remains unchanged, and the pass that might do the change you were referring to, DecomposeVarDeclarations, already handles auto.

It might be an edge case that is slipping through, please provide example code in order to replicate the issue.

@lm-sousa
Copy link
Member

Has this been fixed?

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

No branches or pull requests

3 participants