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

conditional fields of constexpr literal structs #989

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

youknowone
Copy link
Contributor

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.

@youknowone youknowone changed the title Constexpr conditional field conditional fields of constexpr literal structs Aug 10, 2024
Copy link
Collaborator

@emilio emilio left a 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, ", ");
Copy link
Collaborator

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, "{{ ");
Copy link
Collaborator

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.

@emilio
Copy link
Collaborator

emilio commented Oct 27, 2024

Sorry for the lag getting to this btw :(

@youknowone
Copy link
Contributor Author

@emilio Thank you for the review! I updated the both PRs

@emilio emilio force-pushed the constexpr-conditional-field branch from df9f46e to 62c856f Compare October 28, 2024 15:09
@emilio
Copy link
Collaborator

emilio commented Oct 28, 2024

Could you rebase this please? Thanks!

@youknowone
Copy link
Contributor Author

rebased

@youknowone
Copy link
Contributor Author

@emilio Could you check it again?

@youknowone youknowone marked this pull request as draft November 4, 2024 04:21
@youknowone youknowone marked this pull request as ready for review November 4, 2024 04:45
@youknowone
Copy link
Contributor Author

I updated my local patch to this branch. It worked well for the project.

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.

defines is not applied for impl const
2 participants