-
Notifications
You must be signed in to change notification settings - Fork 32
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
Move assignments outside of if statement #18
Move assignments outside of if statement #18
Conversation
I have submitted this thread to the gcc-help mailing list. if ((!(a = b))) is the correct way of wrapping this in parentheses to silence the warning as explained in the thread. Also this is not a false positive, the main question at this point is why the warning is only emitted with c++20. |
3b21b85
to
0f686e8
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.
Hi Thomas, thanks for the proposed changes. I think my preference here would actually be a change of style. As these are PandoraInputTypes the = operator is overloaded here (see this link, so the effective logic here is
m_chi2 = chi2;
if (m_chi2.IsInitialized())
...
In this case, I think this approach, here and in the other examples probably serves to both address the issue and add some clarity.
Move assignements outside of the if statments and check for initialization only in if statements
0f686e8
to
90a937d
Compare
Done. |
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.
Changes look good. Thanks.
@tmadlener The proposed changes look good. I will aim to integrate these into a release candidate early in the new year. |
@tmadlener All of the changes (plus some additional admin) have now been merged across all three relevant repositories. |
Thanks a lot :) |
Starting from version 13, gcc starts warning about this construct only if it's negated and when building with
-std=c++20
. No warning is raised with-std=c++17
or when using gcc12 (see mini demonstrator no compiler explorer with gcc12 and gcc13).Explicitly lifting out the result of the assignment into a variable and checking that explicitly gets around this.
I will try to figure out whether the fact, that this works for
if ((a = b))
, but not forif (!(a = b))
is a gcc bug or expected behavior.This is, I think the better way to fix what I attempted in #17