-
Notifications
You must be signed in to change notification settings - Fork 259
[BUG] Missing braces in assignment operator when initialize vector with a list of values #321
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
Comments
I did a dirty fix to that (I don't know yet how to test if the initializer has diff --git a/source/cppfront.cpp b/source/cppfront.cpp
index 816f5be..45c2a60 100644
--- a/source/cppfront.cpp
+++ b/source/cppfront.cpp
@@ -4321,11 +4321,13 @@ public:
}
out_inits = {};
+ auto found_expression_list = initializer.find(',') != initializer.npos;
+
current_functions.back().prolog.statements.push_back(
(*object)->name()->to_string(true) +
- " = " +
+ " = " + (found_expression_list ? "{" : "") +
initializer +
- ";"
+ (found_expression_list ? "}" : "") + ";"
);
}
// (b) ... if this isn't assignment, only need to emit it if it was
@@ -4393,12 +4395,12 @@ public:
if (initializer.empty()) {
initializer = "{}";
}
-
+ auto found_expression_list = initializer.find(',') != initializer.npos;
current_functions.back().prolog.statements.push_back(
(*object)->name()->to_string(true) +
- " = " +
+ " = " + (found_expression_list ? "{" : "") +
initializer +
- ";"
+ (found_expression_list ? "}" : "")+ ";"
);
}
} The dirty fix works. Maybe you know a better way of checking if |
If I've read the source correctly,
Now, the member Hence, perhaps changing the type of the |
After f608b78 (done to fix #312). It broke the scenario described here: #312 (comment)
For the following code:
Cppfront will generate (skipping type declarations, type definitions and function declarations):
The issue is with
element::operator=()
that has the following lines:And will compile with the error (cut only the part that describes the problem):
Changing problematic lines to the following:
Fixes the issue.
The text was updated successfully, but these errors were encountered: