Skip to content

All enum values not handled in switch cases. ( -Wswitch-enum ) #889

Closed

Description

@shamprasadps

Bug Report

  • What is the issue you have?
    I am having issues while compiling a C++ program using the json.hpp file. I am using the complier options -Wswitch-enum and -Werror. I see that all the enums are not handled in the switch cases, which is why I am seeing some errors while compiling.

  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?
    Include the json.hpp in the header of a c++ program and compile the program using -Wswitch-enum and -Werror options.

  • What is the expected behavior?
    All enums must be handled and there should be no errors while using these compiler options.

  • And what is the actual behavior instead?
    Actual behaviour: It throws the errors like "src/json.hpp:3005:9: error: enumeration value ‘end_array’ not handled in switch [-Werror=switch-enum]"

  • Which compiler and operating system are you using? Is it a supported compiler?
    Im using a Ubuntu OS and using a supported compiler.

  • Did you use a released version of the library or the version from the develop branch?
    Used from 'develop' branch.

  • If you experience a compilation error: can you compile and run the unit tests?
    Not experiencing any issues with the existing compiler options. Errors only when using -Wswitch-enum and -Werror.

Feature Request

  • Describe the feature in as much detail as possible.

  • Include sample usage where appropriate.

Activity

  1. nlohmann commented on Dec 22, 2017

    @nlohmann
    Owner

    Seems to be a duplicate of #555.

  2. shamprasadps commented on Dec 22, 2017

    @shamprasadps
    Author

    Yes . It is a duplicate of this issue. I guess it was rejected because not all enums were handled in switch cases and it still reported some warnings. I have added the enums in the switch cases and a default label too.
    I do agree that the changes made here to handle -Wswitch-enum for gcc , will throw warnings when clang++ is used with -Wcovered-switch-default option.

  3. nlohmann commented on Dec 23, 2017

    @nlohmann
    Owner

    Right - we need to decide whether we want to make Clang or GCC happy, because now we would have

    warning: default label in switch which covers all enumeration values [-Wcovered-switch-default]
    

    all over the place.

  4. nlohmann commented on Dec 28, 2017

    @nlohmann
    Owner

    I do not like the idea add redundancies to the code to make GCC happy while adding a Clang warning at the same time. See #555 for a discussion.

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

    solution: duplicatethe issue is a duplicate; refer to the linked issue instead

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions