public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/15271] New: use of nested template classes generates internal error
@ 2004-05-03 20:41 albert at rad dot upenn dot edu
  2004-05-03 20:51 ` [Bug c++/15271] " pinskia at gcc dot gnu dot org
  2004-05-03 21:28 ` albertm at uphs dot upenn dot edu
  0 siblings, 2 replies; 3+ messages in thread
From: albert at rad dot upenn dot edu @ 2004-05-03 20:41 UTC (permalink / raw)
  To: gcc-bugs

Configuration:
Configured with: /ipl/srcs/gnu/gcc-3.3.1/configure
--prefix=/ipl/inst01/gnu/gcc-3.3.1 --with-gnu-ld
--with-ld=/ipl/inst01/gnu/binutils-2.14/bin/ld --with-gnu-as
--with-as=/ipl/inst01/gnu/binutils-2.14/bin/as
Thread model: posix
gcc version 3.3.1

Compilation of the below code with:
 g++ -c bug bug.cc
generates the following error message:
bug.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]':
bug.cc:31:   instantiated from here
bug.cc:25: internal compiler error: in tsubst, at cp/pt.c:6739
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

Thank you.  As always, you have my deep appreciation.

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 BGvec_base<Dimension,coeff_t>::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;
}

-- 
           Summary: use of nested template classes generates internal error
           Product: gcc
           Version: 3.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: albert at rad dot upenn dot edu
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: sparc-sun-solaris2.8
  GCC host triplet: sparc-sun-solaris2.8
GCC target triplet: sparc-sun-solaris2.8


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/15271] use of nested template classes generates internal error
  2004-05-03 20:41 [Bug c++/15271] New: use of nested template classes generates internal error albert at rad dot upenn dot edu
@ 2004-05-03 20:51 ` pinskia at gcc dot gnu dot org
  2004-05-03 21:28 ` albertm at uphs dot upenn dot edu
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-03 20:51 UTC (permalink / raw)
  To: gcc-bugs


------- 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/15271] use of nested template classes generates internal error
  2004-05-03 20:41 [Bug c++/15271] New: use of nested template classes generates internal error albert at rad dot upenn dot edu
  2004-05-03 20:51 ` [Bug c++/15271] " pinskia at gcc dot gnu dot org
@ 2004-05-03 21:28 ` albertm at uphs dot upenn dot edu
  1 sibling, 0 replies; 3+ messages in thread
From: albertm at uphs dot upenn dot edu @ 2004-05-03 21:28 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From albertm at uphs dot upenn dot edu  2004-05-03 21:28 -------
Subject: Re:  use of nested template classes generates internal
 error

Greetings!

Thank you very much!  The generosity and technical knowledge
of people such as yourself continues to astound me.

Sincerely,
 Mike Albert


On Mon, 3 May 2004, pinskia at gcc dot gnu dot org wrote:

>
> ------- 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
>
> ------- You are receiving this mail because: -------
> You reported the bug, or are watching the reporter.
>


-- 


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-05-03 21:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-03 20:41 [Bug c++/15271] New: use of nested template classes generates internal error albert at rad dot upenn dot edu
2004-05-03 20:51 ` [Bug c++/15271] " pinskia at gcc dot gnu dot org
2004-05-03 21:28 ` albertm at uphs dot upenn dot edu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).