Skip to content

Switch warnings no longer work #2572

Closed

Description

@kripken

See discussion in #2451 (comment)

IIUC the issue is that we cast those class instances to an int, and the warnings don't work for ints.

Maybe there's another way? Or, if we don't want these warnings anymore, perhaps we can remove unnecessary cases from switches?

Activity

  1. tlively commented on Jan 7, 2020

    @tlively
    Member

    This is an issue both before and after #2434, but that PR brings it closer to being fixed.

    The compiler feature that warns about non-exhaustive switches on enums only works when the type being switched on is that enum. But since #2459, switching on types has worked because the following automatic conversion is defined for Type:

    // Allows for using Types in switch statements
    constexpr operator uint32_t() const { return id; }
    

    So the type actually being switched on is uint32_t. I just did a little experiment locally and it looks like switching the conversion operator to return ValueType rather than uint32_t in conjunction with #2434 will solve this problem. The question is then what to do about multivalue types, which don't correspond to any ValueType. I suppose the most robust thing to do would be to assert that the value is not a multivalue in the conversion operator. Multivalue types can't participate in switches anyway because their IDs are not constexpr.

  2. added 2 commits that reference this issue on Jan 7, 2020
    03000c2
    376673b
  3. added a commit that references this issue on Jan 8, 2020
  4. added a commit that references this issue on Jan 9, 2020
    7732943
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions