[Bug c++/15271] use of nested template classes generates internal error

pinskia at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Mon May 3 20:51:00 GMT 2004


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-05-03 20:51 -------
In the 3.4.0 released version I get a good error message:
pr15271.cc: In function `BGvec_base<Dimension, coeff_t> operator*(k_t, const 
BGvec_base<Dimension, coeff_t>&)':
pr15271.cc:25: error: expected primary-expression before '>' token
pr15271.cc: In function `BGvec_base<Dimension, coeff_t> operator*(k_t, const 
BGvec_base<Dimension, coeff_t>&) [with k_t = double, int Dimension = 2, coeff_t = double]':
pr15271.cc:31:   instantiated from here
pr15271.cc:25: error: dependent-name `BGvec_base<Dimension, coeff_t>::Ktimes' is parsed as a non-
type, but instantiation yields a type
pr15271.cc:25: note: say `typename BGvec_base<Dimension, coeff_t>::Ktimes' if a type is meant

And Here is the fixed up code which works from 2.95.3 to the mainline:
template<int Dimension, typename coeff_t=double>
class BGvec_base{
        public:
        //default constructor, default copy constructor, default assignment
        double& operator[](int i){ return v[i]; }
        const double& operator[](int i) const { return v[i]; }

        template<typename k_t>
        class Ktimes : public BGvec_base{
                public:
                Ktimes( k_t k, const BGvec_base& A ){
                        for(int i=0; i<Dimension; ++i) v[i] = k*A[i];
                }
        };


        protected:
        coeff_t v[Dimension];
};

template<typename k_t, int Dimension, typename coeff_t>
BGvec_base<Dimension, coeff_t> operator*
                        ( k_t k, const BGvec_base<Dimension,coeff_t>& A)
{
        return typename BGvec_base<Dimension,coeff_t>::template Ktimes<k_t> (k,A);
}

int main(int argc, char *argv[])
{
        BGvec_base<2> A; A[0] = 5.0; A[1] = 7.0;
        BGvec_base<2> B = 2.0*A;
}

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
           Keywords|                            |ice-on-invalid-code
         Resolution|                            |FIXED
   Target Milestone|---                         |3.4.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15271



More information about the Gcc-bugs mailing list