This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

cv-quals/templates change 2.95.2 to 3.0


Date: Wed, 25 Jul 2001 15:14:06 -0400
From: Benoit Hudson <bh@techhouse.brown.edu>
To: gcc-bugs@gnu.org
Subject: cv-quals/templates change 2.95.2 to 3.0
X-Mailer: Mutt 1.0.1us

I have a program analogous to the one appended here.

With 2.95.2, (and various others like VC60 and 2.7.2.2) the program
compiles; with 3.0, it says:
  foo.cpp:21: no matching function for call to `bounds_check(int, int, int**&)'

So it apparently no longer synthesizes
        bounds_check(unsigned, unsigned, int const * const *)
given
        bounds_check(unsigned, unsigned, int * *)

Is this by design?

In any case, any suggestions on the best way to rewrite my template?

Thanks in advance,
        -- Benoît


--------------------------------------------------------------------


#include <assert.h> // assert
#include <stdio.h>  // printf
#include <stdlib.h> // malloc

template <class T>
const T *bounds_check(unsigned i, unsigned sz, T const * const *array) {
    assert(i<sz);
    return array[i];
}

int main() {
    int **arr;
    arr = (int**)malloc(5*sizeof(int*));
    for(unsigned i=0; i<5; ++i) {
        arr[i] = (int*)malloc(6*sizeof(int));
        for(unsigned j=0; j<6; ++j) {
            arr[i][j] = i+j;
        }
    }

    const int *row = bounds_check(2u, 5u, arr);
    printf("row %d = %p {", 2, row);
    for(unsigned j=0; j<6; ++j) {
        printf(" %d", row[j]);
    }
    printf(" }\n");
    return 0;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]