seanbaxter / circle

The compiler is available for download. Get it!
http://www.circle-lang.org/
2.42k stars 74 forks source link

can't deduce nested template argument in initializer list #175

Open correaa opened 1 year ago

correaa commented 1 year ago

Circle can't deduce nested template argument in init list:

#include <initializer_list>

template<class T>
struct my_array_2D {
    my_array_1D(std::initializer_list<std::initializer_list<T>>) {}
};

template<class T>
my_array_2D(std::initializer_list<std::initializer_list<T>>) -> my_array_2D<T>;

int main() {

    my_array_2D<double> arr1(                                                    {{1.0, 2.0}, {3.0, 4.0}});
    my_array_2D         arr2(std::initializer_list<std::initializer_list<double>>{{1.0, 2.0}, {3.0, 4.0}});

    // VVV--- circle fails here
    my_array_2D         arr3(                                                    {{1.0, 2.0}, {3.0, 4.0}});
}

https://godbolt.org/z/jc1bs937Y

This is the expected result (with gcc and clang): https://godbolt.org/z/6K4MYKMbx

correaa commented 1 year ago

It happens with function templates (not only with deduction gives) and is specific of init lists:

#include <vector>

template<class T>
void f(std::initializer_list<std::initializer_list<T>>) {}

int main() {
    f({{1.0, 1.0}, {1.0, 1.0}});
}

https://godbolt.org/z/Mndo78cce (works on gcc and clang as far as I can tell)