This is an archive of the discontinued LLVM Phabricator instance.

Fix a false positive in misplaced-widening-cast
ClosedPublic

Authored by dkrupp on Dec 4 2018, 12:40 AM.

Details

Summary

bugprone-misplaced-widening-cast check
used to give a false warning to the
following example.

enum DaysEnum{

MON = 0,
TUE = 1
};

day = (DaysEnum)(day + 1);
//warning: either cast from 'int' to 'DaysEnum' is ineffective...

But i think int to enum cast is not widening neither ineffective.

Diff Detail

Repository
rL LLVM

Event Timeline

dkrupp created this revision.Dec 4 2018, 12:40 AM
alexfh accepted this revision.Dec 4 2018, 3:27 AM

LG in general, but a few comments re: test.

test/clang-tidy/bugprone-misplaced-widening-cast-explicit-only.cpp
67–73 ↗(On Diff #176557)

No need for initializers here. Please clang-format the new code.

76 ↗(On Diff #176557)

Please use proper capitalization and punctuation in comments. And put a space between // and the text.

77–88 ↗(On Diff #176557)

Let's make the code a bit shorter and remove unnecessary details. For example, like this:

void f(DaysEnum day){
  if (day < SUN)
      day = (DaysEnum)(day + 1);
  if (day < SUN)
      day = static_cast<DaysEnum>(day + 1);
}
This revision is now accepted and ready to land.Dec 4 2018, 3:27 AM
dkrupp updated this revision to Diff 176604.Dec 4 2018, 4:46 AM

Comments addressed. Please commit if looks good, I don't have commit rights.
Thanks.

dkrupp marked 2 inline comments as done.Dec 4 2018, 4:46 AM
This revision was automatically updated to reflect the committed changes.

Committed, Thank you for the patch! Was there a bug-report for this issue? If yes can you please close it/reference?

Committed, Thank you for the patch! Was there a bug-report for this issue? If yes can you please close it/reference?

There was not bug report for this. Thanks for committing!