This is the mail archive of the gcc-prs@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]
Other format: [Raw text]

c++/6023: Valid template code does not compile



>Number:         6023
>Category:       c++
>Synopsis:       Valid template code does not compile
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Thu Mar 21 02:06:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Klaus Kretschel
>Release:        3.0.4
>Organization:
DLR 
>Environment:
System: Linux darwin 2.4.4-64GB-SMP #1 SMP Wed May 16 01:20:45 GMT 2001 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ./configure 
>Description:
The call h->do_calc from Otto::calc in test program below gives
              the parse error

              temp_test.cc: In member function `T Otto<T>::calc(VEC)':
              temp_test.cc:35: parse error before `;' token

              while the same syntax is correct when called from Hugo::calc.

              I cannot rule out that this might be covered by
	      the missing feature "Two stage lookup in templates
	      is not implemented" but I don't think so.

              Compiler call was "g++ -c -Wall temp_test.cc".

	
>How-To-Repeat:
Test program temp_test.ii (the "vektor" struct can as
                well be replaced by vector; it was only introduced
                to avoid lots of preprocessor output):

# 1 "temp_test.cc"
template<class V> struct vektor
{
  V a;
  vektor(V v) : a(v) {}
};

template<class T> struct Otto;

template<class T> struct Hugo
{
  template<class VEC>
  T calc(VEC x) {
    T tmp;
    tmp = this->do_calc<VEC>(x);
    return tmp;
  }

  template<class VEC>
  T do_calc(const typename Otto<T>::MyTraits<T, VEC>::T2& x)
  { return x.a; }
};

template<class T> struct Otto
{
  template<class T0, typename T1> struct MyTraits;

  template<class T0> struct MyTraits<T0, vektor<T0> >
  { typedef vektor<T0> T2; };

  template<class VEC>
  T calc(VEC x) {
    Hugo<T>* h;
    T tmp;
    tmp = h->calc<VEC>(x);
    tmp = h->do_calc<VEC>(x);
    return tmp;
  }
};

int main()
{
  vektor<char> c('X');
  Otto<char> otto;
  otto.calc(c);
}

	
>Fix:
Have an intermediate method that calls method from inside class
        (like "Hugo::calc" in test program). Possible but very unsatifying
        because of redundant code.
	
>Release-Note:
>Audit-Trail:
>Unformatted:


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