simple template gets compiler error.

Bryan D. Green bgreen@nas.nasa.gov
Thu Jun 17 13:32:00 GMT 1999


The following template code generates a compiler error.
The error is specific to the use of templates.
The error is specifically caused by the use of 'const', combined with the use 
of a two-dimensional array.

I'm attaching the file 'bugsubmit.ii'.

The source code is as follows:

--BEGIN CODE-------------------------------------------------

template<class T>
inline T Mult(const T *mi[])
{
    return mi[0][0] * mi[1][1] * mi[2][2];
}

template<class T>
class Matrix33t {
public:
    T mat[3][3];

    T mult() const {
        return ::Mult(mat);
    }
};

template class Matrix33t<float>;

--END CODE-------------------------------------------------

The Compiler output:

> g++ bugsubmit.C
bugsubmit.C: In method `float Matrix33t<float>::mult<float>() const':
bugsubmit.C:18:   instantiated from here
bugsubmit.C:14: no matching function for call to `Mult (float[3][3])'

Analysis:

If you remove the 'const' from the argument specification in '::Mult', this
code compiles (though in that case it *should* produce an error).

Also, if you change the array involved from a 2D array to a 1D array, the 
problem goes away.  This bug only shows up when the argument is specifically a 
const 2D array.

System info:

> uname -a
Linux yyz 2.2.4 #4 Thu Mar 25 09:33:32 PST 1999 i686 unknown
> g++ -v
Reading specs from /usr/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)

Thanks,
-bryan




More information about the Gcc-bugs mailing list