Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ambiguous regression #3204

Closed
alephzero opened this issue Dec 21, 2021 · 4 comments · Fixed by #3629
Closed

ambiguous regression #3204

alephzero opened this issue Dec 21, 2021 · 4 comments · Fixed by #3629
Assignees
Labels
kind: bug release item: 🐛 bug fix solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@alephzero
Copy link

alephzero commented Dec 21, 2021

There was a regression between v3.10.3 and v3.10.4, in the compiler's ability to disambiguate std::function containing nlohmann::json.

In compiler explorer:

#include <https://raw.githubusercontent.com/nlohmann/json/v3.10.3/single_include/nlohmann/json.hpp>
#include <functional>
#include <string>

struct Foo {
  Foo() {}
  Foo(std::string) {}
};

struct Bar {
  Bar(std::function<void(Foo)>) {}
  Bar(std::function<void(nlohmann::json)>) {}
};

int main() {
  Bar bar([](Foo) {});
}

Generates

ASM generation compiler returned: 0
Execution build compiler returned: 0
Program returned: 0

Changing the version to v3.10.4:

#include <https://raw.githubusercontent.com/nlohmann/json/v3.10.4/single_include/nlohmann/json.hpp>
#include <functional>
#include <string>

struct Foo {
  Foo() {}
  Foo(std::string) {}
};

struct Bar {
  Bar(std::function<void(Foo)>) {}
  Bar(std::function<void(nlohmann::json)>) {}
};

int main() {
  Bar bar([](Foo) {});
}

Generates

<source>: In function 'int main()':
<source>:16:21: error: call of overloaded 'Bar(main()::<lambda(Foo)>)' is ambiguous
<source>:12:3: note: candidate: 'Bar::Bar(std::function<void(nlohmann::basic_json<>)>)'
<source>:11:3: note: candidate: 'Bar::Bar(std::function<void(Foo)>)'
ASM generation compiler returned: 1
<source>: In function 'int main()':
<source>:16:21: error: call of overloaded 'Bar(main()::<lambda(Foo)>)' is ambiguous
<source>:12:3: note: candidate: 'Bar::Bar(std::function<void(nlohmann::basic_json<>)>)'
<source>:11:3: note: candidate: 'Bar::Bar(std::function<void(Foo)>)'
Execution build compiler returned: 1
@alephzero
Copy link
Author

This is still an issue in v3.10.5

@falbrechtskirchinger
Copy link
Contributor

Like #3384 this one is also caused by 0e694b4.

@falbrechtskirchinger
Copy link
Contributor

@alephzero Unfortunately I don't believe your issue is fixable in the short term. Above mentioned commit enabled the intended behavior of implicit string conversion so your only options are to either turn of implicit conversions (define JSON_USE_IMPLICIT_CONVERSIONS=0) or de-rank an overload in the ambiguous overload set, e.g.:

#include <https://raw.githubusercontent.com/nlohmann/json/develop/single_include/nlohmann/json.hpp>
#include <functional>
#include <string>

struct Foo {
  Foo() {}
  Foo(std::string) {}
};

struct Bar {
  // de-rank overload by making it a template
  template<typename>
  Bar(std::function<void(Foo)>) {}
  Bar(std::function<void(nlohmann::json)>) {}
};

int main() {
  Bar bar([](Foo) {});
}

@nlohmann Thoughts?

@falbrechtskirchinger
Copy link
Contributor

@nlohmann This issue was fixed by #3604.

falbrechtskirchinger added a commit to falbrechtskirchinger/json that referenced this issue Jul 30, 2022
falbrechtskirchinger added a commit to falbrechtskirchinger/json that referenced this issue Jul 30, 2022
falbrechtskirchinger added a commit to falbrechtskirchinger/json that referenced this issue Jul 30, 2022
@nlohmann nlohmann added solution: proposed fix a fix for the issue has been proposed and waits for confirmation release item: 🐛 bug fix labels Jul 30, 2022
@nlohmann nlohmann self-assigned this Jul 30, 2022
@nlohmann nlohmann added this to the Release 3.11.0 milestone Jul 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug release item: 🐛 bug fix solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants