Bug 106110 - Expected ambiguity but it resolves fine
Summary: Expected ambiguity but it resolves fine
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 12.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2022-06-27 21:13 UTC by Ted Lyngmo
Modified: 2022-07-07 04:42 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ted Lyngmo 2022-06-27 21:13:57 UTC
I made a type trait to test if a call to a function using certain arguments would be ambiguous or not, but in the below example, where I expected that calling the function `foo` with a `std::tuple<single_type>` would result in ambiguity, it is not detected as such.
```
#include <iostream>
#include <tuple>

template <class T>
void foo(const std::tuple<T>&) { std::cout << "T\n"; }

template <class T, class... Ts>
void foo(const std::tuple<T, Ts...>&) { std::cout << "Ts...\n"; }

template <class... Args>
struct is_foo_call_ambiguous {
    static std::true_type test(...);

    template <class... AArgs>
    static auto test(AArgs&&...)
        -> decltype(foo(std::declval<AArgs>()...), std::false_type{});

    static constexpr bool value =
        decltype(test(std::declval<Args>()...))::value;
};

template <class F, class... Args>
static constexpr bool is_foo_call_ambiguous_v =
    is_foo_call_ambiguous<F, Args...>::value;

int main() {
    // expected `true` here, but it reports `false`:
    std::cout << is_foo_call_ambiguous_v<std::tuple<int>> << '\n';
    
    // `false` as expected:
    std::cout << is_foo_call_ambiguous_v<std::tuple<int, int>> << '\n';
}
```
As can be seen here, clang++ reports it to be ambiguous: https://godbolt.org/z/YTevWvbzz

If I understand it correctly, the added tiebreaker (https://cplusplus.github.io/CWG/issues/1395.html) for variadic templates should not apply here.
Comment 1 Ted Lyngmo 2022-06-28 01:22:47 UTC
Sorry, the helper variable template should be:
```
template <class... Args>
static constexpr bool is_foo_call_ambiguous_v =
    is_foo_call_ambiguous<Args...>::value;
```
It gives the same result: https://godbolt.org/z/bKbn8Gre7