Skip to content

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

Closed
i-make-robots opened this issue Feb 5, 2019 · 3 comments
Closed

Feature request: warn about unused relational operator #8501

i-make-robots opened this issue Feb 5, 2019 · 3 comments
Labels
Type: Invalid Off topic for this repository, or a bug report determined to not actually represent a bug

Comments

@i-make-robots
Copy link

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.

@matthijskooijman
Copy link
Collaborator

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.

@per1234 per1234 added the Type: Invalid Off topic for this repository, or a bug report determined to not actually represent a bug label Feb 5, 2019
@per1234
Copy link
Collaborator

per1234 commented Feb 5, 2019

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

@per1234 per1234 closed this as completed Feb 5, 2019
@i-make-robots
Copy link
Author

i-make-robots commented Feb 6, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Invalid Off topic for this repository, or a bug report determined to not actually represent a bug
Projects
None yet
Development

No branches or pull requests

3 participants