[llvm-bugs] [Bug 50306] New: [concepts] abbreviated concept syntax triggers ambiguous overload warning

via llvm-bugs llvm-bugs at lists.llvm.org
Tue May 11 15:07:40 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=50306

            Bug ID: 50306
           Summary: [concepts] abbreviated concept syntax triggers
                    ambiguous overload warning
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++2a
          Assignee: unassignedclangbugs at nondot.org
          Reporter: ldalessandro at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

Consider the following code that uses the "overloaded" class template idiom to
provide visit-like functionality, where the overloads are done with concepts.

https://godbolt.org/z/nMfEMfr7r

```
template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;

template <class> concept A = true;
template <class T> concept B = A<T> and true;

template <class T>
auto visit(T t, auto op)
{
    return op(t);
}

template <int M = 0>
int bar(int i) {
    return visit(i, overloaded {
        []<A a>(a&&) { return 0; },
        []<B b>(b&&) { return 1; }
    });
}
int n = bar(0);

#ifdef AMBIGUOUS
template <int M = 0>
#endif
int foo(int i) {
    return visit(i, overloaded {
        [](A auto&&) { return 0; },
        [](B auto&&) { return 1; }
    });
}

int m = foo(0); // error: call to object of type 'overloaded<(lambda at
<source>:27:9), (lambda at <source>:28:9)>' is ambiguous
```

The `bar` function defines the overload lambdas using `<[concept] Foo>` syntax
and works fine, the `foo` version uses abbreviated `[concept] auto` syntax and
reports as ambiguous, but *ONLY* when `foo` is a function template.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210511/1438cddf/attachment.html>


More information about the llvm-bugs mailing list