Skip to content

Visual Studio 2017 15.8.5 "conditional expression is constant" warning on Line 1851 in json.hpp #1268

Description

@cugone

There is a warning "conditional expression is constant" issued for VIsual Studio 2017 version 15.8.5 on Line 1851 of the json.hpp single-include header. I have Treat Warnings As Errors turned on as well as the Warning Level set to 4 so this prevents successful compilation. I do not use Clang nor GCC so I do not know if a similar issue shows up and this is just an edge case and can be safely pragma'd out.

(Immediate surrounding code provided for context)

it can be fixed by changing the if-statement to a constexpr-if:
if constexpr (sizeof(typename WideStringType::value_type) == 2) { //...

template<typename WideStringType>
class wide_string_input_adapter : public input_adapter_protocol {
public:
    explicit wide_string_input_adapter(const WideStringType& w) : str(w) {}

    std::char_traits<char>::int_type get_character() noexcept override {
        // check if buffer needs to be filled
        if(utf8_bytes_index == utf8_bytes_filled) {
//Line 1851 WARNING ISSUED Here VV
            if(sizeof(typename WideStringType::value_type) == 2) {
                fill_buffer_utf16();
            } else {
                fill_buffer_utf32();
            }

            assert(utf8_bytes_filled > 0);
            assert(utf8_bytes_index == 0);
        }

        // use buffer
        assert(utf8_bytes_filled > 0);
        assert(utf8_bytes_index < utf8_bytes_filled);
        return utf8_bytes[utf8_bytes_index++];
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions