diff options
Diffstat (limited to 'test/CXX/drs/dr15xx.cpp')
| -rw-r--r-- | test/CXX/drs/dr15xx.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/test/CXX/drs/dr15xx.cpp b/test/CXX/drs/dr15xx.cpp index d35583ff9f4e..7472be72c2f1 100644 --- a/test/CXX/drs/dr15xx.cpp +++ b/test/CXX/drs/dr15xx.cpp @@ -101,4 +101,75 @@ namespace dr1589 { // dr1589: 3.7 c++11 } } // dr1589 + +namespace dr1591 { //dr1591. Deducing array bound and element type from initializer list + template<class T, int N> int h(T const(&)[N]); + int X = h({1,2,3}); // T deduced to int, N deduced to 3 + + template<class T> int j(T const(&)[3]); + int Y = j({42}); // T deduced to int, array bound not considered + + struct Aggr { int i; int j; }; + template<int N> int k(Aggr const(&)[N]); //expected-note{{not viable}} + int Y0 = k({1,2,3}); //expected-error{{no matching function}} + int Z = k({{1},{2},{3}}); // OK, N deduced to 3 + + template<int M, int N> int m(int const(&)[M][N]); + int X0 = m({{1,2},{3,4}}); // M and N both deduced to 2 + + template<class T, int N> int n(T const(&)[N], T); + int X1 = n({{1},{2},{3}},Aggr()); // OK, T is Aggr, N is 3 + + + namespace check_multi_dim_arrays { + template<class T, int N, int M, int O> int ***f(const T (&a)[N][M][O]); //expected-note{{deduced conflicting values}} + template<class T, int N, int M> int **f(const T (&a)[N][M]); //expected-note{{couldn't infer}} + + template<class T, int N> int *f(const T (&a)[N]); //expected-note{{couldn't infer}} + int ***p3 = f({ { {1,2}, {3, 4} }, { {5,6}, {7, 8} }, { {9,10}, {11, 12} } }); + int ***p33 = f({ { {1,2}, {3, 4} }, { {5,6}, {7, 8} }, { {9,10}, {11, 12, 13} } }); //expected-error{{no matching}} + int **p2 = f({ {1,2,3}, {3, 4, 5} }); + int **p22 = f({ {1,2}, {3, 4} }); + int *p1 = f({1, 2, 3}); + } + namespace check_multi_dim_arrays_rref { + template<class T, int N, int M, int O> int ***f(T (&&a)[N][M][O]); //expected-note{{deduced conflicting values}} + template<class T, int N, int M> int **f(T (&&a)[N][M]); //expected-note{{couldn't infer}} + + template<class T, int N> int *f(T (&&a)[N]); //expected-note{{couldn't infer}} + int ***p3 = f({ { {1,2}, {3, 4} }, { {5,6}, {7, 8} }, { {9,10}, {11, 12} } }); + int ***p33 = f({ { {1,2}, {3, 4} }, { {5,6}, {7, 8} }, { {9,10}, {11, 12, 13} } }); //expected-error{{no matching}} + int **p2 = f({ {1,2,3}, {3, 4, 5} }); + int **p22 = f({ {1,2}, {3, 4} }); + int *p1 = f({1, 2, 3}); + } + + namespace check_arrays_of_init_list { + template<class T, int N> float *f(const std::initializer_list<T> (&)[N]); + template<class T, int N> double *f(const T(&)[N]); + double *p = f({1, 2, 3}); + float *fp = f({{1}, {1, 2}, {1, 2, 3}}); + } + namespace core_reflector_28543 { + + template<class T, int N> int *f(T (&&)[N]); // #1 + template<class T> char *f(std::initializer_list<T> &&); //#2 + template<class T, int N, int M> int **f(T (&&)[N][M]); //#3 expected-note{{candidate}} + template<class T, int N> char **f(std::initializer_list<T> (&&)[N]); //#4 expected-note{{candidate}} + + template<class T> short *f(T (&&)[2]); //#5 + + template<class T> using Arr = T[]; + + char *pc = f({1, 2, 3}); // OK prefer #2 via 13.3.3.2 [over.ics.rank] + char *pc2 = f({1, 2}); // #2 also + int *pi = f(Arr<int>{1, 2, 3}); // OK prefer #1 + + void *pv1 = f({ {1, 2, 3}, {4, 5, 6} }); // expected-error{{ambiguous}} btw 3 & 4 + char **pcc = f({ {1}, {2, 3} }); // OK #4 + + short *ps = f(Arr<int>{1, 2}); // OK #5 + } +} // dr1591 + #endif |
