@@ -325,6 +325,7 @@ class TestSimplifyTemplate : public TestFixture {
325325 TEST_CASE (templateTypeDeductionArray); // array arguments: only the decayed dimension is a pointer
326326 TEST_CASE (templateTypeDeductionConstPointer); // "const T *": the parameter provides the pointee const
327327 TEST_CASE (templateTypeDeductionFunctionPointer); // pointers to functions and to members are not deduced
328+ TEST_CASE (templateTypeDeductionPointerToArray); // a pointer to an array is not a pointer to a pointer
328329 TEST_CASE (templateTypeDeductionMemberCall); // "obj . f ( x )": lookup in the class of the object, not at the call site
329330
330331 TEST_CASE (simplifyTemplateArgs1);
@@ -7943,6 +7944,39 @@ class TestSimplifyTemplate : public TestFixture {
79437944 ASSERT_EQUALS (" " , errout_str ());
79447945 }
79457946
7947+ void templateTypeDeductionPointerToArray ()
7948+ { // the ValueType of a pointer to an array ("int ( * p ) [ 3 ]") is "int * *", the same
7949+ // as for a pointer to a pointer, and pointer arithmetic decays only the outermost
7950+ // dimension of an array
7951+ const char code[] = " template<class T> void f(T x) {}\n "
7952+ " template<class T> void h(T* x) {}\n "
7953+ " template<class T> void r(T& x) {}\n "
7954+ " struct S { int (*pa)[3]; int* ap[2]; };\n "
7955+ " void test(S s, bool c) {\n "
7956+ " int a[3]; int b[2][3]; int* q[2]; int (*p)[3] = &a;\n "
7957+ " f(p); h(p); r(*p); f(s.pa); f(b + 1); f(p++); f(c ? p : p); f(&*p);\n "
7958+ " f(*p); r((*p)[0]); f(a + 1); h(b[0] + 1); f(q + 1); f(s.ap); f(*(b + 1));\n "
7959+ " }" ;
7960+ // the generic definitions stay because of the calls that are not deduced
7961+ const char exp[] = " void f<int*> ( int * x ) ; void f<int**> ( int * * x ) ; "
7962+ " template < class T > void f ( T x ) { } "
7963+ " void h<int> ( int * x ) ; "
7964+ " template < class T > void h ( T * x ) { } "
7965+ " void r<int> ( int & x ) ; "
7966+ " template < class T > void r ( T & x ) { } "
7967+ " struct S { int ( * pa ) [ 3 ] ; int * ap [ 2 ] ; } ; "
7968+ " void test ( S s , bool c ) { "
7969+ " int a [ 3 ] ; int b [ 2 ] [ 3 ] ; int * q [ 2 ] ; int ( * p ) [ 3 ] = & a ; "
7970+ " f ( p ) ; h ( p ) ; r ( * p ) ; f ( s . pa ) ; f ( b + 1 ) ; f ( p ++ ) ; f ( c ? p : p ) ; f ( & * p ) ; "
7971+ " f<int*> ( * p ) ; r<int> ( ( * p ) [ 0 ] ) ; f<int*> ( a + 1 ) ; h<int> ( b [ 0 ] + 1 ) ; f<int**> ( q + 1 ) ; f<int**> ( s . ap ) ; f<int*> ( * ( b + 1 ) ) ; "
7972+ " } "
7973+ " void r<int> ( int & x ) { } "
7974+ " void h<int> ( int * x ) { } "
7975+ " void f<int*> ( int * x ) { } void f<int**> ( int * * x ) { }" ;
7976+ ASSERT_EQUALS (exp, tok (code));
7977+ ASSERT_EQUALS (" " , errout_str ());
7978+ }
7979+
79467980 void templateTypeDeductionMemberCall ()
79477981 {
79487982 { // a free template with the same name and arity is not what "r . check ( p )" calls
0 commit comments