Skip to content

Make Json::Value(std::string) etc... explicit #1137

Open
@aaron-michaux

Description

@aaron-michaux

Describe the bug
As it stands, we cannot write code like:

error_code write(std::ostream& in, const string_view s) noexcept;  // 1
error_code write(std::ostream& in, const Json::Value& o) noexcept;

Because the call to '1' this is ambiguous:

write(in, "foo"s);

The problem is that C++ detects that it can automagically convert "foo"s to either a string_view OR a Json::Value.

It's an annoying reality that explicit isn't the default for constructors. It should be. Be that as it may, Jsoncpp would play nicer if it did use explicit.

To Reproduce
Steps to reproduce the behavior:

  1. See code snippets above.

Expected behavior
A clear and concise description of what you expected to happen.

An error message like:

serialize.cpp:343:12: error: call to 'write' is ambiguous
      ec = write(in, str(o));
           ^~~~~
serialize.cpp:260:12: note: candidate function
error_code write(std::ostream& out, std::string_view x) noexcept
           ^
serialize.cpp:339:12: note: candidate function
error_code write(std::ostream& in, const Json::Value& o) noexcept

Desktop (please complete the following information):

Affects all version compiling under a conformant c++ compiler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Language ConformanceC++11, style, or language warning topics addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions