-
Notifications
You must be signed in to change notification settings - Fork 314
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
conditional fields of constexpr literal structs #989
base: master
Are you sure you want to change the base?
Conversation
b890eef
to
ddd17f7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do this, just some nits about whitespace, but looks good.
// TODO: Some C++ versions (c++20?) now support designated | ||
// initializers, consider generating them. | ||
write!(out, "/* .{} = */ ", ordered_key); | ||
self.write_literal(out, &lit.value); | ||
if i + 1 != ordered_fields.len() { | ||
write!(out, ", "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds trailing white-space, please remove the space if is_constexpr
?
@@ -911,33 +911,58 @@ impl LanguageBackend for CLikeLanguageBackend<'_> { | |||
fields, | |||
path, | |||
} => { | |||
let allow_constexpr = self.config.constant.allow_constexpr && l.can_be_constexpr(); | |||
let is_constexpr = self.config.language == Language::Cxx | |||
&& (self.config.constant.allow_static_const || allow_constexpr); | |||
if self.config.language == Language::C { | |||
write!(out, "({})", export_name); | |||
} else { | |||
write!(out, "{}", export_name); | |||
} | |||
|
|||
write!(out, "{{ "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, this space needs to be removed.
Sorry for the lag getting to this btw :( |
ddd17f7
to
df9f46e
Compare
@emilio Thank you for the review! I updated the both PRs |
df9f46e
to
62c856f
Compare
Could you rebase this please? Thanks! |
62c856f
to
cea2ef2
Compare
rebased |
@emilio Could you check it again? |
cea2ef2
to
2ed778c
Compare
I updated my local patch to this branch. It worked well for the project. |
Partially fix #955 about constexpr
#988 is included in this PR
Because constexpr and defines require very different approach about this problem, I created another PR for constexpr fix while keeping the other one for define fix.