-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Feature request: warn about unused relational operator #8501
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 think you can enable this one by enabling warnings in the preferences. Would that solve your issue? It might be good to turn these warnings on by default, but I think there's a bug report about that already. |
If you compile the following sketch with File > Preferences > Compiler warnings set to "More" or "All": void setup() {
byte A = 1;
byte B = 2;
A != B;
A == B;
A <= B;
}
void loop() {} You will get the following warnings:
Here's the issue for having the warnings on by default: arduino/arduino-ide#1630 |
Oh, thank you!
…On Tue, Feb 5, 2019 at 3:12 PM per1234 ***@***.***> wrote:
If you compile the following sketch with *File > Preferences > Compiler
warnings* set to "More" or "All":
void setup() {
byte A = 1;
byte B = 2;
A != B;
A == B;
A <= B;
}
void loop() {}
You will get the following warnings:
E:\\arduino\\StatementHasNoEffect\StatementHasNoEffect.ino:4:5: warning: statement has no effect [-Wunused-value]
A != B;
^
E:\\arduino\\StatementHasNoEffect\StatementHasNoEffect.ino:5:5: warning: statement has no effect [-Wunused-value]
A == B;
^
E:\\arduino\\StatementHasNoEffect\StatementHasNoEffect.ino:6:5: warning: statement has no effect [-Wunused-value]
A <= B;
^
Here's the issue for having the warnings on by default: arduino/arduino-ide#1630
<arduino/arduino-ide#1630>
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#8501 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABZYhnW31sZePn7kdRAEq-ejJs18Tfz6ks5vKg_3gaJpZM4akNIX>
.
--
Dan Royer
Owner
------------------------------
1 (604) 916 2281 <16049162281> [email protected]
www.marginallyclever.com <https://www.facebook.com/MarginallyClever/>
<https://www.instagram.com/imakerobots/>
<https://www.youtube.com/channel/UCfbRxqjuOgE2EzRKxcePArw>
<https://twitter.com/MarginallyC> <https://github.com/MarginallyClever/>
|
Problem
Intend to write A=B;
Accidentally write A != B, A==B, A<=B, etc.
Currently no warning is thrown that the value returned from the operation is never used.
IMHO the nastiest off-by-one error I can make.
Fix
Throw a warning.
Could be suppressed for those special people who like to write A && B; instead of if(A) B;
AFAIK Java IDEs like Eclipse already warn about such behavior. Perhaps this fix could be modeled after that one.
Thank you! I really appreciate all that you do for coders everywhere.
The text was updated successfully, but these errors were encountered: