Skip to content

ambiguous regression #3204

Closed
Closed
@alephzero

Description

@alephzero

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

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions