This is an archive of the discontinued LLVM Phabricator instance.

[Sema] C++11 opaque enums should avoid the "case value not in enumerated type" switch warning
ClosedPublic

Authored by arphaman on Dec 1 2016, 4:00 AM.

Details

Summary

This patch ensures that the switch warning "case value not in enumerated type" isn't shown for opaque enums. We don't know the actual list of values in opaque enums, so that warning is incorrect.

Diff Detail

Repository
rL LLVM

Event Timeline

arphaman updated this revision to Diff 79892.Dec 1 2016, 4:00 AM
arphaman retitled this revision from to [Sema] C++11 opaque enums should avoid the "case value not in enumerated type" switch warning.
arphaman updated this object.
arphaman added reviewers: rsmith, ahatanak.
arphaman set the repository for this revision to rL LLVM.
arphaman added a subscriber: cfe-commits.
ahatanak added inline comments.Dec 1 2016, 10:23 PM
lib/Sema/SemaStmt.cpp
1165 ↗(On Diff #79892)

This function used to call setAllEnumCasesCovered() when parsing a switch statement with an opaque enum condition, but this patch changes the behavior. I couldn't tell whether isAllEnumCasesCovered should return true or false for such switch statements, but was this change intentional?

arphaman added inline comments.Dec 5 2016, 9:49 AM
lib/Sema/SemaStmt.cpp
1165 ↗(On Diff #79892)

You're right, good catch! Originally it wasn't intentional, but I've looked over this change and it seems like the right change to me. We can't know if we actually covered all enum cases when checking an opaque enum because we don't know which cases the enum has (unless we have a switch that covers all the of possible values of the enum's integer type)! It seems that the previous behaviour was incorrect.

ahatanak accepted this revision.Dec 6 2016, 6:55 PM
ahatanak edited edge metadata.

That makes sense. Thanks for the explanation.

This revision is now accepted and ready to land.Dec 6 2016, 6:55 PM
This revision was automatically updated to reflect the committed changes.