This is an archive of the discontinued LLVM Phabricator instance.

[Diagnostics] Implement -Wswitch-default
AbandonedPublic

Authored by xbolva00 on Jun 12 2019, 3:25 AM.

Details

Summary

For MSVC compatibility, based on request in https://bugs.llvm.org/show_bug.cgi?id=4546.

Diff Detail

Event Timeline

xbolva00 created this revision.Jun 12 2019, 3:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 12 2019, 3:25 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
xbolva00 planned changes to this revision.Jun 12 2019, 3:51 AM

I will work on this after we land https://reviews.llvm.org/D63139.

xbolva00 marked an inline comment as done.Jun 12 2019, 4:03 AM
xbolva00 added inline comments.
lib/Sema/SemaStmt.cpp
869

TODO:

if (!SC) -> switch has no default and case labels (empty body is misleading.. switch(x) x = b)

switch (x) {

// warn_empty_switch_body

}

xbolva00 updated this revision to Diff 208974.Jul 10 2019, 8:55 AM

Rebased, improved.

xbolva00 marked an inline comment as not done.Jul 10 2019, 8:55 AM
xbolva00 added a reviewer: aaron.ballman.

I will work on this after we land https://reviews.llvm.org/D63139.

^ not yet landed, but please @aaron.ballman take a look, this patch is ready for review.

xbolva00 updated this revision to Diff 208984.Jul 10 2019, 9:13 AM

I'm wary of adding this as an on-by-default warning, despite its presence in MSVC (and despite submitting a similar patch years ago to implement the same functionality). Machine-generated code runs into this one frequently (we've been bitten by it numerous times with our tablegen code, especially in the backends), but it does not seem likely to occur in hand-written code very often.

While it's pretty easy to implement this in the frontend, I sort of feel like this is a better candidate for clang-tidy's readability module.

xbolva00 planned changes to this revision.Jul 10 2019, 10:34 AM

I see. I should really check clang-tidy codebase :)

I see. I should really check clang-tidy codebase :)

I have a hunch that this will be equally as trivially implementable in clang-tidy -- if you go that route, feel free to add me as a reviewer!

xbolva00 abandoned this revision.Jul 20 2019, 10:11 AM