Issue 115704
Summary [clang] c++ template specialization dispatched incorrectly when template parameters have object reference as a default parameter
Labels clang
Assignees
Reporter M0x1m
    clang++ compile time template specialization dispatched incorrectly when template has reference to an object as a default parameter

For example:
```c++
#include <type_traits>

template <int...>
struct A;

long _long;

template <int x, int ...xs>
struct A<x, xs...> {
    template <int i, typename T = long&, T _l = _long, typename = void>
    struct get {
        auto operator()() {
            using next = typename A<xs...>::template get<i, T, _l>;
 return next{}();
        }
    };
};

template <int x, int ...xs>
template <int i, typename T, T _l>
struct A<x, xs...>::get<i, T, _l, std::enable_if_t<x == i>> {
    auto operator()() {
        return x;
    }
};

template <>
struct A<> {
 template <int, typename T, T>
    struct get {
        auto operator()() {
            return -1;
        }
 };
};

int main()
{
    using _One_ = typename A<0, 1>::template get<1>;
    if (One{}() != 1) throw -1;
    using Zero = typename A<0, 1>::template get<0>;
    if (Zero{}() != 0) throw -1;
}
```

Code should not throw any exceptions as it doesn't on gcc, but throws on clang

clang version: 18.1.8
gcc version: 14.2.1
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to